Skip to content

Commit

Permalink
Added test for HRANDFIELD handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinmwinuka committed Feb 15, 2024
1 parent 93a1992 commit d7fd5b4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/modules/hash/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,34 @@ func Test_HandleHRANDFIELD(t *testing.T) {
if len(rv.Array()) != test.expectedCount {
t.Errorf("expected response array of length \"%d\", got length \"%d\"", test.expectedCount, len(rv.Array()))
}
switch test.withValues {
case false:
for _, v := range rv.Array() {
if !slices.ContainsFunc(test.expectedResponse, func(expected string) bool {
return expected == v.String()
}) {
t.Errorf("could not find response element \"%s\" in expected response", v.String())
}
}
case true:
responseArray := rv.Array()
for i := 0; i < len(responseArray); i++ {
if i%2 == 0 {
field := responseArray[i].String()
value := responseArray[i+1].String()

expectedFieldIndex := slices.Index(test.expectedResponse, field)
if expectedFieldIndex == -1 {
t.Errorf("could not find response value \"%s\" in expected values", field)
}
expectedValue := test.expectedResponse[expectedFieldIndex+1]

if value != expectedValue {
t.Errorf("expected value \"%s\", got \"%s\"", expectedValue, value)
}
}
}
}
}
}

Expand Down

0 comments on commit d7fd5b4

Please sign in to comment.