Merge pull request #54617 from YuxiJin-tobeyjin/printpodwide

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Add unit test for get pod -o wide

**What this PR does / why we need it**:
Add unit test for get pod -o wide;
In func printPod, one can choose to use "options.Wide", so unit test is needed accordingly.

**Release note**:

```release-note
```
NONE
This commit is contained in:
Kubernetes Submit Queue 2017-10-31 11:32:12 -07:00 committed by GitHub
commit a80985a283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1672,6 +1672,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, "<unknown>", "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, "<unknown>", "<none>", "<none>"}}},
},
}
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