Skip to content

Commit

Permalink
add unit tests for portforwarder (helm#4979)
Browse files Browse the repository at this point in the history
Signed-off-by: tariqibrahim <tariq.ibrahim@microsoft.com>
  • Loading branch information
tariq1890 authored and Matthew Fisher committed Dec 4, 2018
1 parent 58be8e4 commit 99199c9
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/helm/portforwarder/portforwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 99199c9

Please sign in to comment.