From 3b07393ea84c57b0c5b995045a2b983df7821d93 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Thu, 10 Oct 2019 15:13:43 +0800 Subject: [PATCH] Refactor UT with testutil from k/k. --- pkg/kubelet/metrics/collectors/log_metrics_test.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/metrics/collectors/log_metrics_test.go b/pkg/kubelet/metrics/collectors/log_metrics_test.go index 0a5687d9000..2006973b977 100644 --- a/pkg/kubelet/metrics/collectors/log_metrics_test.go +++ b/pkg/kubelet/metrics/collectors/log_metrics_test.go @@ -20,25 +20,19 @@ import ( "strings" "testing" - "github.com/prometheus/client_golang/prometheus" - "k8s.io/component-base/metrics/testutil" statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1" ) func TestNoMetricsCollected(t *testing.T) { - ch := make(chan prometheus.Metric) - collector := &logMetricsCollector{ podStats: func() ([]statsapi.PodStats, error) { return []statsapi.PodStats{}, nil }, } - collector.Collect(ch) - num := len(ch) - if num != 0 { - t.Fatalf("Channel expected to be empty, but received %d", num) + if err := testutil.CollectAndCompare(collector, strings.NewReader(""), ""); err != nil { + t.Fatal(err) } }