From a0109f00dff9e7e419ed8005985e26bcc32d0d93 Mon Sep 17 00:00:00 2001 From: shivi28 Date: Fri, 30 Aug 2019 01:50:04 +0530 Subject: [PATCH] nodeipam-controller:fix static check failures --- hack/.staticcheck_failures | 1 - .../nodeipam/ipam/cidrset/cidr_set_test.go | 57 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index 1342b03ac58..d076f3da9d3 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -12,7 +12,6 @@ pkg/controller/disruption pkg/controller/garbagecollector pkg/controller/namespace/deletion pkg/controller/nodeipam -pkg/controller/nodeipam/ipam/cidrset pkg/controller/podautoscaler pkg/controller/podgc pkg/controller/replicaset diff --git a/pkg/controller/nodeipam/ipam/cidrset/cidr_set_test.go b/pkg/controller/nodeipam/ipam/cidrset/cidr_set_test.go index c9e1651274a..a82b08b70ce 100644 --- a/pkg/controller/nodeipam/ipam/cidrset/cidr_set_test.go +++ b/pkg/controller/nodeipam/ipam/cidrset/cidr_set_test.go @@ -700,34 +700,39 @@ func TestCIDRSetv6(t *testing.T) { }, } for _, tc := range cases { - _, clusterCIDR, _ := net.ParseCIDR(tc.clusterCIDRStr) - a, err := NewCIDRSet(clusterCIDR, tc.subNetMaskSize) - if err != nil { - if tc.expectErr { - continue + t.Run(tc.description, func(t *testing.T) { + _, clusterCIDR, _ := net.ParseCIDR(tc.clusterCIDRStr) + a, err := NewCIDRSet(clusterCIDR, tc.subNetMaskSize) + if gotErr := err != nil; gotErr != tc.expectErr { + t.Fatalf("NewCIDRSet(%v, %v) = %v, %v; gotErr = %t, want %t", clusterCIDR, tc.subNetMaskSize, a, err, gotErr, tc.expectErr) } - t.Fatalf("Error allocating CIDRSet for %v", tc.description) - } - - p, err := a.AllocateNext() - if err == nil && tc.expectErr { - t.Errorf("expected error but got none for %v", tc.description) - continue - } - if err != nil && !tc.expectErr { - t.Errorf("unexpected error: %v for %v", err, tc.description) - continue - } - if !tc.expectErr { - if p.String() != tc.expectedCIDR { - t.Fatalf("unexpected allocated cidr: %s for %v", p.String(), tc.description) + if a == nil { + return } - } - p2, err := a.AllocateNext() - if !tc.expectErr { - if p2.String() != tc.expectedCIDR2 { - t.Fatalf("unexpected allocated cidr: %s for %v", p2.String(), tc.description) + p, err := a.AllocateNext() + if err == nil && tc.expectErr { + t.Errorf("a.AllocateNext() = nil, want error") } - } + if err != nil && !tc.expectErr { + t.Errorf("a.AllocateNext() = %+v, want no error", err) + } + if !tc.expectErr { + if p != nil && p.String() != tc.expectedCIDR { + t.Fatalf("a.AllocateNext() got %+v, want %+v", p.String(), tc.expectedCIDR) + } + } + p2, err := a.AllocateNext() + if err == nil && tc.expectErr { + t.Errorf("a.AllocateNext() = nil, want error") + } + if err != nil && !tc.expectErr { + t.Errorf("a.AllocateNext() = %+v, want no error", err) + } + if !tc.expectErr { + if p2 != nil && p2.String() != tc.expectedCIDR2 { + t.Fatalf("a.AllocateNext() got %+v, want %+v", p2.String(), tc.expectedCIDR) + } + } + }) } }