Skip to content
Permalink
Browse files

Add a test for fake metrics.k8s.io Clientset.

This test demonstrates the fix in
#75486.
  • Loading branch information...
misterikkit committed Mar 20, 2019
1 parent 40e1f0f commit 891f448ea6db75e11840d3396bd56abd2f73d88e
@@ -13,6 +13,7 @@ filegroup(
"//staging/src/k8s.io/metrics/pkg/apis/external_metrics:all-srcs",
"//staging/src/k8s.io/metrics/pkg/apis/metrics:all-srcs",
"//staging/src/k8s.io/metrics/pkg/client/clientset/versioned:all-srcs",
"//staging/src/k8s.io/metrics/pkg/client/clientset_test:all-srcs",
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics:all-srcs",
"//staging/src/k8s.io/metrics/pkg/client/external_metrics:all-srcs",
],
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "go_default_test",
srcs = ["clientset_test.go"],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/metrics/pkg/client/clientset/versioned/fake:go_default_library",
],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
@@ -0,0 +1,25 @@
package clientset_test

import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/metrics/pkg/client/clientset/versioned/fake"
)

// TestList is a basic sanity check that makes sure the fake Clientset is working properly.
func TestList(t *testing.T) {
client := fake.NewSimpleClientset()
if _, err := client.MetricsV1alpha1().PodMetricses("").List(metav1.ListOptions{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if _, err := client.MetricsV1alpha1().NodeMetricses().List(metav1.ListOptions{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if _, err := client.MetricsV1beta1().PodMetricses("").List(metav1.ListOptions{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if _, err := client.MetricsV1beta1().NodeMetricses().List(metav1.ListOptions{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

0 comments on commit 891f448

Please sign in to comment.
You can’t perform that action at this time.