(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestCompareVector(t *testing.T) { |
| 106 | for _, tc := range []struct { |
| 107 | name string |
| 108 | expected json.RawMessage |
| 109 | actual json.RawMessage |
| 110 | err error |
| 111 | }{ |
| 112 | { |
| 113 | name: "no metrics", |
| 114 | expected: json.RawMessage(`[]`), |
| 115 | actual: json.RawMessage(`[]`), |
| 116 | }, |
| 117 | { |
| 118 | name: "no metrics in actual response", |
| 119 | expected: json.RawMessage(`[ |
| 120 | {"metric":{"foo":"bar"},"value":[1,"1"]} |
| 121 | ]`), |
| 122 | actual: json.RawMessage(`[]`), |
| 123 | err: errors.New("expected 1 metrics but got 0"), |
| 124 | }, |
| 125 | { |
| 126 | name: "extra metric in actual response", |
| 127 | expected: json.RawMessage(`[ |
| 128 | {"metric":{"foo":"bar"},"value":[1,"1"]} |
| 129 | ]`), |
| 130 | actual: json.RawMessage(`[ |
| 131 | {"metric":{"foo":"bar"},"value":[1,"1"]}, |
| 132 | {"metric":{"foo1":"bar1"},"value":[1,"1"]} |
| 133 | ]`), |
| 134 | err: errors.New("expected 1 metrics but got 2"), |
| 135 | }, |
| 136 | { |
| 137 | name: "same number of metrics but with different labels", |
| 138 | expected: json.RawMessage(`[ |
| 139 | {"metric":{"foo":"bar"},"value":[1,"1"]} |
| 140 | ]`), |
| 141 | actual: json.RawMessage(`[ |
| 142 | {"metric":{"foo1":"bar1"},"value":[1,"1"]} |
| 143 | ]`), |
| 144 | err: errors.New("expected metric {foo=\"bar\"} missing from actual response"), |
| 145 | }, |
| 146 | { |
| 147 | name: "difference in sample timestamp", |
| 148 | expected: json.RawMessage(`[ |
| 149 | {"metric":{"foo":"bar"},"value":[1,"1"]} |
| 150 | ]`), |
| 151 | actual: json.RawMessage(`[ |
| 152 | {"metric":{"foo":"bar"},"value":[2,"1"]} |
| 153 | ]`), |
| 154 | err: errors.New("sample pair not matching for metric {foo=\"bar\"}: expected timestamp 1 but got 2"), |
| 155 | }, |
| 156 | { |
| 157 | name: "difference in sample value", |
| 158 | expected: json.RawMessage(`[ |
| 159 | {"metric":{"foo":"bar"},"value":[1,"1"]} |
| 160 | ]`), |
| 161 | actual: json.RawMessage(`[ |
| 162 | {"metric":{"foo":"bar"},"value":[1,"2"]} |
nothing calls this directly
no test coverage detected