Skip to content

Commit a212306

Browse files
committed
improving tests
1 parent 0ce364a commit a212306

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pkg/querier/stats/stats_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ func TestQueryStats_AddExtraFields(t *testing.T) {
4848
stats.AddExtraFields("a", "b")
4949
stats.AddExtraFields("c")
5050

51-
assert.ElementsMatch(t, []interface{}{"a", "b", "c", ""}, stats.LoadExtraFields())
51+
checkExtraFields(t, []interface{}{"a", "b", "c", ""}, stats.LoadExtraFields())
5252
})
5353

5454
t.Run("add and load extra fields nil receiver", func(t *testing.T) {
5555
var stats *QueryStats
5656
stats.AddExtraFields("a", "b")
5757

58-
assert.ElementsMatch(t, []interface{}{}, stats.LoadExtraFields())
58+
checkExtraFields(t, []interface{}{}, stats.LoadExtraFields())
5959
})
6060
}
6161

@@ -116,7 +116,7 @@ func TestStats_Merge(t *testing.T) {
116116
assert.Equal(t, uint64(110), stats1.LoadFetchedSeries())
117117
assert.Equal(t, uint64(142), stats1.LoadFetchedChunkBytes())
118118
assert.Equal(t, uint64(201), stats1.LoadFetchedDataBytes())
119-
assert.ElementsMatch(t, []interface{}{"a", "b", "d", "c"}, stats1.LoadExtraFields())
119+
checkExtraFields(t, []interface{}{"a", "b", "c", "d"}, stats1.LoadExtraFields())
120120
})
121121

122122
t.Run("merge two nil stats objects", func(t *testing.T) {
@@ -129,6 +129,19 @@ func TestStats_Merge(t *testing.T) {
129129
assert.Equal(t, uint64(0), stats1.LoadFetchedSeries())
130130
assert.Equal(t, uint64(0), stats1.LoadFetchedChunkBytes())
131131
assert.Equal(t, uint64(0), stats1.LoadFetchedDataBytes())
132-
assert.Equal(t, []interface{}{}, stats1.LoadExtraFields())
132+
checkExtraFields(t, []interface{}{}, stats1.LoadExtraFields())
133133
})
134134
}
135+
136+
func checkExtraFields(t *testing.T, expected, actual []interface{}) {
137+
assert.Equal(t, len(expected), len(actual))
138+
expectedMap := map[string]string{}
139+
actualMap := map[string]string{}
140+
141+
for i := 0; i < len(expected); i += 2 {
142+
expectedMap[expected[i].(string)] = expected[i+1].(string)
143+
actualMap[actual[i].(string)] = actual[i+1].(string)
144+
}
145+
146+
assert.Equal(t, expectedMap, actualMap)
147+
}

0 commit comments

Comments
 (0)