From c5774a703ddb1f651ef41906c214d4d730f6d410 Mon Sep 17 00:00:00 2001 From: Damien Grisonnet Date: Fri, 3 Feb 2023 20:35:52 +0100 Subject: [PATCH] component-base: add ScrapeAndCompare wrapper Signed-off-by: Damien Grisonnet --- .../src/k8s.io/component-base/metrics/testutil/testutil.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/staging/src/k8s.io/component-base/metrics/testutil/testutil.go b/staging/src/k8s.io/component-base/metrics/testutil/testutil.go index 439045989ce..8587c752242 100644 --- a/staging/src/k8s.io/component-base/metrics/testutil/testutil.go +++ b/staging/src/k8s.io/component-base/metrics/testutil/testutil.go @@ -67,6 +67,13 @@ func CustomCollectAndCompare(c metrics.StableCollector, expected io.Reader, metr return GatherAndCompare(registry, expected, metricNames...) } +// ScrapeAndCompare calls a remote exporter's endpoint which is expected to return some metrics in +// plain text format. Then it compares it with the results that the `expected` would return. +// If the `metricNames` is not empty it would filter the comparison only to the given metric names. +func ScrapeAndCompare(url string, expected io.Reader, metricNames ...string) error { + return testutil.ScrapeAndCompare(url, expected, metricNames...) +} + // NewFakeKubeRegistry creates a fake `KubeRegistry` that takes the input version as `build in version`. // It should only be used in testing scenario especially for the deprecated metrics. // The input version format should be `major.minor.patch`, e.g. '1.18.0'.