mirror of https://github.com/k3s-io/k3s
Add unit test for get pod -o wide
parent
c0a519be1f
commit
131d612b13
|
@ -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, "<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
|
||||
|
|
Loading…
Reference in New Issue