Hide failed/succeeded pods in 'kubectl get pods' by default
This commit is contained in:
@@ -237,18 +237,18 @@ type TestUnknownType struct{}
|
||||
|
||||
func (*TestUnknownType) IsAnAPIObject() {}
|
||||
|
||||
func PrintCustomType(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, columnLabels []string) error {
|
||||
func PrintCustomType(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, showAll bool, columnLabels []string) error {
|
||||
_, err := fmt.Fprintf(w, "%s", obj.Data)
|
||||
return err
|
||||
}
|
||||
|
||||
func ErrorPrintHandler(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, columnLabels []string) error {
|
||||
func ErrorPrintHandler(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, showAll bool, columnLabels []string) error {
|
||||
return fmt.Errorf("ErrorPrintHandler error")
|
||||
}
|
||||
|
||||
func TestCustomTypePrinting(t *testing.T) {
|
||||
columns := []string{"Data"}
|
||||
printer := NewHumanReadablePrinter(false, false, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, false, false, false, []string{})
|
||||
printer.Handler(columns, PrintCustomType)
|
||||
|
||||
obj := TestPrintType{"test object"}
|
||||
@@ -265,7 +265,7 @@ func TestCustomTypePrinting(t *testing.T) {
|
||||
|
||||
func TestPrintHandlerError(t *testing.T) {
|
||||
columns := []string{"Data"}
|
||||
printer := NewHumanReadablePrinter(false, false, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, false, false, false, []string{})
|
||||
printer.Handler(columns, ErrorPrintHandler)
|
||||
obj := TestPrintType{"test object"}
|
||||
buffer := &bytes.Buffer{}
|
||||
@@ -276,7 +276,7 @@ func TestPrintHandlerError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnknownTypePrinting(t *testing.T) {
|
||||
printer := NewHumanReadablePrinter(false, false, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, false, false, false, []string{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(&TestUnknownType{}, buffer)
|
||||
if err == nil {
|
||||
@@ -451,8 +451,8 @@ func TestPrinters(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
printers := map[string]ResourcePrinter{
|
||||
"humanReadable": NewHumanReadablePrinter(true, false, false, []string{}),
|
||||
"humanReadableHeaders": NewHumanReadablePrinter(false, false, false, []string{}),
|
||||
"humanReadable": NewHumanReadablePrinter(true, false, false, false, []string{}),
|
||||
"humanReadableHeaders": NewHumanReadablePrinter(false, false, false, false, []string{}),
|
||||
"json": &JSONPrinter{},
|
||||
"yaml": &YAMLPrinter{},
|
||||
"template": templatePrinter,
|
||||
@@ -489,7 +489,7 @@ func TestPrinters(t *testing.T) {
|
||||
|
||||
func TestPrintEventsResultSorted(t *testing.T) {
|
||||
// Arrange
|
||||
printer := NewHumanReadablePrinter(false /* noHeaders */, false, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false /* noHeaders */, false, false, false, []string{})
|
||||
|
||||
obj := api.EventList{
|
||||
Items: []api.Event{
|
||||
@@ -530,7 +530,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintMinionStatus(t *testing.T) {
|
||||
printer := NewHumanReadablePrinter(false, false, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, false, false, false, []string{})
|
||||
table := []struct {
|
||||
minion api.Node
|
||||
status string
|
||||
@@ -741,7 +741,7 @@ func TestPrintHumanReadableService(t *testing.T) {
|
||||
|
||||
for _, svc := range tests {
|
||||
buff := bytes.Buffer{}
|
||||
printService(&svc, &buff, false, false, []string{})
|
||||
printService(&svc, &buff, false, false, false, []string{})
|
||||
output := string(buff.Bytes())
|
||||
ip := svc.Spec.ClusterIP
|
||||
if !strings.Contains(output, ip) {
|
||||
@@ -922,7 +922,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
for _, test := range table {
|
||||
if test.isNamespaced {
|
||||
// Expect output to include namespace when requested.
|
||||
printer := NewHumanReadablePrinter(false, true, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, true, false, false, []string{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err != nil {
|
||||
@@ -934,7 +934,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
}
|
||||
} else {
|
||||
// Expect error when trying to get all namespaces for un-namespaced object.
|
||||
printer := NewHumanReadablePrinter(false, true, false, []string{})
|
||||
printer := NewHumanReadablePrinter(false, true, false, false, []string{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err == nil {
|
||||
@@ -1029,7 +1029,100 @@ func TestPrintPod(t *testing.T) {
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
for _, test := range tests {
|
||||
printPod(&test.pod, buf, false, false, []string{})
|
||||
printPod(&test.pod, buf, false, false, true, []string{})
|
||||
// We ignore time
|
||||
if !strings.HasPrefix(buf.String(), test.expect) {
|
||||
t.Fatalf("Expected: %s, got: %s", test.expect, buf.String())
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintNonTerminatedPod(t *testing.T) {
|
||||
tests := []struct {
|
||||
pod api.Pod
|
||||
expect string
|
||||
}{
|
||||
{
|
||||
// Test pod phase Running should be printed
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "test1"},
|
||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
"test1\t1/2\tRunning\t6\t",
|
||||
},
|
||||
{
|
||||
// Test pod phase Pending should be printed
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "test2"},
|
||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodPending,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
"test2\t1/2\tPending\t6\t",
|
||||
},
|
||||
{
|
||||
// Test pod phase Unknown should be printed
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "test3"},
|
||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodUnknown,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
"test3\t1/2\tUnknown\t6\t",
|
||||
},
|
||||
{
|
||||
// Test pod phase Succeeded shouldn't be printed
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "test4"},
|
||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodSucceeded,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
// Test pod phase Failed shouldn't be printed
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "test5"},
|
||||
Spec: api.PodSpec{Containers: make([]api.Container, 2)},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodFailed,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{Ready: true, RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
for _, test := range tests {
|
||||
printPod(&test.pod, buf, false, false, false, []string{})
|
||||
// We ignore time
|
||||
if !strings.HasPrefix(buf.String(), test.expect) {
|
||||
t.Fatalf("Expected: %s, got: %s", test.expect, buf.String())
|
||||
@@ -1089,7 +1182,7 @@ func TestPrintPodWithLabels(t *testing.T) {
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
for _, test := range tests {
|
||||
printPod(&test.pod, buf, false, false, test.labelColumns)
|
||||
printPod(&test.pod, buf, false, false, false, test.labelColumns)
|
||||
// We ignore time
|
||||
if !strings.HasPrefix(buf.String(), test.startsWith) || !strings.HasSuffix(buf.String(), test.endsWith) {
|
||||
t.Fatalf("Expected to start with: %s and end with: %s, but got: %s", test.startsWith, test.endsWith, buf.String())
|
||||
|
Reference in New Issue
Block a user