Skip to content

Commit

Permalink
fix UT
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Aug 22, 2024
1 parent 5330fb9 commit faf3bb7
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions cni/network/network_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
netNs string
nwCfg *cni.NetworkConfig
interfaceInfo *network.InterfaceInfo
want net.HardwareAddr
want string
wantErr bool
}{
{
Expand All @@ -613,7 +613,7 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
MacAddress: parsedMacAddress,
NICType: cns.NodeNetworkInterfaceFrontendNIC,
},
want: parsedMacAddress,
want: swiftv2NetworkNamePrefix + parsedMacAddress.String(),
wantErr: false,
},
{
Expand All @@ -635,7 +635,7 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
MacAddress: parsedMacAddress,
NICType: cns.BackendNIC,
},
want: parsedMacAddress,
want: swiftv2NetworkNamePrefix + parsedMacAddress.String(),
wantErr: false,
},
{
Expand All @@ -657,7 +657,7 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
MacAddress: parsedMacAddress,
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
},
want: parsedMacAddress,
want: swiftv2NetworkNamePrefix + parsedMacAddress.String(),
wantErr: false,
},
{
Expand All @@ -675,8 +675,8 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
MultiTenancy: false,
},
interfaceInfo: &network.InterfaceInfo{}, // return empty network name with empty interfaceInfo
want: parsedMacAddress,
wantErr: true,
want: "",
wantErr: false,
},
{
name: "Unhappy path: Get Network Name from CNS for swiftv2 AccelnetNIC with invalid nicType",
Expand All @@ -697,37 +697,29 @@ func TestGetNetworkNameSwiftv2FromCNS(t *testing.T) {
MacAddress: parsedMacAddress,
NICType: "invalidNICType",
}, // return empty network name with invalid nic type
want: parsedMacAddress,
wantErr: true,
want: "",
wantErr: false,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Log(tt.interfaceInfo)
// compare networkNamess
networkName, err := tt.plugin.getNetworkName(tt.netNs, tt.interfaceInfo, tt.nwCfg)
if err != nil {
t.Fatalf("Failed to get network name due to error: %v", err)
}

// compare networkNames
expectedMacAddress := swiftv2NetworkNamePrefix + tt.want.String()
if tt.wantErr {
require.NotEqual(t, expectedMacAddress, networkName)
require.Error(t, err)
} else {
require.Equal(t, expectedMacAddress, networkName)
require.Equal(t, tt.want, networkName)
}

// compare networkIDs
networkID, err := tt.plugin.getNetworkID(tt.netNs, tt.interfaceInfo, tt.nwCfg)
if err != nil {
t.Fatalf("Failed to get network ID due to error: %v", err)
}
if tt.wantErr {
require.NotEqual(t, expectedMacAddress, networkID)
require.Error(t, err)
} else {
require.Equal(t, expectedMacAddress, networkID)
require.Equal(t, tt.want, networkID)
}
})
}
Expand Down

0 comments on commit faf3bb7

Please sign in to comment.