From 3b07393ea84c57b0c5b995045a2b983df7821d93 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Thu, 10 Oct 2019 15:13:43 +0800 Subject: [PATCH 1/2] 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) } } From 633bb52b497df98cf0e2be4509c087f450b7a920 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Thu, 10 Oct 2019 15:19:42 +0800 Subject: [PATCH 2/2] Deal with auto-generated files. Update bazel by hack/update-bazel.sh --- pkg/kubelet/metrics/collectors/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/kubelet/metrics/collectors/BUILD b/pkg/kubelet/metrics/collectors/BUILD index 328688e3d19..2a6f0e88125 100644 --- a/pkg/kubelet/metrics/collectors/BUILD +++ b/pkg/kubelet/metrics/collectors/BUILD @@ -30,7 +30,6 @@ go_test( "//pkg/kubelet/server/stats/testing:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/component-base/metrics/testutil:go_default_library", - "//vendor/github.com/prometheus/client_golang/prometheus:go_default_library", ], )