From 2218422150151531227c522b3c9fd97668b5c60a Mon Sep 17 00:00:00 2001 From: Daria Danilenko Date: Wed, 21 Dec 2022 17:31:48 +0100 Subject: [PATCH] Add testcase for multiple expected metrics --- prometheus/testutil/testutil_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/prometheus/testutil/testutil_test.go b/prometheus/testutil/testutil_test.go index 2a46e5dbb..4a1f7bc27 100644 --- a/prometheus/testutil/testutil_test.go +++ b/prometheus/testutil/testutil_test.go @@ -331,6 +331,31 @@ func TestScrapeAndCompare(t *testing.T) { } } +func TestScrapeAndCompareWithMultipleExpected(t *testing.T) { + const expected = ` + # HELP some_total A value that represents a counter. + # TYPE some_total counter + + some_total{ label1 = "value1" } 1 + + # HELP some_total2 A value that represents a counter. + # TYPE some_total2 counter + + some_total2{ label1 = "value1" } 1 + ` + + expectedReader := strings.NewReader(expected) + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, expected) + })) + defer ts.Close() + + if err := ScrapeAndCompare(ts.URL, expectedReader, "some_total2"); err != nil { + t.Errorf("unexpected scraping result:\n%s", err) + } +} + func TestScrapeAndCompareFetchingFail(t *testing.T) { err := ScrapeAndCompare("some_url", strings.NewReader("some expectation"), "some_total") if err == nil {