Skip to content

Commit

Permalink
Add test for empty ip (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubronzhan authored Mar 25, 2022
1 parent d2d1ba6 commit 9c62385
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 9 additions & 0 deletions pkg/cloudprovider/vsphere/nodemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,15 @@ func TestDiscoverNodeIPs(t *testing.T) {
},
expectedErrorSubstring: "unable to find suitable IP address for node",
},
{
testName: "whenVCreturnsEmptyGuestNicInfo",
setup: testSetup{
ipFamilyPriority: []string{"ipv4"},
cpiConfig: nil,
networks: []vimtypes.GuestNicInfo{},
},
expectedErrorSubstring: "VM GuestNicInfo is empty",
},
}

for _, testcase := range testcases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ func TestProcessIPPoolCreateOrUpdate(t *testing.T) {
c, cs := newController()

if _, err := c.ippoolclientset.NsxV1alpha1().IPPools(testClusterNS).Create(context.Background(), &testIPPool, metav1.CreateOptions{}); err != nil {
t.Errorf("failed to create test ippool %s: %w", testIPPool.Name, err)
t.Errorf("failed to create test ippool %s: %v", testIPPool.Name, err)
}

if err := c.processIPPoolCreateOrUpdate(&testIPPool); err != nil {
t.Errorf("failed to processIPPoolCreateOrUpdate %v: %w", testIPPool, err)
t.Errorf("failed to processIPPoolCreateOrUpdate %v: %v", testIPPool, err)
}

for _, n := range tc.nodes {
if _, err := c.kubeclientset.CoreV1().Nodes().Create(context.Background(), &n, metav1.CreateOptions{}); err != nil {
t.Errorf("failed to create test node %s: %w", n.Name, err)
t.Errorf("failed to create test node %s: %v", n.Name, err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func TestProcessNodeCreateOrUpdate(t *testing.T) {
// create nodes and run process processNodeCreateOrUpdate
for _, n := range tc.nodes {
if err := ippc.processNodeCreateOrUpdate(&n); err != nil {
t.Errorf("failed to create test node %s: %w", n.Name, err)
t.Errorf("failed to create test node %s: %v", n.Name, err)
}
}
for _, n := range tc.nodesUpdate {
if err := ippc.processNodeCreateOrUpdate(&n); err != nil {
t.Errorf("failed to create test node %s: %w", n.Name, err)
t.Errorf("failed to create test node %s: %v", n.Name, err)
}
}

Expand Down Expand Up @@ -231,14 +231,14 @@ func TestProcessNodeDelete(t *testing.T) {
if tc.ippoolExist {
// pre create test nodes
if _, err := createIPPool(ippcs, tc.nodes); err != nil {
t.Errorf("failed to create ippool %w", err)
t.Errorf("failed to create ippool %v", err)
}
}

// delete node
for _, n := range tc.nodesToBeDeleted {
if err := ippc.processNodeDelete(n.Name); err != nil {
t.Errorf("failed to create test node %s: %w", n.Name, err)
t.Errorf("failed to create test node %s: %v", n.Name, err)
}
}

Expand Down

0 comments on commit 9c62385

Please sign in to comment.