Refactor UT with testutil from k/k.
This commit is contained in:
parent
77f86630d4
commit
3b07393ea8
@ -20,25 +20,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
|
|
||||||
"k8s.io/component-base/metrics/testutil"
|
"k8s.io/component-base/metrics/testutil"
|
||||||
statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNoMetricsCollected(t *testing.T) {
|
func TestNoMetricsCollected(t *testing.T) {
|
||||||
ch := make(chan prometheus.Metric)
|
|
||||||
|
|
||||||
collector := &logMetricsCollector{
|
collector := &logMetricsCollector{
|
||||||
podStats: func() ([]statsapi.PodStats, error) {
|
podStats: func() ([]statsapi.PodStats, error) {
|
||||||
return []statsapi.PodStats{}, nil
|
return []statsapi.PodStats{}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
collector.Collect(ch)
|
|
||||||
|
|
||||||
num := len(ch)
|
if err := testutil.CollectAndCompare(collector, strings.NewReader(""), ""); err != nil {
|
||||||
if num != 0 {
|
t.Fatal(err)
|
||||||
t.Fatalf("Channel expected to be empty, but received %d", num)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user