Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Realmonia committed Sep 13, 2023
1 parent ca9f304 commit e643672
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 499 deletions.
2 changes: 1 addition & 1 deletion ecs-agent/netlib/model/ecscni/bridge_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (bc *BridgeConfig) String() string {
// InterfaceName returns the veth pair name will be used inside the namespace
func (bc *BridgeConfig) InterfaceName() string {
if bc.DeviceName == "" {
return defaultInterfaceName
return DefaultInterfaceName
}

return bc.DeviceName
Expand Down
10 changes: 0 additions & 10 deletions ecs-agent/netlib/model/ecscni/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ const (
versionCommand = "--version"
)

// CNI defines the plugin invocation interface
type CNI interface {
// Add calls the plugin add command with given configuration
Add(context.Context, PluginConfig) (types.Result, error)
// Del calls the plugin del command with given configuration
Del(context.Context, PluginConfig) error
// Version calls the version command of plugin
Version(string) (string, error)
}

// CNIClient is the client to invoke the plugin
type cniClient struct {
pluginPath []string
Expand Down
50 changes: 50 additions & 0 deletions ecs-agent/netlib/model/ecscni/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build unit
// +build unit

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package ecscni

import (
"context"
"testing"

mock_libcni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/ecscni/mocks_libcni"

"github.com/golang/mock/gomock"
)

func TestAddDel(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
ctx, _ := context.WithCancel(context.TODO())

client := NewCNIClient([]string{})
mockLibCNIClient := mock_libcni.NewMockCNI(ctrl)
client.(*cniClient).cni = mockLibCNIClient

config := &TestCNIConfig{
CNIConfig: CNIConfig{
NetNSPath: NetNS,
CNISpecVersion: CNIVersion,
CNIPluginName: PluginName,
},
NetworkInterfaceName: IfName,
}

client.Add(ctx, config)
client.Del(ctx, config)
mockLibCNIClient.EXPECT().AddNetwork(gomock.Any(), gomock.Any())
mockLibCNIClient.EXPECT().DelNetwork(gomock.Any(), gomock.Any())
}
2 changes: 1 addition & 1 deletion ecs-agent/netlib/model/ecscni/eni_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (ec *ENIConfig) NSPath() string {

func (ec *ENIConfig) InterfaceName() string {
if ec.DeviceName == "" {
return defaultENIName
return DefaultENIName
}
return ec.DeviceName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

//go:build !windows
// +build !windows

package ecscni

//go:generate mockgen -build_flags=--mod=mod -destination=mocks/ecscni_mocks_linux.go -copyright_file=../../../../scripts/copyright_file github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/ecscni Config,NetNSUtil,CNI
//go:generate mockgen -destination=../mocks_libcni/libcni_mocks.go -copyright_file=../../../../scripts/copyright_file github.com/containernetworking/cni/libcni CNI
255 changes: 0 additions & 255 deletions ecs-agent/netlib/model/ecscni/mocks/ecscni_mocks_linux.go

This file was deleted.

Loading

0 comments on commit e643672

Please sign in to comment.