Skip to content

Commit

Permalink
cephfs: add unit test for ParseBlocklistEntries
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 0b45b24 commit 7d7d514
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions internal/csi-addons/networkfence/fencing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,60 @@ func TestFetchIPfromEntry(t *testing.T) {
})
}
}

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

tests := []struct {
output string
expected []string
expectedSize int
}{
{
output: `listed 3 entries
127.0.0.1:0/3710147553 2018-03-19 11:32:24.716146
192.168.0.1:0/1234567890 2022-08-23 14:12:34.567890`,
expected: []string{
"127.0.0.1:0/3710147553 2018-03-19 11:32:24.716146",
"192.168.0.1:0/1234567890 2022-08-23 14:12:34.567890",
},
expectedSize: 2,
},
{
output: "listed 0 entries\n",
expected: []string{},
expectedSize: 0,
},
{
output: `listed 1 entries
192.168.0.1:0/1234567890 2022-08-23 14:12:34.567890`,
expected: []string{
"192.168.0.1:0/1234567890 2022-08-23 14:12:34.567890",
},
expectedSize: 1,
},
{
output: "",
expected: []string{},
expectedSize: 0,
},
}

for _, tt := range tests {
ts := tt
t.Run(ts.output, func(t *testing.T) {
t.Parallel()
entries := parseBlocklistEntries(ts.output)

if len(entries) != ts.expectedSize {
t.Errorf("expected length %d but got %d", ts.expectedSize, len(entries))
}

for i, entry := range entries {
if entry != ts.expected[i] {
t.Errorf("expected entry %s but got %s", ts.expected[i], entry)
}
}
})
}
}

0 comments on commit 7d7d514

Please sign in to comment.