cephfs: adding unit test for fetchID

Signed-off-by: Riya Singhal <rsinghal@redhat.com>
This commit is contained in:
Riya Singhal 2023-09-26 02:18:21 +05:30 committed by mergify[bot]
parent b8e74e62c0
commit d925937d53
2 changed files with 38 additions and 1 deletions

View File

@ -224,7 +224,6 @@ func (ac *activeClient) fetchID() (int, error) {
}
return 0, fmt.Errorf("failed to extract client ID, incorrect format: %s", clientInfo)
}
// AddClientEviction blocks access for all the IPs in the CIDR block

View File

@ -94,3 +94,41 @@ func TestFetchIP(t *testing.T) {
})
}
}
func TestFetchID(t *testing.T) {
t.Parallel()
tests := []struct {
clientInfo string
expectedID int
expectedErr bool
}{
{
clientInfo: "client.4305 172.21.9.34:0/422650892",
expectedID: 4305,
expectedErr: false,
},
{
clientInfo: "",
expectedID: 0,
expectedErr: true,
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.clientInfo, func(t *testing.T) {
t.Parallel()
ac := &activeClient{Inst: ts.clientInfo}
actualID, actualErr := ac.fetchID()
if (actualErr != nil) != ts.expectedErr {
t.Errorf("expected error %v but got %v", ts.expectedErr, actualErr)
}
if actualID != ts.expectedID {
t.Errorf("expected ID %d but got %d", ts.expectedID, actualID)
}
})
}
}