From 99199c975236430fdf7599c69a956c6eb73b44e9 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Tue, 4 Dec 2018 08:25:38 -0800 Subject: [PATCH] add unit tests for portforwarder (#4979) Signed-off-by: tariqibrahim --- pkg/helm/portforwarder/portforwarder_test.go | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/helm/portforwarder/portforwarder_test.go b/pkg/helm/portforwarder/portforwarder_test.go index f5efe3443..2809bcbff 100644 --- a/pkg/helm/portforwarder/portforwarder_test.go +++ b/pkg/helm/portforwarder/portforwarder_test.go @@ -85,3 +85,54 @@ func TestGetFirstPod(t *testing.T) { } } } + +func TestGetTillerPodImage(t *testing.T) { + tests := []struct { + name string + podSpec v1.PodSpec + expected string + err bool + }{ + { + name: "pod with tiller container image", + podSpec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "tiller", + Image: "gcr.io/kubernetes-helm/tiller:v2.0.0", + }, + }, + }, + expected: "gcr.io/kubernetes-helm/tiller:v2.0.0", + err: false, + }, + { + name: "pod without tiller container image", + podSpec: v1.PodSpec{ + Containers: []v1.Container{ + { + Name: "not_tiller", + Image: "gcr.io/kubernetes-helm/not_tiller:v1.0.0", + }, + }, + }, + expected: "", + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mockPod := mockTillerPod() + mockPod.Spec = tt.podSpec + client := fake.NewSimpleClientset(&v1.PodList{Items: []v1.Pod{mockPod}}) + imageName, err := GetTillerPodImage(client.CoreV1(), v1.NamespaceDefault) + if (err != nil) != tt.err { + t.Errorf("%q. expected error: %v, got %v", tt.name, tt.err, err) + } + if imageName != tt.expected { + t.Errorf("%q. expected %q, got %q", tt.name, tt.expected, imageName) + } + }) + } +}