Skip to content

Commit

Permalink
Convert actual value to array of maps
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Jul 25, 2024
1 parent 82eb5a3 commit d42d06f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1899,8 +1899,7 @@ func assertRequestResultDocs(
fmt.Sprintf("node: %v, doc: %v", nodeID, actualDocIndex),
)
case []map[string]any:
actualValueMap, ok := actualValue.([]map[string]any)
require.True(s.t, ok, "expected array of maps, got %T", actualValue)
actualValueMap := convertToArrayOfMaps(s.t, actualValue)

assertRequestResultDocs(
s,
Expand All @@ -1925,6 +1924,22 @@ func assertRequestResultDocs(
return false
}

func convertToArrayOfMaps(t testing.TB, value any) []map[string]any {
valueArrayMap, ok := value.([]map[string]any)
if ok {
return valueArrayMap
}
valueArray, ok := value.([]any)
require.True(t, ok, "expected value to be an array of maps %v", value)

valueArrayMap = make([]map[string]any, len(valueArray))
for i, v := range valueArray {
valueArrayMap[i], ok = v.(map[string]any)
require.True(t, ok, "expected value to be an array of maps %v", value)
}
return valueArrayMap
}

func assertExpectedErrorRaised(t testing.TB, description string, expectedError string, wasRaised bool) {
if expectedError != "" && !wasRaised {
assert.Fail(t, "Expected an error however none was raised.", description)
Expand Down

0 comments on commit d42d06f

Please sign in to comment.