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

Function TestMatrixHistogramJSON

model/value_histogram_test.go:709–748  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

707}
708
709func TestMatrixHistogramJSON(t *testing.T) {
710 input := []struct {
711 plain string
712 value Matrix
713 }{
714 {
715 plain: `[]`,
716 value: Matrix{},
717 },
718 {
719 plain: sampleHistogramPairMatrixPlain,
720 value: sampleHistogramPairMatrixValue,
721 },
722 }
723
724 for _, test := range input {
725 b, err := json.Marshal(test.value)
726 if err != nil {
727 t.Error(err)
728 continue
729 }
730
731 trimmed := noWhitespace.ReplaceAllString(test.plain, "")
732 if string(b) != trimmed {
733 t.Errorf("encoding error: expected %q, got %q", trimmed, b)
734 continue
735 }
736
737 var mat Matrix
738 err = json.Unmarshal(b, &mat)
739 if err != nil {
740 t.Error(err)
741 continue
742 }
743
744 if !reflect.DeepEqual(mat, test.value) {
745 t.Errorf("decoding error: expected %v, got %v", test.value, mat)
746 }
747 }
748}
749
750func BenchmarkJSONMarshallingSampleHistogramPairMatrix(b *testing.B) {
751 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected