Skip to content

Commit 66996d2

Browse files
committed
add negative test case
1 parent f823484 commit 66996d2

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cns/middlewares/k8sSwiftV2_windows.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package middlewares
22

33
import (
4-
"fmt"
5-
64
"github.com/Azure/azure-container-networking/cns"
75
"github.com/Azure/azure-container-networking/cns/middlewares/utils"
86
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
@@ -23,7 +21,6 @@ func (k *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
2321

2422
// add routes for infraNIC
2523
routes, err := k.SetInfraRoutes(podIPInfo)
26-
fmt.Printf("routes are %v", routes)
2724
if err != nil {
2825
return errors.Wrap(err, "failed to set routes for infraNIC interface")
2926
}

cns/middlewares/k8sSwiftV2_windows_test.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package middlewares
22

33
import (
4-
"fmt"
54
"reflect"
65
"testing"
76

@@ -37,7 +36,6 @@ func TestSetRoutesSuccess(t *testing.T) {
3736
}
3837
for i := range podIPInfo {
3938
ipInfo := &podIPInfo[i]
40-
fmt.Printf("ipInfo is %v", ipInfo)
4139
err := middleware.setRoutes(ipInfo)
4240
assert.Equal(t, err, nil)
4341
if ipInfo.NICType == cns.InfraNIC {
@@ -48,6 +46,27 @@ func TestSetRoutesSuccess(t *testing.T) {
4846
}
4947
}
5048

49+
func TestSetRoutesFailure(t *testing.T) {
50+
// Failure due to env var not set
51+
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()}
52+
podIPInfo := []cns.PodIpInfo{
53+
{
54+
PodIPConfig: cns.IPSubnet{
55+
IPAddress: "10.0.1.10",
56+
PrefixLength: 32,
57+
},
58+
NICType: cns.InfraNIC,
59+
},
60+
}
61+
for i := range podIPInfo {
62+
ipInfo := &podIPInfo[i]
63+
err := middleware.setRoutes(ipInfo)
64+
if err == nil {
65+
t.Errorf("SetRoutes should fail due to env var not set")
66+
}
67+
}
68+
}
69+
5170
func TestAssignSubnetPrefixSuccess(t *testing.T) {
5271
middleware := K8sSWIFTv2Middleware{Cli: mock.NewClient()}
5372

0 commit comments

Comments
 (0)