make kubectl get generic with respect to objects

This commit is contained in:
deads2k
2016-11-02 12:29:01 -04:00
parent 7fe9bd4c30
commit 61673c4b39
16 changed files with 410 additions and 394 deletions

View File

@@ -19,7 +19,6 @@ package cmd
import (
"bytes"
encjson "encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
@@ -37,10 +36,8 @@ import (
"k8s.io/kubernetes/pkg/client/restclient/fake"
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime/serializer"
"k8s.io/kubernetes/pkg/runtime/serializer/json"
"k8s.io/kubernetes/pkg/runtime/serializer/streaming"
"k8s.io/kubernetes/pkg/util/diff"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch/versioned"
)
@@ -120,10 +117,11 @@ func testComponentStatusData() *api.ComponentStatusList {
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func TestGetUnknownSchemaObject(t *testing.T) {
f, tf, codec, ns := cmdtesting.NewTestFactory()
f, tf, _, _ := cmdtesting.NewAPIFactory()
_, _, codec, _ := cmdtesting.NewTestFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", "foo"))},
}
tf.Namespace = "test"
@@ -135,114 +133,39 @@ func TestGetUnknownSchemaObject(t *testing.T) {
cmd.SetOutput(buf)
cmd.Run(cmd, []string{"type", "foo"})
expected := cmdtesting.NewInternalType("", "", "foo")
actual := tf.Printer.(*testPrinter).Objects[0]
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
expected := []runtime.Object{cmdtesting.NewInternalType("", "", "foo")}
actual := tf.Printer.(*testPrinter).Objects
if len(actual) != len(expected) {
t.Fatal(actual)
}
if buf.String() != fmt.Sprintf("%#v", expected) {
t.Errorf("unexpected output: %s", buf.String())
}
}
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
// Because api.List is part of the Kube API, resource.Builder has to perform a conversion on
// api.Scheme, which may not have access to all objects, and not all objects are at the same
// internal versioning scheme. This test verifies that two isolated schemes (Test, and api.Scheme)
// can be conjoined into a single output object.
//
// The expected behavior of the `kubectl get` command is:
// 1. objects using unrecognized schemes will always be returned using that scheme/version, "unlikelyversion" in this test;
// 2. if the specified output-version is a recognized, valid Scheme, then the list should use that scheme, and otherwise it will default to the client version, registered.GroupOrDie(api.GroupName).GroupVersion.String() in this test;
// 3a. if the specified output-version is a recognized, valid Scheme, in which the requested object (replicationcontroller) can be represented, then the object should be returned using that version;
// 3b. otherwise if the specified output-version is unrecognized, but the requested object (replicationcontroller) is recognized by the client's codec, then it will be converted to the client version, registered.GroupOrDie(api.GroupName).GroupVersion.String() in this test.
func TestGetUnknownSchemaObjectListGeneric(t *testing.T) {
testCases := map[string]struct {
outputVersion string
listVersion string
testtypeVersion string
rcVersion string
}{
"handles specific version": {
outputVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
listVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
testtypeVersion: cmdtesting.UnlikelyGV.String(),
rcVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
},
"handles second specific version": {
outputVersion: "unlikely.group/unlikelyversion",
listVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
testtypeVersion: cmdtesting.UnlikelyGV.String(),
rcVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(), // see expected behavior 3b
},
"handles common version": {
outputVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
listVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
testtypeVersion: cmdtesting.UnlikelyGV.String(),
rcVersion: registered.GroupOrDie(api.GroupName).GroupVersion.String(),
},
}
for k, test := range testCases {
apiCodec := testapi.Default.Codec()
apiNegotiatedSerializer := testapi.Default.NegotiatedSerializer()
regularClient := &fake.RESTClient{
NegotiatedSerializer: apiNegotiatedSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(apiCodec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})}, nil
}),
for i, obj := range actual {
expectedJSON := runtime.EncodeOrDie(codec, expected[i])
expectedMap := map[string]interface{}{}
if err := encjson.Unmarshal([]byte(expectedJSON), &expectedMap); err != nil {
t.Fatal(err)
}
f, tf, codec := cmdtesting.NewMixedFactory(regularClient)
negotiatedSerializer := serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec})
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: negotiatedSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", "foo"))}, nil
}),
actualJSON := runtime.EncodeOrDie(api.Codecs.LegacyCodec(), obj)
actualMap := map[string]interface{}{}
if err := encjson.Unmarshal([]byte(actualJSON), &actualMap); err != nil {
t.Fatal(err)
}
tf.Namespace = "test"
tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &registered.GroupOrDie(api.GroupName).GroupVersion}}
buf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmd := NewCmdGet(f, buf, errBuf)
cmd.SetOutput(buf)
cmd.Flags().Set("output", "json")
cmd.Flags().Set("output-version", test.outputVersion)
err := RunGet(f, buf, errBuf, cmd, []string{"type/foo", "replicationcontrollers/foo"}, &GetOptions{})
if err != nil {
t.Errorf("%s: unexpected error: %v", k, err)
continue
}
out := make(map[string]interface{})
if err := encjson.Unmarshal(buf.Bytes(), &out); err != nil {
t.Errorf("%s: unexpected error: %v\n%s", k, err, buf.String())
continue
}
if out["apiVersion"] != test.listVersion {
t.Errorf("%s: unexpected list: %#v", k, out)
}
arr := out["items"].([]interface{})
if arr[0].(map[string]interface{})["apiVersion"] != test.testtypeVersion {
t.Errorf("%s: unexpected list: %#v", k, out)
}
if arr[1].(map[string]interface{})["apiVersion"] != test.rcVersion {
t.Errorf("%s: unexpected list: %#v", k, out)
if !reflect.DeepEqual(expectedMap, actualMap) {
t.Errorf("unexpected object: \n%#v\n%#v", expectedMap, actualMap)
}
}
}
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func TestGetSchemaObject(t *testing.T) {
f, tf, _, _ := cmdtesting.NewTestFactory()
f, tf, _, _ := cmdtesting.NewAPIFactory()
tf.Mapper = testapi.Default.RESTMapper()
tf.Typer = api.Scheme
codec := testapi.Default.Codec()
ns := testapi.Default.NegotiatedSerializer()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})},
}
tf.Namespace = "test"
@@ -261,10 +184,10 @@ func TestGetSchemaObject(t *testing.T) {
func TestGetObjects(t *testing.T) {
pods, _, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
}
tf.Namespace = "test"
@@ -276,10 +199,8 @@ func TestGetObjects(t *testing.T) {
cmd.Run(cmd, []string{"pods", "foo"})
expected := []runtime.Object{&pods.Items[0]}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -306,10 +227,10 @@ func TestGetSortedObjects(t *testing.T) {
},
}
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
}
tf.Namespace = "test"
@@ -327,23 +248,37 @@ func TestGetSortedObjects(t *testing.T) {
// expect sorted: a,b,c
expected := []runtime.Object{&pods.Items[2], &pods.Items[1], &pods.Items[0]}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
}
func verifyObjects(t *testing.T, expected, actual []runtime.Object) {
if len(actual) != len(expected) {
t.Fatal(actual)
}
for i, obj := range actual {
actualObj, err := runtime.Decode(
api.Codecs.UniversalDecoder(),
[]byte(runtime.EncodeOrDie(api.Codecs.LegacyCodec(), obj)))
if err != nil {
t.Fatal(err)
}
if !api.Semantic.DeepEqual(expected[i], actualObj) {
t.Errorf("unexpected object: \n%#v\n%#v", expected[i], actualObj)
}
}
}
func TestGetObjectsIdentifiedByFile(t *testing.T) {
pods, _, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
}
tf.Namespace = "test"
@@ -356,10 +291,8 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
cmd.Run(cmd, []string{})
expected := []runtime.Object{&pods.Items[0]}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -368,10 +301,10 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
func TestGetListObjects(t *testing.T) {
pods, _, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
}
tf.Namespace = "test"
@@ -384,12 +317,10 @@ func TestGetListObjects(t *testing.T) {
expected, err := extractResourceList([]runtime.Object{pods})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: expected %#v, got %#v", expected, actual)
t.Fatal(err)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -412,10 +343,10 @@ func extractResourceList(objs []runtime.Object) ([]runtime.Object, error) {
func TestGetAllListObjects(t *testing.T) {
pods, _, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
}
tf.Namespace = "test"
@@ -429,12 +360,10 @@ func TestGetAllListObjects(t *testing.T) {
expected, err := extractResourceList([]runtime.Object{pods})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v %#v", expected, actual)
t.Fatal(err)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -443,10 +372,10 @@ func TestGetAllListObjects(t *testing.T) {
func TestGetListComponentStatus(t *testing.T) {
statuses := testComponentStatusData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, statuses)},
}
tf.Namespace = "test"
@@ -459,12 +388,10 @@ func TestGetListComponentStatus(t *testing.T) {
expected, err := extractResourceList([]runtime.Object{statuses})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: expected %#v, got %#v", expected, actual)
t.Fatal(err)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -473,10 +400,10 @@ func TestGetListComponentStatus(t *testing.T) {
func TestGetMultipleTypeObjects(t *testing.T) {
pods, svc, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods":
@@ -499,12 +426,10 @@ func TestGetMultipleTypeObjects(t *testing.T) {
expected, err := extractResourceList([]runtime.Object{pods, svc})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
t.Fatal(err)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -513,10 +438,10 @@ func TestGetMultipleTypeObjects(t *testing.T) {
func TestGetMultipleTypeObjectsAsList(t *testing.T) {
pods, svc, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods":
@@ -574,10 +499,10 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
pods, svc, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(registered.GroupOrDie(api.GroupName).GroupVersion.String())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@@ -605,12 +530,10 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
expected, err := extractResourceList([]runtime.Object{pods, svc})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
t.Fatal(err)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -627,10 +550,10 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
},
}
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/nodes/foo":
@@ -653,10 +576,8 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
cmd.Run(cmd, []string{"services/bar", "node/foo"})
expected := []runtime.Object{&svc.Items[0], node}
actual := tf.Printer.(*testPrinter).Objects
if !api.Semantic.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %s", diff.ObjectDiff(expected, actual))
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -665,10 +586,10 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
func TestGetByNameForcesFlag(t *testing.T) {
pods, _, _ := testData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])},
}
tf.Namespace = "test"
@@ -758,7 +679,7 @@ func watchTestData() ([]api.Pod, []watch.Event) {
func TestWatchSelector(t *testing.T) {
pods, events := watchTestData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
podList := &api.PodList{
Items: pods,
@@ -767,7 +688,7 @@ func TestWatchSelector(t *testing.T) {
},
}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
if req.URL.Query().Get(unversioned.LabelSelectorQueryParam(registered.GroupOrDie(api.GroupName).GroupVersion.String())) != "a=b" {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
@@ -795,10 +716,8 @@ func TestWatchSelector(t *testing.T) {
cmd.Run(cmd, []string{"pods"})
expected := []runtime.Object{podList, events[2].Object, events[3].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object:\nExpected: %#v\n\nGot: %#v\n\n", expected, actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -807,10 +726,10 @@ func TestWatchSelector(t *testing.T) {
func TestWatchResource(t *testing.T) {
pods, events := watchTestData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/foo":
@@ -834,10 +753,8 @@ func TestWatchResource(t *testing.T) {
cmd.Run(cmd, []string{"pods", "foo"})
expected := []runtime.Object{&pods[1], events[2].Object, events[3].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object:\nExpected: %#v\n\nGot: %#v\n\n", expected, actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -846,10 +763,10 @@ func TestWatchResource(t *testing.T) {
func TestWatchResourceIdentifiedByFile(t *testing.T) {
pods, events := watchTestData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/replicationcontrollers/cassandra":
@@ -874,10 +791,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
cmd.Run(cmd, []string{})
expected := []runtime.Object{&pods[1], events[2].Object, events[3].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("expected object: %#v unexpected object: %#v", expected, actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
@@ -887,10 +801,10 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
func TestWatchOnlyResource(t *testing.T) {
pods, events := watchTestData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods/foo":
@@ -914,10 +828,8 @@ func TestWatchOnlyResource(t *testing.T) {
cmd.Run(cmd, []string{"pods", "foo"})
expected := []runtime.Object{events[2].Object, events[3].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}
@@ -926,7 +838,7 @@ func TestWatchOnlyResource(t *testing.T) {
func TestWatchOnlyList(t *testing.T) {
pods, events := watchTestData()
f, tf, codec, ns := cmdtesting.NewAPIFactory()
f, tf, codec, _ := cmdtesting.NewAPIFactory()
tf.Printer = &testPrinter{}
podList := &api.PodList{
Items: pods,
@@ -935,7 +847,7 @@ func TestWatchOnlyList(t *testing.T) {
},
}
tf.Client = &fake.RESTClient{
NegotiatedSerializer: ns,
NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
switch req.URL.Path {
case "/namespaces/test/pods":
@@ -959,10 +871,8 @@ func TestWatchOnlyList(t *testing.T) {
cmd.Run(cmd, []string{"pods"})
expected := []runtime.Object{events[2].Object, events[3].Object}
actual := tf.Printer.(*testPrinter).Objects
if !reflect.DeepEqual(expected, actual) {
t.Errorf("unexpected object: %#v", actual)
}
verifyObjects(t, expected, tf.Printer.(*testPrinter).Objects)
if len(buf.String()) == 0 {
t.Errorf("unexpected empty output")
}