Skip to content

Commit

Permalink
cephfs: adding unit test for fetchIP for client eviction
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Singhal <[email protected]>
  • Loading branch information
riya-singhal31 committed Sep 25, 2023
1 parent 32d9568 commit 18cfe93
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/csi-addons/networkfence/fencing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,48 @@ func TestGetIPRange(t *testing.T) {
})
}
}

func TestFetchIP(t *testing.T) {
t.Parallel()

tests := []struct {
clientInfo string
expectedIP string
expectedErr bool
}{
{
clientInfo: "client.4305 172.21.9.34:0/422650892",
expectedIP: "172.21.9.34",
expectedErr: false,
},
{
clientInfo: "invalid client info",
expectedIP: "",
expectedErr: true,
},
{
clientInfo: "",
expectedIP: "",
expectedErr: true,
},
}

for _, tt := range tests {
tt := tt

t.Run(tt.clientInfo, func(t *testing.T) {
t.Parallel()

client := activeClient{Inst: tt.clientInfo}
ip, actualErr := client.fetchIP()

if (actualErr != nil) != tt.expectedErr {
t.Errorf("expected error %v but got %v", tt.expectedErr, actualErr)
}

if ip != tt.expectedIP {
t.Errorf("expected IP %s but got %s", tt.expectedIP, ip)
}
})
}
}

0 comments on commit 18cfe93

Please sign in to comment.