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

Function TestTextDecoderWithBufioReader

expfmt/decode_test.go:554–580  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

552}
553
554func TestTextDecoderWithBufioReader(t *testing.T) {
555 example := `
556 # TYPE foo gauge
557 foo 0
558 `
559
560 var decoded bool
561 r := bufio.NewReader(strings.NewReader(example))
562 dec := NewDecoder(r, FmtText)
563 for {
564 var mf dto.MetricFamily
565 if err := dec.Decode(&mf); err != nil {
566 if errors.Is(err, io.EOF) {
567 break
568 }
569 t.Fatalf("Unexpected error: %v", err)
570 }
571 if mf.GetName() != "foo" {
572 t.Errorf("Unexpected metric name: got %v, expected %v", mf.GetName(), "foo")
573 }
574 if len(mf.Metric) != 1 {
575 t.Errorf("Unexpected number of metrics: got %v, expected %v", len(mf.Metric), 1)
576 }
577 decoded = true
578 }
579 require.Truef(t, decoded, "Metric foo not decoded")
580}
581
582func TestNewDecoder(t *testing.T) {
583 om20Format, err := NewOpenMetricsFormat(OpenMetricsVersion_2_0_0)

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected