From 7f644ab469497f977fee92c5e5ec7a142e4ab2a3 Mon Sep 17 00:00:00 2001 From: moriadry Date: Sun, 14 Jul 2019 14:30:08 +0800 Subject: [PATCH] add test case for controller_fetcher and cluster_feeder add test case for controller_fetcher correct comments typo --- .../recommender/input/cluster_feeder_test.go | 8 +++ .../controller_fetcher_test.go | 66 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder_test.go b/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder_test.go index ec4c976ca2fc..cfce8add2909 100644 --- a/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder_test.go @@ -119,6 +119,14 @@ func TestLoadPods(t *testing.T) { expectedConfigUnsupported: nil, expectedConfigDeprecated: nil, }, + { + name: "no targetRef", + selector: parseLabelSelector("app = test"), + fetchSelectorError: nil, + expectedSelector: labels.Nothing(), + expectedConfigUnsupported: nil, + expectedConfigDeprecated: nil, + }, { name: "can't decide if top-level-ref", selector: nil, diff --git a/vertical-pod-autoscaler/pkg/recommender/input/controller_fetcher/controller_fetcher_test.go b/vertical-pod-autoscaler/pkg/recommender/input/controller_fetcher/controller_fetcher_test.go index 337420063aa2..574db5175931 100644 --- a/vertical-pod-autoscaler/pkg/recommender/input/controller_fetcher/controller_fetcher_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/input/controller_fetcher/controller_fetcher_test.go @@ -24,6 +24,8 @@ import ( "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" + batchv1 "k8s.io/api/batch/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/cache" @@ -117,6 +119,70 @@ func TestControllerFetcher(t *testing.T) { Name: "test-deployment", Kind: "Deployment", Namespace: "test-namesapce"}}, // Deployment has no parent expectedError: nil, }, + { + key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-statefulset", Kind: "StatefulSet", Namespace: "test-namesapce"}}, + objects: []runtime.Object{&appsv1.StatefulSet{ + TypeMeta: metav1.TypeMeta{ + Kind: "StatefulSet", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-statefulset", + Namespace: "test-namesapce", + }, + }}, + expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-statefulset", Kind: "StatefulSet", Namespace: "test-namesapce"}}, // StatefulSet has no parent + expectedError: nil, + }, + { + key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-daemonset", Kind: "DaemonSet", Namespace: "test-namesapce"}}, + objects: []runtime.Object{&appsv1.DaemonSet{ + TypeMeta: metav1.TypeMeta{ + Kind: "DaemonSet", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-daemonset", + Namespace: "test-namesapce", + }, + }}, + expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-daemonset", Kind: "DaemonSet", Namespace: "test-namesapce"}}, // DaemonSet has no parent + expectedError: nil, + }, + { + key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-job", Kind: "Job", Namespace: "test-namesapce"}}, + objects: []runtime.Object{&batchv1.Job{ + TypeMeta: metav1.TypeMeta{ + Kind: "Job", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-job", + Namespace: "test-namesapce", + }, + }}, + expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-job", Kind: "Job", Namespace: "test-namesapce"}}, // Job has no parent + expectedError: nil, + }, + { + key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-rc", Kind: "ReplicationController", Namespace: "test-namesapce"}}, + objects: []runtime.Object{&corev1.ReplicationController{ + TypeMeta: metav1.TypeMeta{ + Kind: "ReplicationController", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-rc", + Namespace: "test-namesapce", + }, + }}, + expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ + Name: "test-rc", Kind: "ReplicationController", Namespace: "test-namesapce"}}, // ReplicationController has no parent + expectedError: nil, + }, { key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{ Name: "test-deployment", Kind: "Deployment", Namespace: "test-namesapce"}},