Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expfmt: add test case for issue with *bufio.Reader and FmtText format #448

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions expfmt/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package expfmt

import (
"bufio"
"io"
"net/http"
"reflect"
Expand Down Expand Up @@ -491,3 +492,33 @@ func TestExtractSamples(t *testing.T) {
t.Errorf("unexpected samples extracted, got: %v, want: %v", got, want)
}
}

func TestTextDecoderWithBufioReader(t *testing.T) {
example := `
# TYPE foo gauge
foo 0
`

var decoded bool
r := bufio.NewReader(strings.NewReader(example))
dec := NewDecoder(r, FmtText)
for {
var mf dto.MetricFamily
if err := dec.Decode(&mf); err != nil {
if err == io.EOF {
break
}
t.Fatalf("Unexpected error: %v", err)
}
if mf.GetName() != "foo" {
t.Errorf("Unexpected metric name: got %v, expected %v", mf.GetName(), "foo")
}
if len(mf.Metric) != 1 {
t.Errorf("Unexpected number of metrics: got %v, expected %v", len(mf.Metric), 1)
}
decoded = true
}
if !decoded {
t.Fatal("Metric foo not decoded")
}
}