From 0c0d9c5c6bef37320c59a9564e8fbecc195bce9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Fri, 15 Dec 2023 13:51:26 +0100 Subject: [PATCH 1/2] utils/golden: DiffPrometheusMetricsHTTP accept string instead of *url.URL Fixes #603 --- utils/golden/prometheus.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/golden/prometheus.go b/utils/golden/prometheus.go index d92d6c09..55bce7ba 100644 --- a/utils/golden/prometheus.go +++ b/utils/golden/prometheus.go @@ -10,7 +10,6 @@ import ( "bytes" "io" "net/http" - "net/url" "os" "runtime" "testing" @@ -45,11 +44,11 @@ func DiffPrometheusMetrics(t *testing.T, p prometheus.Gatherer, filter ...func(* } } -func DiffPrometheusMetricsHTTP(t *testing.T, u *url.URL, filter ...func(*dto.MetricFamily) bool) { +func DiffPrometheusMetricsHTTP(t *testing.T, url string, filter ...func(*dto.MetricFamily) bool) { t.Helper() http.DefaultClient.Timeout = 30 * time.Second - res, err := http.DefaultClient.Get(u.String()) //nolint:noctx // The timeout is set above. + res, err := http.DefaultClient.Get(url) //nolint:noctx // The timeout is set above. if err != nil { t.Fatal(err) } From a1e6ece540c113aca07ddfb5153659756ea480b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Fri, 15 Dec 2023 13:52:56 +0100 Subject: [PATCH 2/2] utils/golden: DiffPrometheusMetrics replace / in test name with _ This allows to have a flat testdata structure with subtests. --- utils/golden/prometheus.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/golden/prometheus.go b/utils/golden/prometheus.go index 55bce7ba..0fafab39 100644 --- a/utils/golden/prometheus.go +++ b/utils/golden/prometheus.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "runtime" + "strings" "testing" "time" @@ -24,7 +25,7 @@ import ( func DiffPrometheusMetrics(t *testing.T, p prometheus.Gatherer, filter ...func(*dto.MetricFamily) bool) { t.Helper() - goldenFile := "testdata/" + t.Name() + ".golden.txt" + goldenFile := "testdata/" + strings.ReplaceAll(t.Name(), "/", "_") + ".golden.txt" golden, err := os.ReadFile(goldenFile) if err != nil && !os.IsNotExist(err) { t.Fatal(err)