From 131d612b13c3bfbe04a1fed9c1d8d2e3c8ec558a Mon Sep 17 00:00:00 2001 From: YuxiJin-tobeyjin Date: Fri, 27 Oct 2017 10:39:09 +0800 Subject: [PATCH] Add unit test for get pod -o wide --- pkg/printers/internalversion/printers_test.go | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index f15250dfb09..c6c84137285 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -1673,6 +1673,65 @@ func TestPrintPod(t *testing.T) { } } +func TestPrintPodwide(t *testing.T) { + tests := []struct { + pod api.Pod + expect []metav1alpha1.TableRow + }{ + { + // Test when the NodeName and PodIP are not none + api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "test1"}, + Spec: api.PodSpec{ + Containers: make([]api.Container, 2), + NodeName: "test1", + }, + Status: api.PodStatus{ + Phase: "podPhase", + PodIP: "1.1.1.1", + ContainerStatuses: []api.ContainerStatus{ + {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, + {RestartCount: 3}, + }, + }, + }, + []metav1alpha1.TableRow{{Cells: []interface{}{"test1", "1/2", "podPhase", 6, "", "1.1.1.1", "test1"}}}, + }, + { + // Test when the NodeName and PodIP are none + api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "test2"}, + Spec: api.PodSpec{ + Containers: make([]api.Container, 2), + NodeName: "", + }, + Status: api.PodStatus{ + Phase: "podPhase", + PodIP: "", + ContainerStatuses: []api.ContainerStatus{ + {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, + {State: api.ContainerState{Waiting: &api.ContainerStateWaiting{Reason: "ContainerWaitingReason"}}, RestartCount: 3}, + }, + }, + }, + []metav1alpha1.TableRow{{Cells: []interface{}{"test2", "1/2", "ContainerWaitingReason", 6, "", "", ""}}}, + }, + } + + for i, test := range tests { + rows, err := printPod(&test.pod, printers.PrintOptions{Wide: true}) + if err != nil { + t.Fatal(err) + } + for i := range rows { + rows[i].Object.Object = nil + } + if !reflect.DeepEqual(test.expect, rows) { + t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expect, rows)) + } + } +} + func TestPrintPodList(t *testing.T) { tests := []struct { pods api.PodList