From fc4994c93c739aabbf873535ec1951be4aa839bc Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 22 Aug 2018 23:54:26 +0200 Subject: [PATCH] Remove removeUnusedWhitespace It wasn't needed, as is now proven by the tests Signed-off-by: beorn7 --- testutils/testutils.go | 23 ----------------------- testutils/testutils_test.go | 3 ++- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/testutils/testutils.go b/testutils/testutils.go index c6da37b..c732a03 100644 --- a/testutils/testutils.go +++ b/testutils/testutils.go @@ -21,7 +21,6 @@ import ( "fmt" "reflect" "sort" - "strings" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" @@ -32,8 +31,6 @@ import ( // to an expected output in the Prometheus text exposition format. // metricNames allows only comparing the given metrics. All are compared if it's nil. func GatherAndCompare(c prometheus.Collector, expected string, metricNames ...string) error { - expected = removeUnusedWhitespace(expected) - reg := prometheus.NewPedanticRegistry() if err := reg.Register(c); err != nil { return fmt.Errorf("registering collector failed: %s", err) @@ -100,26 +97,6 @@ func filterMetrics(metrics []*dto.MetricFamily, names []string) []*dto.MetricFam return filtered } -func removeUnusedWhitespace(s string) string { - var ( - trimmedLine string - trimmedLines []string - lines = strings.Split(s, "\n") - ) - - for _, l := range lines { - trimmedLine = strings.TrimSpace(l) - - if len(trimmedLine) > 0 { - trimmedLines = append(trimmedLines, trimmedLine) - } - } - - // The Prometheus metrics representation parser expects an empty line at the - // end otherwise fails with an unexpected EOF error. - return strings.Join(trimmedLines, "\n") + "\n" -} - // The below sorting code is copied form the Prometheus client library modulo the added // label pair sorting. // https://github.com/prometheus/client_golang/blob/ea6e1db4cb8127eeb0b6954f7320363e5451820f/prometheus/registry.go#L642-L684 diff --git a/testutils/testutils_test.go b/testutils/testutils_test.go index 96ad971..54bdf8e 100644 --- a/testutils/testutils_test.go +++ b/testutils/testutils_test.go @@ -22,7 +22,8 @@ func TestGatherAndCompare(t *testing.T) { c.Inc() expected := ` - some_total{label1="value1"} 1 + + some_total{ label1 = "value1" } 1 ` if err := GatherAndCompare(c, metadata+expected, "some_total"); err != nil {