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

Function TestTextDecoderWithBufioReader

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…