Unverified Commit a80985a2 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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
parents 35e97841 131d612b
...@@ -1672,6 +1672,65 @@ func TestPrintPod(t *testing.T) { ...@@ -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) { func TestPrintPodList(t *testing.T) {
tests := []struct { tests := []struct {
pods api.PodList pods api.PodList
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment