cephfs: adding unit test for fetchIP for client eviction

Signed-off-by: Riya Singhal <rsinghal@redhat.com>
This commit is contained in:
Riya Singhal 2023-09-26 01:11:04 +05:30 committed by mergify[bot]
parent 6b0c412996
commit b8e74e62c0

View File

@ -54,3 +54,43 @@ 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: "",
expectedIP: "",
expectedErr: true,
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.clientInfo, func(t *testing.T) {
t.Parallel()
client := activeClient{Inst: ts.clientInfo}
ip, actualErr := client.fetchIP()
if (actualErr != nil) != ts.expectedErr {
t.Errorf("expected error %v but got %v", ts.expectedErr, actualErr)
}
if ip != ts.expectedIP {
t.Errorf("expected IP %s but got %s", ts.expectedIP, ip)
}
})
}
}