Skip to content

Commit e643672

Browse files
author
Heming Han
committed
add test
1 parent ca9f304 commit e643672

19 files changed

+341
-499
lines changed

ecs-agent/netlib/model/ecscni/bridge_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (bc *BridgeConfig) String() string {
3737
// InterfaceName returns the veth pair name will be used inside the namespace
3838
func (bc *BridgeConfig) InterfaceName() string {
3939
if bc.DeviceName == "" {
40-
return defaultInterfaceName
40+
return DefaultInterfaceName
4141
}
4242

4343
return bc.DeviceName

ecs-agent/netlib/model/ecscni/client.go

-10
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ const (
3030
versionCommand = "--version"
3131
)
3232

33-
// CNI defines the plugin invocation interface
34-
type CNI interface {
35-
// Add calls the plugin add command with given configuration
36-
Add(context.Context, PluginConfig) (types.Result, error)
37-
// Del calls the plugin del command with given configuration
38-
Del(context.Context, PluginConfig) error
39-
// Version calls the version command of plugin
40-
Version(string) (string, error)
41-
}
42-
4333
// CNIClient is the client to invoke the plugin
4434
type cniClient struct {
4535
pluginPath []string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//go:build unit
2+
// +build unit
3+
4+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
7+
// not use this file except in compliance with the License. A copy of the
8+
// License is located at
9+
//
10+
// http://aws.amazon.com/apache2.0/
11+
//
12+
// or in the "license" file accompanying this file. This file is distributed
13+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
// express or implied. See the License for the specific language governing
15+
// permissions and limitations under the License.
16+
17+
package ecscni
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
mock_libcni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/ecscni/mocks_libcni"
24+
25+
"github.com/golang/mock/gomock"
26+
)
27+
28+
func TestAddDel(t *testing.T) {
29+
ctrl := gomock.NewController(t)
30+
defer ctrl.Finish()
31+
ctx, _ := context.WithCancel(context.TODO())
32+
33+
client := NewCNIClient([]string{})
34+
mockLibCNIClient := mock_libcni.NewMockCNI(ctrl)
35+
client.(*cniClient).cni = mockLibCNIClient
36+
37+
config := &TestCNIConfig{
38+
CNIConfig: CNIConfig{
39+
NetNSPath: NetNS,
40+
CNISpecVersion: CNIVersion,
41+
CNIPluginName: PluginName,
42+
},
43+
NetworkInterfaceName: IfName,
44+
}
45+
46+
client.Add(ctx, config)
47+
client.Del(ctx, config)
48+
mockLibCNIClient.EXPECT().AddNetwork(gomock.Any(), gomock.Any())
49+
mockLibCNIClient.EXPECT().DelNetwork(gomock.Any(), gomock.Any())
50+
}

ecs-agent/netlib/model/ecscni/eni_config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (ec *ENIConfig) NSPath() string {
7575

7676
func (ec *ENIConfig) InterfaceName() string {
7777
if ec.DeviceName == "" {
78-
return defaultENIName
78+
return DefaultENIName
7979
}
8080
return ec.DeviceName
8181
}

ecs-agent/netlib/model/ecscni/generate_mocks_linux.go renamed to ecs-agent/netlib/model/ecscni/generate_mocks.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// express or implied. See the License for the specific language governing
1212
// permissions and limitations under the License.
1313

14-
//go:build !windows
15-
// +build !windows
16-
1714
package ecscni
1815

19-
//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
16+
//go:generate mockgen -destination=../mocks_libcni/libcni_mocks.go -copyright_file=../../../../scripts/copyright_file github.com/containernetworking/cni/libcni CNI

ecs-agent/netlib/model/ecscni/mocks/ecscni_mocks_linux.go

-255
This file was deleted.

0 commit comments

Comments
 (0)