From cc56738a9e5d2969ec8d01f42816ce86671c25d0 Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Fri, 11 Oct 2019 12:31:36 -0700 Subject: [PATCH] Removes unnecessary/irrelevant tests Remove test TestPrintPodTable Removes test TestPrintPodShowLabels --- pkg/printers/internalversion/printers_test.go | 339 ------------------ 1 file changed, 339 deletions(-) diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 266dbf8c3ff..9b35d8423b0 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -19,7 +19,6 @@ package internalversion import ( "bytes" "reflect" - "strconv" "strings" "testing" "time" @@ -27,8 +26,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/kubernetes/pkg/apis/apps" @@ -943,264 +940,6 @@ func TestPrintServiceLoadBalancer(t *testing.T) { } } -func TestPrintHumanReadableWithNamespace(t *testing.T) { - namespaceName := "testnamespace" - name := "test" - table := []struct { - obj runtime.Object - isNamespaced bool - }{ - { - obj: &api.Pod{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - }, - isNamespaced: true, - }, - { - obj: &api.ReplicationController{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Spec: api.ReplicationControllerSpec{ - Replicas: 2, - Template: &api.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - "name": "foo", - "type": "production", - }, - }, - Spec: api.PodSpec{ - Containers: []api.Container{ - { - Image: "foo/bar", - TerminationMessagePath: api.TerminationMessagePathDefault, - ImagePullPolicy: api.PullIfNotPresent, - }, - }, - RestartPolicy: api.RestartPolicyAlways, - DNSPolicy: api.DNSDefault, - NodeSelector: map[string]string{ - "baz": "blah", - }, - }, - }, - }, - }, - isNamespaced: true, - }, - { - obj: &api.Service{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Spec: api.ServiceSpec{ - ClusterIP: "1.2.3.4", - Ports: []api.ServicePort{ - { - Port: 80, - Protocol: "TCP", - }, - }, - }, - Status: api.ServiceStatus{ - LoadBalancer: api.LoadBalancerStatus{ - Ingress: []api.LoadBalancerIngress{ - { - IP: "2.3.4.5", - }, - }, - }, - }, - }, - isNamespaced: true, - }, - { - obj: &api.Endpoints{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Subsets: []api.EndpointSubset{{ - Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}, {IP: "localhost"}}, - Ports: []api.EndpointPort{{Port: 8080}}, - }, - }, - }, - isNamespaced: true, - }, - { - obj: &api.Namespace{ - ObjectMeta: metav1.ObjectMeta{Name: name}, - }, - isNamespaced: false, - }, - { - obj: &api.Secret{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - }, - isNamespaced: true, - }, - { - obj: &api.ServiceAccount{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Secrets: []api.ObjectReference{}, - }, - isNamespaced: true, - }, - { - obj: &api.Node{ - ObjectMeta: metav1.ObjectMeta{Name: name}, - Status: api.NodeStatus{}, - }, - isNamespaced: false, - }, - { - obj: &api.PersistentVolume{ - ObjectMeta: metav1.ObjectMeta{Name: name}, - Spec: api.PersistentVolumeSpec{}, - }, - isNamespaced: false, - }, - { - obj: &api.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Spec: api.PersistentVolumeClaimSpec{}, - }, - isNamespaced: true, - }, - { - obj: &api.Event{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - Source: api.EventSource{Component: "kubelet"}, - Message: "Item 1", - FirstTimestamp: metav1.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)), - LastTimestamp: metav1.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)), - Count: 1, - Type: api.EventTypeNormal, - }, - isNamespaced: true, - }, - { - obj: &api.ResourceQuota{ - ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespaceName}, - }, - isNamespaced: true, - }, - { - obj: &api.ComponentStatus{ - Conditions: []api.ComponentCondition{ - {Type: api.ComponentHealthy, Status: api.ConditionTrue, Message: "ok", Error: ""}, - }, - }, - isNamespaced: false, - }, - } - - //*******// - options := printers.PrintOptions{ - WithNamespace: true, - NoHeaders: true, - } - generator := printers.NewTableGenerator().With(AddHandlers) - printer := printers.NewTablePrinter(options) - for i, test := range table { - table, err := generator.GenerateTable(test.obj, printers.GenerateOptions{}) - if err != nil { - t.Fatalf("An error occurred generating table for object: %#v", err) - } - buffer := &bytes.Buffer{} - err = printer.PrintObj(table, buffer) - if err != nil { - t.Fatalf("An error occurred printing object: %#v", err) - } - if test.isNamespaced { - if !strings.HasPrefix(buffer.String(), namespaceName+" ") { - t.Errorf("%d: Expect printing object %T to contain namespace %q, got %s", i, test.obj, namespaceName, buffer.String()) - } - } else { - if !strings.HasPrefix(buffer.String(), " ") { - t.Errorf("%d: Expect printing object %T to not contain namespace got %s", i, test.obj, buffer.String()) - } - } - } -} - -func TestPrintPodTable(t *testing.T) { - runningPod := &api.Pod{ - ObjectMeta: metav1.ObjectMeta{Name: "test1", Labels: map[string]string{"a": "1", "b": "2"}}, - Spec: api.PodSpec{Containers: make([]api.Container, 2)}, - Status: api.PodStatus{ - Phase: "Running", - ContainerStatuses: []api.ContainerStatus{ - {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, - {RestartCount: 3}, - }, - }, - } - failedPod := &api.Pod{ - ObjectMeta: metav1.ObjectMeta{Name: "test2", Labels: map[string]string{"b": "2"}}, - Spec: api.PodSpec{Containers: make([]api.Container, 2)}, - Status: api.PodStatus{ - Phase: "Failed", - ContainerStatuses: []api.ContainerStatus{ - {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, - {RestartCount: 3}, - }, - }, - } - tests := []struct { - obj runtime.Object - opts printers.PrintOptions - expect string - }{ - { - obj: runningPod, - opts: printers.PrintOptions{}, - expect: "NAME READY STATUS RESTARTS AGE\ntest1 1/2 Running 6 \n", - }, - { - obj: runningPod, - opts: printers.PrintOptions{WithKind: true, Kind: schema.GroupKind{Kind: "Pod"}}, - expect: "NAME READY STATUS RESTARTS AGE\npod/test1 1/2 Running 6 \n", - }, - { - obj: runningPod, - opts: printers.PrintOptions{ShowLabels: true}, - expect: "NAME READY STATUS RESTARTS AGE LABELS\ntest1 1/2 Running 6 a=1,b=2\n", - }, - { - obj: &api.PodList{Items: []api.Pod{*runningPod, *failedPod}}, - opts: printers.PrintOptions{ColumnLabels: []string{"a"}}, - expect: "NAME READY STATUS RESTARTS AGE A\ntest1 1/2 Running 6 1\ntest2 1/2 Failed 6 \n", - }, - { - obj: runningPod, - opts: printers.PrintOptions{NoHeaders: true}, - expect: "test1 1/2 Running 6 \n", - }, - { - obj: failedPod, - opts: printers.PrintOptions{}, - expect: "NAME READY STATUS RESTARTS AGE\ntest2 1/2 Failed 6 \n", - }, - { - obj: failedPod, - opts: printers.PrintOptions{}, - expect: "NAME READY STATUS RESTARTS AGE\ntest2 1/2 Failed 6 \n", - }, - } - - for i, test := range tests { - table, err := printers.NewTableGenerator().With(AddHandlers).GenerateTable(test.obj, printers.GenerateOptions{}) - if err != nil { - t.Fatal(err) - } - verifyTable(t, table) - buf := &bytes.Buffer{} - p := printers.NewTablePrinter(test.opts) - if err := p.PrintObj(table, buf); err != nil { - t.Fatal(err) - } - if test.expect != buf.String() { - t.Errorf("%d mismatch:\n%s\n%s", i, strconv.Quote(test.expect), strconv.Quote(buf.String())) - } - } -} - func TestPrintPod(t *testing.T) { tests := []struct { pod api.Pod @@ -2918,84 +2657,6 @@ func TestPrintHPA(t *testing.T) { } } -func TestPrintPodShowLabels(t *testing.T) { - tests := []struct { - pod api.Pod - showLabels bool - expectLabels []string - }{ - { - // Test name, num of containers, restarts, container ready status - api.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test1", - Labels: map[string]string{"col1": "asd", "COL2": "zxc"}, - }, - Spec: api.PodSpec{Containers: make([]api.Container, 2)}, - Status: api.PodStatus{ - Phase: "podPhase", - ContainerStatuses: []api.ContainerStatus{ - {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, - {RestartCount: 3}, - }, - }, - }, - true, - []string{"col1=asd", "COL2=zxc"}, - }, - { - // Test name, num of containers, restarts, container ready status - api.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test1", - Labels: map[string]string{"col3": "asd", "COL4": "zxc"}, - }, - Spec: api.PodSpec{Containers: make([]api.Container, 2)}, - Status: api.PodStatus{ - Phase: "podPhase", - ContainerStatuses: []api.ContainerStatus{ - {Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}}, - {RestartCount: 3}, - }, - }, - }, - false, - []string{}, - }, - } - - for _, test := range tests { - table, err := printers.NewTableGenerator().With(AddHandlers).GenerateTable(&test.pod, printers.GenerateOptions{}) - if err != nil { - t.Fatal(err) - } - - buf := bytes.NewBuffer([]byte{}) - printer := printers.NewTablePrinter(printers.PrintOptions{ShowLabels: test.showLabels}) - if err := printer.PrintObj(table, buf); err != nil { - t.Errorf("Error printing table: %v", err) - } - - if test.showLabels { - // LABELS column header should be present. - if !strings.Contains(buf.String(), "LABELS") { - t.Errorf("Error Printing Table: missing LABELS column heading: (%s)", buf.String()) - } - // Validate that each of the expected labels is present. - for _, label := range test.expectLabels { - if !strings.Contains(buf.String(), label) { - t.Errorf("Error Printing Table: missing LABEL column value: (%s) from (%s)", label, buf.String()) - } - } - } else { - // LABELS column header should not be present. - if strings.Contains(buf.String(), "LABELS") { - t.Errorf("Error Printing Table: unexpected LABEL column heading: (%s)", buf.String()) - } - } - } -} - func TestPrintService(t *testing.T) { singleExternalIP := []string{"80.11.12.10"} mulExternalIP := []string{"80.11.12.10", "80.11.12.11"}