Skip to content

Commit

Permalink
cephfs: add unit test for fetchIPfromEntry
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Singhal <[email protected]>
  • Loading branch information
riya-singhal31 committed Oct 13, 2023
1 parent 55d9bf5 commit 0b45b24
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/csi-addons/networkfence/fencing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,40 @@ func TestFetchID(t *testing.T) {
})
}
}

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

tests := []struct {
entry string
expectedIP string
expectedErr bool
}{
{
entry: "127.0.0.1:0/3710147553 2018-03-19 11:32:24.716146",
expectedIP: "127.0.0.1",
expectedErr: false,
},
{
entry: "",
expectedIP: "",
expectedErr: true,
},
}

for _, tt := range tests {
ts := tt
t.Run(ts.entry, func(t *testing.T) {
t.Parallel()
ip, actualErr := fetchIPfromEntry(ts.entry)

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)
}
})
}
}

0 comments on commit 0b45b24

Please sign in to comment.