MCPcopy Create free account
hub / github.com/prometheus/common / TestMatrixJSON

Function TestMatrixJSON

model/value_float_test.go:260–298  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestMatrixJSON(t *testing.T) {
261 input := []struct {
262 plain string
263 value Matrix
264 }{
265 {
266 plain: `[]`,
267 value: Matrix{},
268 },
269 {
270 plain: samplePairMatrixPlain,
271 value: samplePairMatrixValue,
272 },
273 }
274
275 for _, test := range input {
276 b, err := json.Marshal(test.value)
277 if err != nil {
278 t.Error(err)
279 continue
280 }
281
282 if string(b) != test.plain {
283 t.Errorf("encoding error: expected %q, got %q", test.plain, b)
284 continue
285 }
286
287 var mat Matrix
288 err = json.Unmarshal(b, &mat)
289 if err != nil {
290 t.Error(err)
291 continue
292 }
293
294 if !reflect.DeepEqual(mat, test.value) {
295 t.Errorf("decoding error: expected %v, got %v", test.value, mat)
296 }
297 }
298}
299
300func BenchmarkJSONMarshallingSamplePairMatrix(b *testing.B) {
301 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected