MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestCompareMatrix

Function TestCompareMatrix

tools/querytee/response_comparator_test.go:11–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestCompareMatrix(t *testing.T) {
12 for _, tc := range []struct {
13 name string
14 expected json.RawMessage
15 actual json.RawMessage
16 err error
17 }{
18 {
19 name: "no metrics",
20 expected: json.RawMessage(`[]`),
21 actual: json.RawMessage(`[]`),
22 },
23 {
24 name: "no metrics in actual response",
25 expected: json.RawMessage(`[
26 {"metric":{"foo":"bar"},"values":[[1,"1"]]}
27 ]`),
28 actual: json.RawMessage(`[]`),
29 err: errors.New("expected 1 metrics but got 0"),
30 },
31 {
32 name: "extra metric in actual response",
33 expected: json.RawMessage(`[
34 {"metric":{"foo":"bar"},"values":[[1,"1"]]}
35 ]`),
36 actual: json.RawMessage(`[
37 {"metric":{"foo":"bar"},"values":[[1,"1"]]},
38 {"metric":{"foo1":"bar1"},"values":[[1,"1"]]}
39 ]`),
40 err: errors.New("expected 1 metrics but got 2"),
41 },
42 {
43 name: "same number of metrics but with different labels",
44 expected: json.RawMessage(`[
45 {"metric":{"foo":"bar"},"values":[[1,"1"]]}
46 ]`),
47 actual: json.RawMessage(`[
48 {"metric":{"foo1":"bar1"},"values":[[1,"1"]]}
49 ]`),
50 err: errors.New("expected metric {foo=\"bar\"} missing from actual response"),
51 },
52 {
53 name: "difference in number of samples",
54 expected: json.RawMessage(`[
55 {"metric":{"foo":"bar"},"values":[[1,"1"],[2,"2"]]}
56 ]`),
57 actual: json.RawMessage(`[
58 {"metric":{"foo":"bar"},"values":[[1,"1"]]}
59 ]`),
60 err: errors.New("expected 2 samples for metric {foo=\"bar\"} but got 1"),
61 },
62 {
63 name: "difference in sample timestamp",
64 expected: json.RawMessage(`[
65 {"metric":{"foo":"bar"},"values":[[1,"1"],[2,"2"]]}
66 ]`),
67 actual: json.RawMessage(`[
68 {"metric":{"foo":"bar"},"values":[[1,"1"],[3,"2"]]}

Callers

nothing calls this directly

Calls 4

compareMatrixFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected