diff --git a/pkg/kubectl/cmd/annotate_test.go b/pkg/kubectl/cmd/annotate_test.go index a9ee8d69596..7fff598ca02 100644 --- a/pkg/kubectl/cmd/annotate_test.go +++ b/pkg/kubectl/cmd/annotate_test.go @@ -417,12 +417,12 @@ func TestAnnotateErrors(t *testing.T) { } for k, testCase := range testCases { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdAnnotate(f, buf) + cmd := NewCmdAnnotate(tf, buf) cmd.SetOutput(buf) for k, v := range testCase.flags { @@ -446,7 +446,7 @@ func TestAnnotateErrors(t *testing.T) { func TestAnnotateObject(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -477,10 +477,10 @@ func TestAnnotateObject(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdAnnotate(f, buf) + cmd := NewCmdAnnotate(tf, buf) cmd.SetOutput(buf) options := &AnnotateOptions{} args := []string{"pods/foo", "a=b", "c-"} @@ -490,7 +490,7 @@ func TestAnnotateObject(t *testing.T) { if err := options.Validate(); err != nil { t.Fatalf("unexpected error: %v", err) } - if err := options.RunAnnotate(f, cmd); err != nil { + if err := options.RunAnnotate(tf, cmd); err != nil { t.Fatalf("unexpected error: %v", err) } } @@ -498,7 +498,7 @@ func TestAnnotateObject(t *testing.T) { func TestAnnotateObjectFromFile(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -529,10 +529,10 @@ func TestAnnotateObjectFromFile(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdAnnotate(f, buf) + cmd := NewCmdAnnotate(tf, buf) cmd.SetOutput(buf) options := &AnnotateOptions{} options.Filenames = []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"} @@ -543,13 +543,13 @@ func TestAnnotateObjectFromFile(t *testing.T) { if err := options.Validate(); err != nil { t.Fatalf("unexpected error: %v", err) } - if err := options.RunAnnotate(f, cmd); err != nil { + if err := options.RunAnnotate(tf, cmd); err != nil { t.Fatalf("unexpected error: %v", err) } } func TestAnnotateLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"}, NegotiatedSerializer: unstructuredSerializer, @@ -559,10 +559,10 @@ func TestAnnotateLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdAnnotate(f, buf) + cmd := NewCmdAnnotate(tf, buf) options := &AnnotateOptions{local: true} options.Filenames = []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"} args := []string{"a=b"} @@ -572,7 +572,7 @@ func TestAnnotateLocal(t *testing.T) { if err := options.Validate(); err != nil { t.Fatalf("unexpected error: %v", err) } - if err := options.RunAnnotate(f, cmd); err != nil { + if err := options.RunAnnotate(tf, cmd); err != nil { t.Fatalf("unexpected error: %v", err) } } @@ -580,7 +580,7 @@ func TestAnnotateLocal(t *testing.T) { func TestAnnotateMultipleObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"}, @@ -612,10 +612,10 @@ func TestAnnotateMultipleObjects(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdAnnotate(f, buf) + cmd := NewCmdAnnotate(tf, buf) cmd.SetOutput(buf) options := &AnnotateOptions{all: true} args := []string{"pods", "a=b", "c-"} @@ -625,7 +625,7 @@ func TestAnnotateMultipleObjects(t *testing.T) { if err := options.Validate(); err != nil { t.Fatalf("unexpected error: %v", err) } - if err := options.RunAnnotate(f, cmd); err != nil { + if err := options.RunAnnotate(tf, cmd); err != nil { t.Fatalf("unexpected error: %v", err) } } diff --git a/pkg/kubectl/cmd/apply_test.go b/pkg/kubectl/cmd/apply_test.go index 1788fa77e1a..08d07dd1e5c 100644 --- a/pkg/kubectl/cmd/apply_test.go +++ b/pkg/kubectl/cmd/apply_test.go @@ -67,7 +67,7 @@ func TestApplyExtraArgsFail(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() c := NewCmdApply("kubectl", f, buf, errBuf) if validateApplyArgs(c, []string{"rc"}) == nil { t.Fatalf("unexpected non-error") @@ -331,7 +331,7 @@ func TestRunApplyViewLastApplied(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -356,7 +356,7 @@ func TestRunApplyViewLastApplied(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) cmdutil.BehaviorOnFatal(func(str string, code int) { @@ -365,7 +365,7 @@ func TestRunApplyViewLastApplied(t *testing.T) { } }) - cmd := NewCmdApplyViewLastApplied(f, buf, errBuf) + cmd := NewCmdApplyViewLastApplied(tf, buf, errBuf) if test.filePath != "" { cmd.Flags().Set("filename", test.filePath) } @@ -388,7 +388,7 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { nameRC, rcBytes := readReplicationController(t, filenameRC) pathRC := "/namespaces/test/replicationcontrollers/" + nameRC - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -406,11 +406,11 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -432,7 +432,7 @@ func TestApplyObject(t *testing.T) { pathRC := "/namespaces/test/replicationcontrollers/" + nameRC for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -455,7 +455,7 @@ func TestApplyObject(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -493,7 +493,7 @@ func TestApplyObjectOutput(t *testing.T) { } for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -516,7 +516,7 @@ func TestApplyObjectOutput(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "yaml") cmd.Run(cmd, []string{}) @@ -542,7 +542,7 @@ func TestApplyRetry(t *testing.T) { firstPatch := true retry := false getCount := 0 - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -574,7 +574,7 @@ func TestApplyRetry(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -599,7 +599,7 @@ func TestApplyNonExistObject(t *testing.T) { pathRC := "/namespaces/test/replicationcontrollers" pathNameRC := pathRC + "/" + nameRC - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -621,7 +621,7 @@ func TestApplyNonExistObject(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -643,7 +643,7 @@ func TestApplyEmptyPatch(t *testing.T) { var body []byte - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: "v1"}, NegotiatedSerializer: unstructuredSerializer, @@ -674,7 +674,7 @@ func TestApplyEmptyPatch(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -691,7 +691,7 @@ func TestApplyEmptyPatch(t *testing.T) { buf = bytes.NewBuffer([]byte{}) errBuf = bytes.NewBuffer([]byte{}) - cmd = NewCmdApply("kubectl", f, buf, errBuf) + cmd = NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -717,7 +717,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { pathSVC := "/namespaces/test/services/" + nameSVC for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -747,7 +747,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) if asList { cmd.Flags().Set("filename", filenameRCSVC) } else { @@ -800,7 +800,7 @@ func TestApplyNULLPreservation(t *testing.T) { deploymentBytes := readDeploymentFromFile(t, filenameDeployObjServerside) for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -844,7 +844,7 @@ func TestApplyNULLPreservation(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameDeployObjClientside) cmd.Flags().Set("output", "name") @@ -872,7 +872,7 @@ func TestUnstructuredApply(t *testing.T) { verifiedPatch := false for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -907,7 +907,7 @@ func TestUnstructuredApply(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameWidgetClientside) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -939,7 +939,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) { verifiedPatch := false for _, fn := range testingOpenAPISchemaFns { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -997,7 +997,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameWidgetClientside) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -1067,7 +1067,7 @@ func TestRunApplySetLastApplied(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -1096,7 +1096,7 @@ func TestRunApplySetLastApplied(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) cmdutil.BehaviorOnFatal(func(str string, code int) { @@ -1105,7 +1105,7 @@ func TestRunApplySetLastApplied(t *testing.T) { } }) - cmd := NewCmdApplySetLastApplied(f, buf, errBuf) + cmd := NewCmdApplySetLastApplied(tf, buf, errBuf) cmd.Flags().Set("filename", test.filePath) cmd.Flags().Set("output", test.output) cmd.Run(cmd, []string{}) @@ -1159,7 +1159,7 @@ func TestForceApply(t *testing.T) { for _, fn := range testingOpenAPISchemaFns { deleted := false counts := map[string]int{} - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -1219,12 +1219,12 @@ func TestForceApply(t *testing.T) { } tf.OpenAPISchemaFunc = fn tf.Client = tf.UnstructuredClient - tf.ClientConfig = &restclient.Config{} + tf.ClientConfigVal = &restclient.Config{} tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdApply("kubectl", f, buf, errBuf) + cmd := NewCmdApply("kubectl", tf, buf, errBuf) cmd.Flags().Set("filename", filenameRC) cmd.Flags().Set("output", "name") cmd.Flags().Set("force", "true") diff --git a/pkg/kubectl/cmd/attach_test.go b/pkg/kubectl/cmd/attach_test.go index babbf843869..c1ef0e067d3 100644 --- a/pkg/kubectl/cmd/attach_test.go +++ b/pkg/kubectl/cmd/attach_test.go @@ -139,7 +139,7 @@ func TestPodAndContainerAttach(t *testing.T) { } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -154,13 +154,13 @@ func TestPodAndContainerAttach(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() cmd := &cobra.Command{} options := test.p cmdutil.AddPodRunningTimeoutFlag(cmd, test.timeout) - err := options.Complete(f, cmd, test.args) + err := options.Complete(tf, cmd, test.args) if test.expectError && err == nil { t.Errorf("%s: unexpected non-error", test.name) } @@ -219,7 +219,7 @@ func TestAttach(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -242,7 +242,7 @@ func TestAttach(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} + tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} bufOut := bytes.NewBuffer([]byte{}) bufErr := bytes.NewBuffer([]byte{}) bufIn := bytes.NewBuffer([]byte{}) @@ -262,7 +262,7 @@ func TestAttach(t *testing.T) { } cmd := &cobra.Command{} cmdutil.AddPodRunningTimeoutFlag(cmd, 1000) - if err := params.Complete(f, cmd, []string{"foo"}); err != nil { + if err := params.Complete(tf, cmd, []string{"foo"}); err != nil { t.Fatal(err) } err := params.Run() @@ -309,7 +309,7 @@ func TestAttachWarnings(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -331,7 +331,7 @@ func TestAttachWarnings(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} + tf.ClientConfigVal = &restclient.Config{APIPath: "/api", ContentConfig: restclient.ContentConfig{NegotiatedSerializer: legacyscheme.Codecs, GroupVersion: &schema.GroupVersion{Version: test.version}}} bufOut := bytes.NewBuffer([]byte{}) bufErr := bytes.NewBuffer([]byte{}) bufIn := bytes.NewBuffer([]byte{}) @@ -350,7 +350,7 @@ func TestAttachWarnings(t *testing.T) { } cmd := &cobra.Command{} cmdutil.AddPodRunningTimeoutFlag(cmd, 1000) - if err := params.Complete(f, cmd, []string{"foo"}); err != nil { + if err := params.Complete(tf, cmd, []string{"foo"}); err != nil { t.Fatal(err) } if err := params.Run(); err != nil { diff --git a/pkg/kubectl/cmd/auth/cani_test.go b/pkg/kubectl/cmd/auth/cani_test.go index 2a786602a18..0696bc05c69 100644 --- a/pkg/kubectl/cmd/auth/cani_test.go +++ b/pkg/kubectl/cmd/auth/cani_test.go @@ -120,7 +120,7 @@ func TestRunAccessCheck(t *testing.T) { test.o.Out = ioutil.Discard test.o.Err = ioutil.Discard - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -155,9 +155,9 @@ func TestRunAccessCheck(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}} - if err := test.o.Complete(f, test.args); err != nil { + if err := test.o.Complete(tf, test.args); err != nil { t.Errorf("%s: %v", test.name, err) continue } diff --git a/pkg/kubectl/cmd/clusterinfo_dump_test.go b/pkg/kubectl/cmd/clusterinfo_dump_test.go index 552a2676496..6d577baad85 100644 --- a/pkg/kubectl/cmd/clusterinfo_dump_test.go +++ b/pkg/kubectl/cmd/clusterinfo_dump_test.go @@ -30,7 +30,7 @@ func TestSetupOutputWriterNoOp(t *testing.T) { tests := []string{"", "-"} for _, test := range tests { out := &bytes.Buffer{} - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() cmd := NewCmdClusterInfoDump(f, os.Stdout) cmd.Flag("output-directory").Value.Set(test) writer := setupOutputWriter(cmd, out, "/some/file/that/should/be/ignored") @@ -50,7 +50,7 @@ func TestSetupOutputWriterFile(t *testing.T) { defer os.RemoveAll(dir) out := &bytes.Buffer{} - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() cmd := NewCmdClusterInfoDump(f, os.Stdout) cmd.Flag("output-directory").Value.Set(dir) writer := setupOutputWriter(cmd, out, file) diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index f61042dbca6..69614b363db 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -177,14 +177,14 @@ func stringBody(body string) io.ReadCloser { } func Example_printMultiContainersReplicationControllerWithWide() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: nil, } - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) ctrl := &api.ReplicationController{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", @@ -227,14 +227,14 @@ func Example_printMultiContainersReplicationControllerWithWide() { } func Example_printReplicationController() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: nil, } - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) ctrl := &api.ReplicationController{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", @@ -276,7 +276,7 @@ func Example_printReplicationController() { } func Example_printPodWithWideFormat() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -284,7 +284,7 @@ func Example_printPodWithWideFormat() { Client: nil, } nodeName := "kubernetes-node-abcd" - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) pod := &api.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", @@ -314,7 +314,7 @@ func Example_printPodWithWideFormat() { } func Example_printPodWithShowLabels() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -322,7 +322,7 @@ func Example_printPodWithShowLabels() { Client: nil, } nodeName := "kubernetes-node-abcd" - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) pod := &api.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "test1", @@ -447,17 +447,17 @@ func newAllPhasePodList() *api.PodList { } func Example_printPodHideTerminated() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: nil, } - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) podList := newAllPhasePodList() // filter pods - filterFuncs := f.DefaultResourceFilterFunc() + filterFuncs := tf.DefaultResourceFilterFunc() filterOpts := cmdutil.ExtractCmdPrintOptions(cmd, false) _, filteredPodList, errs := cmdutil.FilterResourceList(podList, filterFuncs, filterOpts) if errs != nil { @@ -481,14 +481,14 @@ func Example_printPodHideTerminated() { } func Example_printPodShowAll() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: nil, } - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) podList := newAllPhasePodList() err := cmdutil.PrintObject(cmd, podList, os.Stdout) if err != nil { @@ -504,14 +504,14 @@ func Example_printPodShowAll() { } func Example_printServiceWithLabels() { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ NegotiatedSerializer: ns, Client: nil, } - cmd := resource.NewCmdGet(f, os.Stdout, os.Stderr) + cmd := resource.NewCmdGet(tf, os.Stdout, os.Stderr) svc := &api.ServiceList{ Items: []api.Service{ { diff --git a/pkg/kubectl/cmd/convert_test.go b/pkg/kubectl/cmd/convert_test.go index a79a24d001d..19ee215881b 100644 --- a/pkg/kubectl/cmd/convert_test.go +++ b/pkg/kubectl/cmd/convert_test.go @@ -101,7 +101,7 @@ func TestConvertObject(t *testing.T) { for _, tc := range testcases { for _, field := range tc.fields { t.Run(fmt.Sprintf("%s %s", tc.name, field), func(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) @@ -111,7 +111,7 @@ func TestConvertObject(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdConvert(f, buf) + cmd := NewCmdConvert(tf, buf) cmd.Flags().Set("filename", tc.file) cmd.Flags().Set("output-version", tc.outputVersion) cmd.Flags().Set("local", "true") diff --git a/pkg/kubectl/cmd/create_clusterrole_test.go b/pkg/kubectl/cmd/create_clusterrole_test.go index d74934a9840..1b246369d53 100644 --- a/pkg/kubectl/cmd/create_clusterrole_test.go +++ b/pkg/kubectl/cmd/create_clusterrole_test.go @@ -32,10 +32,10 @@ import ( func TestCreateClusterRole(t *testing.T) { clusterRoleName := "my-cluster-role" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tf.Client = &fake.RESTClient{} - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() tests := map[string]struct { verbs string @@ -125,7 +125,7 @@ func TestCreateClusterRole(t *testing.T) { for name, test := range tests { buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateClusterRole(f, buf) + cmd := NewCmdCreateClusterRole(tf, buf) cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "yaml") cmd.Flags().Set("verb", test.verbs) @@ -147,7 +147,7 @@ func TestCreateClusterRole(t *testing.T) { } func TestClusterRoleValidate(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tests := map[string]struct { @@ -426,7 +426,7 @@ func TestClusterRoleValidate(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - test.clusterRoleOptions.Mapper, _ = f.Object() + test.clusterRoleOptions.Mapper, _ = tf.Object() err := test.clusterRoleOptions.Validate() if test.expectErr && err == nil { t.Errorf("%s: expect error happens, but validate passes.", name) diff --git a/pkg/kubectl/cmd/create_clusterrolebinding_test.go b/pkg/kubectl/cmd/create_clusterrolebinding_test.go index 0c433066f37..00628a92ae0 100644 --- a/pkg/kubectl/cmd/create_clusterrolebinding_test.go +++ b/pkg/kubectl/cmd/create_clusterrolebinding_test.go @@ -67,7 +67,7 @@ func TestCreateClusterRoleBinding(t *testing.T) { }, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) @@ -110,7 +110,7 @@ func TestCreateClusterRoleBinding(t *testing.T) { expectedOutput := "clusterrolebinding.rbac.authorization.k8s.io/" + expectBinding.Name + "\n" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateClusterRoleBinding(f, buf) + cmd := NewCmdCreateClusterRoleBinding(tf, buf) cmd.Flags().Set("clusterrole", "fake-clusterrole") cmd.Flags().Set("user", "fake-user") cmd.Flags().Set("group", "fake-group") diff --git a/pkg/kubectl/cmd/create_configmap_test.go b/pkg/kubectl/cmd/create_configmap_test.go index 60702f64caf..0ffa2696ce4 100644 --- a/pkg/kubectl/cmd/create_configmap_test.go +++ b/pkg/kubectl/cmd/create_configmap_test.go @@ -32,7 +32,7 @@ import ( func TestCreateConfigMap(t *testing.T) { configMap := &v1.ConfigMap{} configMap.Name = "my-configmap" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -51,7 +51,7 @@ func TestCreateConfigMap(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateConfigMap(f, buf) + cmd := NewCmdCreateConfigMap(tf, buf) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{configMap.Name}) expectedOutput := "configmap/" + configMap.Name + "\n" diff --git a/pkg/kubectl/cmd/create_deployment_test.go b/pkg/kubectl/cmd/create_deployment_test.go index 27541466726..bf94557220c 100644 --- a/pkg/kubectl/cmd/create_deployment_test.go +++ b/pkg/kubectl/cmd/create_deployment_test.go @@ -74,7 +74,7 @@ func Test_generatorFromName(t *testing.T) { func TestCreateDeployment(t *testing.T) { depName := "jonny-dep" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -86,11 +86,11 @@ func TestCreateDeployment(t *testing.T) { }, nil }), } - tf.ClientConfig = &restclient.Config{} + tf.ClientConfigVal = &restclient.Config{} tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateDeployment(f, buf, buf) + cmd := NewCmdCreateDeployment(tf, buf, buf) cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "name") cmd.Flags().Set("image", "hollywood/jonny.depp:v2") @@ -103,7 +103,7 @@ func TestCreateDeployment(t *testing.T) { func TestCreateDeploymentNoImage(t *testing.T) { depName := "jonny-dep" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -115,13 +115,13 @@ func TestCreateDeploymentNoImage(t *testing.T) { }, nil }), } - tf.ClientConfig = &restclient.Config{} + tf.ClientConfigVal = &restclient.Config{} tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateDeployment(f, buf, buf) + cmd := NewCmdCreateDeployment(tf, buf, buf) cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "name") - err := createDeployment(f, buf, buf, cmd, []string{depName}) + err := createDeployment(tf, buf, buf, cmd, []string{depName}) assert.Error(t, err, "at least one image must be specified") } diff --git a/pkg/kubectl/cmd/create_job_test.go b/pkg/kubectl/cmd/create_job_test.go index 4fb54df19c2..e04cf9201ee 100644 --- a/pkg/kubectl/cmd/create_job_test.go +++ b/pkg/kubectl/cmd/create_job_test.go @@ -81,7 +81,7 @@ func TestCreateJobFromCronJob(t *testing.T) { submittedJob = ca.GetObject().(*batchv1.Job) return true, expectJob, nil }) - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() buf := bytes.NewBuffer([]byte{}) cmdOptions := &CreateJobOptions{ Name: testJobName, diff --git a/pkg/kubectl/cmd/create_namespace_test.go b/pkg/kubectl/cmd/create_namespace_test.go index 43cca404749..5b8d587d4fd 100644 --- a/pkg/kubectl/cmd/create_namespace_test.go +++ b/pkg/kubectl/cmd/create_namespace_test.go @@ -32,7 +32,7 @@ import ( func TestCreateNamespace(t *testing.T) { namespaceObject := &v1.Namespace{} namespaceObject.Name = "my-namespace" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -50,7 +50,7 @@ func TestCreateNamespace(t *testing.T) { }), } buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateNamespace(f, buf) + cmd := NewCmdCreateNamespace(tf, buf) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{namespaceObject.Name}) expectedOutput := "namespace/" + namespaceObject.Name + "\n" diff --git a/pkg/kubectl/cmd/create_pdb_test.go b/pkg/kubectl/cmd/create_pdb_test.go index f78b57057e7..76b82ebb1f4 100644 --- a/pkg/kubectl/cmd/create_pdb_test.go +++ b/pkg/kubectl/cmd/create_pdb_test.go @@ -31,7 +31,7 @@ import ( func TestCreatePdb(t *testing.T) { pdbName := "my-pdb" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -44,16 +44,16 @@ func TestCreatePdb(t *testing.T) { }, nil }), } - tf.ClientConfig = &restclient.Config{} + tf.ClientConfigVal = &restclient.Config{} tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreatePodDisruptionBudget(f, buf) + cmd := NewCmdCreatePodDisruptionBudget(tf, buf) cmd.Flags().Set("min-available", "1") cmd.Flags().Set("selector", "app=rails") cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "name") - CreatePodDisruptionBudget(f, buf, cmd, []string{pdbName}) + CreatePodDisruptionBudget(tf, buf, cmd, []string{pdbName}) expectedOutput := "poddisruptionbudget.policy/" + pdbName + "\n" if buf.String() != expectedOutput { t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) diff --git a/pkg/kubectl/cmd/create_priorityclass_test.go b/pkg/kubectl/cmd/create_priorityclass_test.go index 27eaca7c298..14b77ef2e45 100644 --- a/pkg/kubectl/cmd/create_priorityclass_test.go +++ b/pkg/kubectl/cmd/create_priorityclass_test.go @@ -31,7 +31,7 @@ import ( func TestCreatePriorityClass(t *testing.T) { pcName := "my-pc" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -44,16 +44,16 @@ func TestCreatePriorityClass(t *testing.T) { }, nil }), } - tf.ClientConfig = &restclient.Config{} + tf.ClientConfigVal = &restclient.Config{} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreatePriorityClass(f, buf) + cmd := NewCmdCreatePriorityClass(tf, buf) cmd.Flags().Set("value", "1000") cmd.Flags().Set("global-default", "true") cmd.Flags().Set("description", "my priority") cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "name") - CreatePriorityClass(f, buf, cmd, []string{pcName}) + CreatePriorityClass(tf, buf, cmd, []string{pcName}) expectedOutput := "priorityclass.scheduling.k8s.io/" + pcName + "\n" if buf.String() != expectedOutput { t.Errorf("expected output: %s, but got: %s", expectedOutput, buf.String()) diff --git a/pkg/kubectl/cmd/create_quota_test.go b/pkg/kubectl/cmd/create_quota_test.go index e0d942c0c29..cfcf1e4738c 100644 --- a/pkg/kubectl/cmd/create_quota_test.go +++ b/pkg/kubectl/cmd/create_quota_test.go @@ -32,7 +32,7 @@ import ( func TestCreateQuota(t *testing.T) { resourceQuotaObject := &v1.ResourceQuota{} resourceQuotaObject.Name = "my-quota" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -74,7 +74,7 @@ func TestCreateQuota(t *testing.T) { } for name, test := range tests { buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateQuota(f, buf) + cmd := NewCmdCreateQuota(tf, buf) cmd.Flags().Parse(test.flags) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{resourceQuotaObject.Name}) diff --git a/pkg/kubectl/cmd/create_role_test.go b/pkg/kubectl/cmd/create_role_test.go index 4de396789bc..82c265b5dd9 100644 --- a/pkg/kubectl/cmd/create_role_test.go +++ b/pkg/kubectl/cmd/create_role_test.go @@ -34,10 +34,10 @@ import ( func TestCreateRole(t *testing.T) { roleName := "my-role" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tf.Client = &fake.RESTClient{} - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() tests := map[string]struct { verbs string @@ -124,7 +124,7 @@ func TestCreateRole(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateRole(f, buf) + cmd := NewCmdCreateRole(tf, buf) cmd.Flags().Set("dry-run", "true") cmd.Flags().Set("output", "yaml") cmd.Flags().Set("verb", test.verbs) @@ -146,7 +146,7 @@ func TestCreateRole(t *testing.T) { } func TestValidate(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tests := map[string]struct { @@ -331,7 +331,7 @@ func TestValidate(t *testing.T) { } for name, test := range tests { - test.roleOptions.Mapper, _ = f.Object() + test.roleOptions.Mapper, _ = tf.Object() err := test.roleOptions.Validate() if test.expectErr && err == nil { t.Errorf("%s: expect error happens but validate passes.", name) @@ -345,13 +345,13 @@ func TestValidate(t *testing.T) { func TestComplete(t *testing.T) { roleName := "my-role" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tf.Client = &fake.RESTClient{} - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateRole(f, buf) + cmd := NewCmdCreateRole(tf, buf) cmd.Flags().Set("resource", "pods,deployments.extensions") tests := map[string]struct { @@ -476,7 +476,7 @@ func TestComplete(t *testing.T) { } for name, test := range tests { - err := test.roleOptions.Complete(f, cmd, test.params) + err := test.roleOptions.Complete(tf, cmd, test.params) if !test.expectErr && err != nil { t.Errorf("%s: unexpected error: %v", name, err) } diff --git a/pkg/kubectl/cmd/create_rolebinding_test.go b/pkg/kubectl/cmd/create_rolebinding_test.go index d4c9c068b5c..b42faaa9db8 100644 --- a/pkg/kubectl/cmd/create_rolebinding_test.go +++ b/pkg/kubectl/cmd/create_rolebinding_test.go @@ -69,7 +69,7 @@ func TestCreateRoleBinding(t *testing.T) { }, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) @@ -111,7 +111,7 @@ func TestCreateRoleBinding(t *testing.T) { } buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateRoleBinding(f, buf) + cmd := NewCmdCreateRoleBinding(tf, buf) cmd.Flags().Set("role", "fake-role") cmd.Flags().Set("user", "fake-user") cmd.Flags().Set("group", "fake-group") diff --git a/pkg/kubectl/cmd/create_secret_test.go b/pkg/kubectl/cmd/create_secret_test.go index 2160eff3afa..86487976765 100644 --- a/pkg/kubectl/cmd/create_secret_test.go +++ b/pkg/kubectl/cmd/create_secret_test.go @@ -37,7 +37,7 @@ func TestCreateSecretGeneric(t *testing.T) { }, } secretObject.Name = "my-secret" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -56,7 +56,7 @@ func TestCreateSecretGeneric(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateSecretGeneric(f, buf) + cmd := NewCmdCreateSecretGeneric(tf, buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("from-literal", "password=includes,comma") cmd.Flags().Set("from-literal", "username=test_user") @@ -70,7 +70,7 @@ func TestCreateSecretGeneric(t *testing.T) { func TestCreateSecretDockerRegistry(t *testing.T) { secretObject := &v1.Secret{} secretObject.Name = "my-secret" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -89,7 +89,7 @@ func TestCreateSecretDockerRegistry(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateSecretDockerRegistry(f, buf) + cmd := NewCmdCreateSecretDockerRegistry(tf, buf) cmd.Flags().Set("docker-username", "test-user") cmd.Flags().Set("docker-password", "test-pass") cmd.Flags().Set("docker-email", "test-email") diff --git a/pkg/kubectl/cmd/create_service_test.go b/pkg/kubectl/cmd/create_service_test.go index ef1d7b0deb2..adf9679d962 100644 --- a/pkg/kubectl/cmd/create_service_test.go +++ b/pkg/kubectl/cmd/create_service_test.go @@ -32,7 +32,7 @@ import ( func TestCreateService(t *testing.T) { service := &v1.Service{} service.Name = "my-service" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) negSer := legacyscheme.Codecs @@ -51,7 +51,7 @@ func TestCreateService(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateServiceClusterIP(f, buf) + cmd := NewCmdCreateServiceClusterIP(tf, buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("tcp", "8080:8000") cmd.Run(cmd, []string{service.Name}) @@ -64,7 +64,7 @@ func TestCreateService(t *testing.T) { func TestCreateServiceNodePort(t *testing.T) { service := &v1.Service{} service.Name = "my-node-port-service" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) negSer := legacyscheme.Codecs @@ -83,7 +83,7 @@ func TestCreateServiceNodePort(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateServiceNodePort(f, buf) + cmd := NewCmdCreateServiceNodePort(tf, buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("tcp", "30000:8000") cmd.Run(cmd, []string{service.Name}) @@ -96,7 +96,7 @@ func TestCreateServiceNodePort(t *testing.T) { func TestCreateServiceExternalName(t *testing.T) { service := &v1.Service{} service.Name = "my-external-name-service" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) negSer := legacyscheme.Codecs @@ -115,7 +115,7 @@ func TestCreateServiceExternalName(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateServiceExternalName(f, buf) + cmd := NewCmdCreateServiceExternalName(tf, buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("external-name", "name") cmd.Run(cmd, []string{service.Name}) diff --git a/pkg/kubectl/cmd/create_serviceaccount_test.go b/pkg/kubectl/cmd/create_serviceaccount_test.go index 7c761098e04..382f66dbe0f 100644 --- a/pkg/kubectl/cmd/create_serviceaccount_test.go +++ b/pkg/kubectl/cmd/create_serviceaccount_test.go @@ -32,7 +32,7 @@ import ( func TestCreateServiceAccount(t *testing.T) { serviceAccountObject := &v1.ServiceAccount{} serviceAccountObject.Name = "my-service-account" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -51,7 +51,7 @@ func TestCreateServiceAccount(t *testing.T) { } tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreateServiceAccount(f, buf) + cmd := NewCmdCreateServiceAccount(tf, buf) cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{serviceAccountObject.Name}) expectedOutput := "serviceaccount/" + serviceAccountObject.Name + "\n" diff --git a/pkg/kubectl/cmd/create_test.go b/pkg/kubectl/cmd/create_test.go index 703c5423829..c4f0019aa86 100644 --- a/pkg/kubectl/cmd/create_test.go +++ b/pkg/kubectl/cmd/create_test.go @@ -33,7 +33,7 @@ func TestExtraArgsFail(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() c := NewCmdCreate(f, buf, errBuf) options := CreateOptions{} if options.ValidateArgs(c, []string{"rc"}) == nil { @@ -46,7 +46,7 @@ func TestCreateObject(t *testing.T) { _, _, rc := testData() rc.Items[0].Name = "redis-master-controller" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -66,7 +66,7 @@ func TestCreateObject(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreate(f, buf, errBuf) + cmd := NewCmdCreate(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -81,7 +81,7 @@ func TestCreateMultipleObject(t *testing.T) { initTestErrorHandler(t) _, svc, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -103,7 +103,7 @@ func TestCreateMultipleObject(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreate(f, buf, errBuf) + cmd := NewCmdCreate(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("output", "name") @@ -120,7 +120,7 @@ func TestCreateDirectory(t *testing.T) { _, _, rc := testData() rc.Items[0].Name = "name" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -140,7 +140,7 @@ func TestCreateDirectory(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdCreate(f, buf, errBuf) + cmd := NewCmdCreate(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy") cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) diff --git a/pkg/kubectl/cmd/delete_test.go b/pkg/kubectl/cmd/delete_test.go index 07f520e3798..fc0dd589d55 100644 --- a/pkg/kubectl/cmd/delete_test.go +++ b/pkg/kubectl/cmd/delete_test.go @@ -56,7 +56,7 @@ func TestDeleteObjectByTuple(t *testing.T) { initTestErrorHandler(t) _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -82,7 +82,7 @@ func TestDeleteObjectByTuple(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -93,7 +93,7 @@ func TestDeleteObjectByTuple(t *testing.T) { // Test cascading delete of object without client-side reaper doesn't make GET requests buf, errBuf = bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd = NewCmdDelete(f, buf, errBuf) + cmd = NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{"secrets/mysecret"}) @@ -120,7 +120,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { initTestErrorHandler(t) _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) var expectedOrphanDependents *bool @@ -143,7 +143,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { falseVar := false expectedOrphanDependents = &falseVar buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{"secrets/mysecret"}) @@ -155,7 +155,7 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { trueVar := true expectedOrphanDependents = &trueVar buf, errBuf = bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd = NewCmdDelete(f, buf, errBuf) + cmd = NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -170,7 +170,7 @@ func TestDeleteNamedObject(t *testing.T) { initTestErrorHandler(t) _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -196,7 +196,7 @@ func TestDeleteNamedObject(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -207,7 +207,7 @@ func TestDeleteNamedObject(t *testing.T) { // Test cascading delete of object without client-side reaper doesn't make GET requests buf, errBuf = bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd = NewCmdDelete(f, buf, errBuf) + cmd = NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -221,7 +221,7 @@ func TestDeleteObject(t *testing.T) { initTestErrorHandler(t) _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -239,7 +239,7 @@ func TestDeleteObject(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -280,7 +280,7 @@ func TestDeleteObjectGraceZero(t *testing.T) { objectDeletionWaitInterval = time.Millisecond count := 0 - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -310,7 +310,7 @@ func TestDeleteObjectGraceZero(t *testing.T) { buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) reaper := &fakeReaper{} - fake := &fakeReaperFactory{Factory: f, reaper: reaper} + fake := &fakeReaperFactory{Factory: tf, reaper: reaper} cmd := NewCmdDelete(fake, buf, errBuf) cmd.Flags().Set("output", "name") cmd.Flags().Set("grace-period", "0") @@ -330,7 +330,7 @@ func TestDeleteObjectGraceZero(t *testing.T) { func TestDeleteObjectNotFound(t *testing.T) { initTestErrorHandler(t) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -354,7 +354,7 @@ func TestDeleteObjectNotFound(t *testing.T) { Cascade: false, Output: "name", } - err := options.Complete(f, buf, errBuf, []string{}, fakecmd) + err := options.Complete(tf, buf, errBuf, []string{}, fakecmd) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -366,7 +366,7 @@ func TestDeleteObjectNotFound(t *testing.T) { func TestDeleteObjectIgnoreNotFound(t *testing.T) { initTestErrorHandler(t) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -382,7 +382,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("ignore-not-found", "true") @@ -401,7 +401,7 @@ func TestDeleteAllNotFound(t *testing.T) { svc.Items = append(svc.Items, api.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}) notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -432,7 +432,7 @@ func TestDeleteAllNotFound(t *testing.T) { IgnoreNotFound: false, Output: "name", } - err := options.Complete(f, buf, errBuf, []string{"services"}, fakecmd) + err := options.Complete(tf, buf, errBuf, []string{"services"}, fakecmd) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -446,7 +446,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) { initTestErrorHandler(t) _, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) // Add an item to the list which will result in a 404 on delete @@ -472,7 +472,7 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("all", "true") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -487,7 +487,7 @@ func TestDeleteMultipleObject(t *testing.T) { initTestErrorHandler(t) _, svc, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -507,7 +507,7 @@ func TestDeleteMultipleObject(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("cascade", "false") @@ -523,7 +523,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { initTestErrorHandler(t) _, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -551,7 +551,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { Cascade: false, Output: "name", } - err := options.Complete(f, buf, errBuf, []string{}, fakecmd) + err := options.Complete(tf, buf, errBuf, []string{}, fakecmd) if err != nil { t.Errorf("unexpected error: %v", err) } @@ -568,7 +568,7 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { initTestErrorHandler(t) _, svc, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -593,7 +593,7 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -607,7 +607,7 @@ func TestDeleteDirectory(t *testing.T) { initTestErrorHandler(t) _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -625,7 +625,7 @@ func TestDeleteDirectory(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -640,7 +640,7 @@ func TestDeleteMultipleSelector(t *testing.T) { initTestErrorHandler(t) pods, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -670,7 +670,7 @@ func TestDeleteMultipleSelector(t *testing.T) { tf.Namespace = "test" buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) - cmd := NewCmdDelete(f, buf, errBuf) + cmd := NewCmdDelete(tf, buf, errBuf) cmd.Flags().Set("selector", "a=b") cmd.Flags().Set("cascade", "false") cmd.Flags().Set("output", "name") @@ -706,9 +706,9 @@ func TestResourceErrors(t *testing.T) { } for k, testCase := range testCases { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf, errBuf := bytes.NewBuffer([]byte{}), bytes.NewBuffer([]byte{}) @@ -718,7 +718,7 @@ func TestResourceErrors(t *testing.T) { Cascade: false, Output: "name", } - err := options.Complete(f, buf, errBuf, testCase.args, fakecmd) + err := options.Complete(tf, buf, errBuf, testCase.args, fakecmd) if !testCase.errFn(err) { t.Errorf("%s: unexpected error: %v", k, err) continue diff --git a/pkg/kubectl/cmd/describe_test.go b/pkg/kubectl/cmd/describe_test.go index a8c074f4eac..9e5b39a8ae2 100644 --- a/pkg/kubectl/cmd/describe_test.go +++ b/pkg/kubectl/cmd/describe_test.go @@ -32,9 +32,9 @@ import ( // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. func TestDescribeUnknownSchemaObject(t *testing.T) { d := &testDescriber{Output: "test output"} - f, tf := cmdtesting.NewTestFactory() + tf := cmdtesting.NewTestFactory() _, _, codec := cmdtesting.NewExternalScheme() - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", "foo"))}, @@ -42,7 +42,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) { tf.Namespace = "non-default" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Run(cmd, []string{"type", "foo"}) if d.Name != "foo" || d.Namespace != "" { @@ -57,10 +57,10 @@ func TestDescribeUnknownSchemaObject(t *testing.T) { // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { d := &testDescriber{Output: "test output"} - f, tf := cmdtesting.NewTestFactory() + tf := cmdtesting.NewTestFactory() _, _, codec := cmdtesting.NewExternalScheme() - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalNamespacedType("", "", "foo", "non-default"))}, @@ -68,7 +68,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { tf.Namespace = "non-default" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Run(cmd, []string{"namespacedtype", "foo"}) if d.Name != "foo" || d.Namespace != "non-default" { @@ -82,11 +82,11 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { func TestDescribeObject(t *testing.T) { _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) d := &testDescriber{Output: "test output"} - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -102,7 +102,7 @@ func TestDescribeObject(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Run(cmd, []string{}) @@ -117,11 +117,11 @@ func TestDescribeObject(t *testing.T) { func TestDescribeListObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) d := &testDescriber{Output: "test output"} - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, @@ -130,7 +130,7 @@ func TestDescribeListObjects(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Run(cmd, []string{"pods"}) if buf.String() != fmt.Sprintf("%s\n\n%s", d.Output, d.Output) { t.Errorf("unexpected output: %s", buf.String()) @@ -139,11 +139,11 @@ func TestDescribeListObjects(t *testing.T) { func TestDescribeObjectShowEvents(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) d := &testDescriber{Output: "test output"} - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, @@ -152,7 +152,7 @@ func TestDescribeObjectShowEvents(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Flags().Set("show-events", "true") cmd.Run(cmd, []string{"pods"}) if d.Settings.ShowEvents != true { @@ -162,11 +162,11 @@ func TestDescribeObjectShowEvents(t *testing.T) { func TestDescribeObjectSkipEvents(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) d := &testDescriber{Output: "test output"} - tf.Describer = d + tf.DescriberVal = d tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, @@ -175,7 +175,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.Flags().Set("show-events", "false") cmd.Run(cmd, []string{"pods"}) if d.Settings.ShowEvents != false { @@ -184,11 +184,11 @@ func TestDescribeObjectSkipEvents(t *testing.T) { } func TestDescribeHelpMessage(t *testing.T) { - f, _ := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() buf := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{}) - cmd := NewCmdDescribe(f, buf, buferr) + cmd := NewCmdDescribe(tf, buf, buferr) cmd.SetArgs([]string{"-h"}) cmd.SetOutput(buf) _, err := cmd.ExecuteC() diff --git a/pkg/kubectl/cmd/drain_test.go b/pkg/kubectl/cmd/drain_test.go index cb9d26d5816..deaaa867f27 100644 --- a/pkg/kubectl/cmd/drain_test.go +++ b/pkg/kubectl/cmd/drain_test.go @@ -150,7 +150,7 @@ func TestCordon(t *testing.T) { } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -194,10 +194,10 @@ func TestCordon(t *testing.T) { } }), } - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := test.cmd(f, buf) + cmd := test.cmd(tf, buf) saw_fatal := false func() { @@ -600,7 +600,7 @@ func TestDrain(t *testing.T) { new_node := &corev1.Node{} deleted := false evicted := false - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -700,11 +700,11 @@ func TestDrain(t *testing.T) { } }), } - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdDrain(f, buf, errBuf) + cmd := NewCmdDrain(tf, buf, errBuf) saw_fatal := false fatal_msg := "" @@ -824,9 +824,9 @@ func TestDeletePods(t *testing.T) { } for _, test := range tests { - f, _ := cmdtesting.NewAPIFactory() - o := DrainOptions{Factory: f} - o.mapper, _ = f.Object() + tf := cmdtesting.NewTestFactory() + o := DrainOptions{Factory: tf} + o.mapper, _ = tf.Object() o.Out = os.Stdout _, pods := createPods(false) pendingPods, err := o.waitForDelete(pods, test.interval, test.timeout, false, test.getPodFn) diff --git a/pkg/kubectl/cmd/edit_test.go b/pkg/kubectl/cmd/edit_test.go index 955bd694b72..b01c3c4be27 100644 --- a/pkg/kubectl/cmd/edit_test.go +++ b/pkg/kubectl/cmd/edit_test.go @@ -206,7 +206,7 @@ func TestEdit(t *testing.T) { t.Fatalf("%s: %v", name, err) } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) { versionedAPIPath := "" if mapping.GroupVersionKind.Group == "" { @@ -224,20 +224,20 @@ func TestEdit(t *testing.T) { if len(testcase.Namespace) > 0 { tf.Namespace = testcase.Namespace } - tf.ClientConfig = defaultClientConfig() - tf.Command = "edit test cmd invocation" + tf.ClientConfigVal = defaultClientConfig() + tf.CommandVal = "edit test cmd invocation" buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) var cmd *cobra.Command switch testcase.Mode { case "edit": - cmd = NewCmdEdit(f, buf, errBuf) + cmd = NewCmdEdit(tf, buf, errBuf) case "create": - cmd = NewCmdCreate(f, buf, errBuf) + cmd = NewCmdCreate(tf, buf, errBuf) cmd.Flags().Set("edit", "true") case "edit-last-applied": - cmd = NewCmdApplyEditLastApplied(f, buf, errBuf) + cmd = NewCmdApplyEditLastApplied(tf, buf, errBuf) default: t.Fatalf("%s: unexpected mode %s", name, testcase.Mode) } diff --git a/pkg/kubectl/cmd/exec_test.go b/pkg/kubectl/cmd/exec_test.go index 0466f315879..58e3ccf9050 100644 --- a/pkg/kubectl/cmd/exec_test.go +++ b/pkg/kubectl/cmd/exec_test.go @@ -130,7 +130,7 @@ func TestPodAndContainer(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -138,12 +138,12 @@ func TestPodAndContainer(t *testing.T) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { return nil, nil }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() cmd := &cobra.Command{} options := test.p options.Err = bytes.NewBuffer([]byte{}) - err := options.Complete(f, cmd, test.args, test.argsLenAtDash) + err := options.Complete(tf, cmd, test.args, test.argsLenAtDash) if test.expectError && err == nil { t.Errorf("%s: unexpected non-error", test.name) } @@ -187,7 +187,7 @@ func TestExec(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -206,7 +206,7 @@ func TestExec(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() bufOut := bytes.NewBuffer([]byte{}) bufErr := bytes.NewBuffer([]byte{}) bufIn := bytes.NewBuffer([]byte{}) @@ -226,7 +226,7 @@ func TestExec(t *testing.T) { } cmd := &cobra.Command{} args := []string{"test", "command"} - if err := params.Complete(f, cmd, args, -1); err != nil { + if err := params.Complete(tf, cmd, args, -1); err != nil { t.Fatal(err) } err := params.Run() diff --git a/pkg/kubectl/cmd/expose_test.go b/pkg/kubectl/cmd/expose_test.go index 3cf6e6e4438..1239d4bcc72 100644 --- a/pkg/kubectl/cmd/expose_test.go +++ b/pkg/kubectl/cmd/expose_test.go @@ -466,7 +466,7 @@ func TestRunExposeService(t *testing.T) { } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -488,7 +488,7 @@ func TestRunExposeService(t *testing.T) { tf.Namespace = test.ns buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdExposeService(f, buf) + cmd := NewCmdExposeService(tf, buf) cmd.SetOutput(buf) for flag, value := range test.flags { cmd.Flags().Set(flag, value) diff --git a/pkg/kubectl/cmd/label_test.go b/pkg/kubectl/cmd/label_test.go index 5fbd334055c..14d6ec97e80 100644 --- a/pkg/kubectl/cmd/label_test.go +++ b/pkg/kubectl/cmd/label_test.go @@ -321,12 +321,12 @@ func TestLabelErrors(t *testing.T) { } for k, testCase := range testCases { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLabel(f, buf) + cmd := NewCmdLabel(tf, buf) cmd.SetOutput(buf) for k, v := range testCase.flags { @@ -338,7 +338,7 @@ func TestLabelErrors(t *testing.T) { err = opts.Validate() } if err == nil { - err = opts.RunLabel(f, cmd) + err = opts.RunLabel(tf, cmd) } if !testCase.errFn(err) { t.Errorf("%s: unexpected error: %v", k, err) @@ -352,7 +352,7 @@ func TestLabelErrors(t *testing.T) { func TestLabelForResourceFromFile(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -382,10 +382,10 @@ func TestLabelForResourceFromFile(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLabel(f, buf) + cmd := NewCmdLabel(tf, buf) opts := LabelOptions{FilenameOptions: resource.FilenameOptions{ Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}} err := opts.Complete(buf, cmd, []string{"a=b"}) @@ -393,7 +393,7 @@ func TestLabelForResourceFromFile(t *testing.T) { err = opts.Validate() } if err == nil { - err = opts.RunLabel(f, cmd) + err = opts.RunLabel(tf, cmd) } if err != nil { t.Fatalf("unexpected error: %v", err) @@ -404,7 +404,7 @@ func TestLabelForResourceFromFile(t *testing.T) { } func TestLabelLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -413,10 +413,10 @@ func TestLabelLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLabel(f, buf) + cmd := NewCmdLabel(tf, buf) opts := LabelOptions{FilenameOptions: resource.FilenameOptions{ Filenames: []string{"../../../examples/storage/cassandra/cassandra-controller.yaml"}}, local: true} @@ -425,7 +425,7 @@ func TestLabelLocal(t *testing.T) { err = opts.Validate() } if err == nil { - err = opts.RunLabel(f, cmd) + err = opts.RunLabel(tf, cmd) } if err != nil { t.Fatalf("unexpected error: %v", err) @@ -437,7 +437,7 @@ func TestLabelLocal(t *testing.T) { func TestLabelMultipleObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -469,17 +469,17 @@ func TestLabelMultipleObjects(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLabel(f, buf) + cmd := NewCmdLabel(tf, buf) opts := LabelOptions{all: true} err := opts.Complete(buf, cmd, []string{"pods", "a=b"}) if err == nil { err = opts.Validate() } if err == nil { - err = opts.RunLabel(f, cmd) + err = opts.RunLabel(tf, cmd) } if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/pkg/kubectl/cmd/logs_test.go b/pkg/kubectl/cmd/logs_test.go index f5ef4de7c04..8d5f0b9ec92 100644 --- a/pkg/kubectl/cmd/logs_test.go +++ b/pkg/kubectl/cmd/logs_test.go @@ -49,7 +49,7 @@ func TestLog(t *testing.T) { } for _, test := range tests { logContent := "test log content" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -71,10 +71,10 @@ func TestLog(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLogs(f, buf, buf) + cmd := NewCmdLogs(tf, buf, buf) cmd.Flags().Set("namespace", "test") cmd.Run(cmd, []string{"foo"}) @@ -100,7 +100,7 @@ func testPod() *api.Pod { } func TestValidateLogFlags(t *testing.T) { - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() tests := []struct { name string @@ -151,7 +151,7 @@ func TestValidateLogFlags(t *testing.T) { } func TestLogComplete(t *testing.T) { - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() tests := []struct { name string diff --git a/pkg/kubectl/cmd/patch_test.go b/pkg/kubectl/cmd/patch_test.go index 7beab48685e..dc276b80acd 100644 --- a/pkg/kubectl/cmd/patch_test.go +++ b/pkg/kubectl/cmd/patch_test.go @@ -31,7 +31,7 @@ import ( func TestPatchObject(t *testing.T) { _, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -56,7 +56,7 @@ func TestPatchObject(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdPatch(f, buf) + cmd := NewCmdPatch(tf, buf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("patch", `{"spec":{"type":"NodePort"}}`) cmd.Flags().Set("output", "name") @@ -71,7 +71,7 @@ func TestPatchObject(t *testing.T) { func TestPatchObjectFromFile(t *testing.T) { _, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -89,7 +89,7 @@ func TestPatchObjectFromFile(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdPatch(f, buf) + cmd := NewCmdPatch(tf, buf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("patch", `{"spec":{"type":"NodePort"}}`) cmd.Flags().Set("output", "name") @@ -107,7 +107,7 @@ func TestPatchNoop(t *testing.T) { getObject := &svc.Items[0] patchObject := &svc.Items[0] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -134,7 +134,7 @@ func TestPatchNoop(t *testing.T) { } patchObject.Annotations["foo"] = "bar" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdPatch(f, buf) + cmd := NewCmdPatch(tf, buf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("patch", `{"metadata":{"annotations":{"foo":"bar"}}}`) cmd.Run(cmd, []string{"services", "frontend"}) @@ -153,7 +153,7 @@ func TestPatchObjectFromFileOutput(t *testing.T) { } svcCopy.Labels["post-patch"] = "post-patch-value" - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -173,7 +173,7 @@ func TestPatchObjectFromFileOutput(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdPatch(f, buf) + cmd := NewCmdPatch(tf, buf) cmd.Flags().Set("namespace", "test") cmd.Flags().Set("patch", `{"spec":{"type":"NodePort"}}`) cmd.Flags().Set("output", "yaml") diff --git a/pkg/kubectl/cmd/plugin_test.go b/pkg/kubectl/cmd/plugin_test.go index 58267eaf1a5..bfda32eb64f 100644 --- a/pkg/kubectl/cmd/plugin_test.go +++ b/pkg/kubectl/cmd/plugin_test.go @@ -92,7 +92,7 @@ func TestPluginCmd(t *testing.T) { success: test.expectedSuccess, } - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() cmd := NewCmdForPlugin(f, test.plugin, runner, inBuf, outBuf, errBuf) if cmd == nil { if !test.expectedNilCmd { diff --git a/pkg/kubectl/cmd/portforward_test.go b/pkg/kubectl/cmd/portforward_test.go index f2d0eba3926..673df92c2c9 100644 --- a/pkg/kubectl/cmd/portforward_test.go +++ b/pkg/kubectl/cmd/portforward_test.go @@ -72,7 +72,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { } for _, test := range tests { var err error - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -93,16 +93,16 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() ff := &fakePortForwarder{} if test.pfErr { ff.pfErr = fmt.Errorf("pf error") } opts := &PortForwardOptions{} - cmd := NewCmdPortForward(f, os.Stdout, os.Stderr) + cmd := NewCmdPortForward(tf, os.Stdout, os.Stderr) cmd.Run = func(cmd *cobra.Command, args []string) { - if err = opts.Complete(f, cmd, args); err != nil { + if err = opts.Complete(tf, cmd, args); err != nil { return } opts.PortForwarder = ff diff --git a/pkg/kubectl/cmd/replace_test.go b/pkg/kubectl/cmd/replace_test.go index 4e2f7c6b9d4..164c2ab0d20 100644 --- a/pkg/kubectl/cmd/replace_test.go +++ b/pkg/kubectl/cmd/replace_test.go @@ -32,7 +32,7 @@ import ( func TestReplaceObject(t *testing.T) { _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) deleted := false @@ -64,7 +64,7 @@ func TestReplaceObject(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdReplace(f, buf) + cmd := NewCmdReplace(tf, buf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("output", "name") cmd.Run(cmd, []string{}) @@ -88,7 +88,7 @@ func TestReplaceObject(t *testing.T) { func TestReplaceMultipleObject(t *testing.T) { _, svc, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) redisMasterDeleted := false @@ -134,7 +134,7 @@ func TestReplaceMultipleObject(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdReplace(f, buf) + cmd := NewCmdReplace(tf, buf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("filename", "../../../examples/guestbook/frontend-service.yaml") cmd.Flags().Set("output", "name") @@ -158,7 +158,7 @@ func TestReplaceMultipleObject(t *testing.T) { func TestReplaceDirectory(t *testing.T) { _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) created := map[string]bool{} @@ -191,7 +191,7 @@ func TestReplaceDirectory(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdReplace(f, buf) + cmd := NewCmdReplace(tf, buf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy") cmd.Flags().Set("namespace", "test") cmd.Flags().Set("output", "name") @@ -215,7 +215,7 @@ func TestReplaceDirectory(t *testing.T) { func TestForceReplaceObjectNotFound(t *testing.T) { _, _, rc := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -237,7 +237,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) { tf.Namespace = "test" buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdReplace(f, buf) + cmd := NewCmdReplace(tf, buf) cmd.Flags().Set("filename", "../../../examples/guestbook/legacy/redis-master-controller.yaml") cmd.Flags().Set("force", "true") cmd.Flags().Set("cascade", "false") diff --git a/pkg/kubectl/cmd/resource/get_test.go b/pkg/kubectl/cmd/resource/get_test.go index a56f18f15e7..d4a191c8902 100644 --- a/pkg/kubectl/cmd/resource/get_test.go +++ b/pkg/kubectl/cmd/resource/get_test.go @@ -197,7 +197,7 @@ 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) { t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!") - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() _, _, codec := cmdtesting.NewExternalScheme() tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath) @@ -215,9 +215,9 @@ func TestGetUnknownSchemaObject(t *testing.T) { }, } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() - mapper, _ := f.Object() + mapper, _ := tf.Object() m, err := mapper.RESTMapping(schema.GroupKind{Group: "apitest", Kind: "Type"}) if err != nil { t.Fatal(err) @@ -239,7 +239,7 @@ func TestGetUnknownSchemaObject(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"type", "foo"}) @@ -271,18 +271,18 @@ func TestGetUnknownSchemaObject(t *testing.T) { // 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.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := testapi.Default.Codec() tf.UnstructuredClient = &fake.RESTClient{ NegotiatedSerializer: unstructuredSerializer, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.ReplicationController{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})}, } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.Run(cmd, []string{"replicationcontrollers", "foo"}) if !strings.Contains(buf.String(), "foo") { @@ -293,7 +293,7 @@ func TestGetSchemaObject(t *testing.T) { func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) // overide the openAPISchema function to return custom output @@ -307,7 +307,7 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set(useOpenAPIPrintColumnFlagLabel, "true") cmd.Run(cmd, []string{"pods", "foo"}) @@ -350,7 +350,7 @@ func testOpenAPISchemaData() (openapi.Resources, error) { func TestGetObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -361,7 +361,7 @@ func TestGetObjects(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods", "foo"}) @@ -400,7 +400,7 @@ func TestGetObjectsFiltered(t *testing.T) { for i, test := range testCases { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -412,7 +412,7 @@ func TestGetObjectsFiltered(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) for k, v := range test.flags { cmd.Flags().Lookup(k).Value.Set(v) @@ -442,7 +442,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) { }, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -463,7 +463,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("ignore-not-found", "true") cmd.Flags().Set("output", "yaml") @@ -495,7 +495,7 @@ func TestGetSortedObjects(t *testing.T) { }, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -503,12 +503,12 @@ func TestGetSortedObjects(t *testing.T) { Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)}, } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: "v1"}}} buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) // sorting with metedata.name @@ -528,7 +528,7 @@ c 0/0 0 func TestGetObjectsIdentifiedByFile(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -539,7 +539,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("filename", "../../../../examples/storage/cassandra/cassandra-controller.yaml") cmd.Run(cmd, []string{}) @@ -555,7 +555,7 @@ foo 0/0 0 func TestGetListObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -566,7 +566,7 @@ func TestGetListObjects(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods"}) @@ -582,7 +582,7 @@ bar 0/0 0 func TestGetAllListObjects(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -593,7 +593,7 @@ func TestGetAllListObjects(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("show-all", "true") cmd.Run(cmd, []string{"pods"}) @@ -610,7 +610,7 @@ bar 0/0 0 func TestGetListComponentStatus(t *testing.T) { statuses := testComponentStatusData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -621,7 +621,7 @@ func TestGetListComponentStatus(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"componentstatuses"}) @@ -651,7 +651,7 @@ func TestGetMixedGenericObjects(t *testing.T) { Code: 0, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -667,11 +667,11 @@ func TestGetMixedGenericObjects(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("output", "json") cmd.Run(cmd, []string{"pods"}) @@ -701,7 +701,7 @@ func TestGetMixedGenericObjects(t *testing.T) { func TestGetMultipleTypeObjects(t *testing.T) { pods, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -722,7 +722,7 @@ func TestGetMultipleTypeObjects(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods,services"}) @@ -740,7 +740,7 @@ baz ClusterIP func TestGetMultipleTypeObjectsAsList(t *testing.T) { pods, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -758,11 +758,11 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("output", "json") @@ -842,7 +842,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { pods, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -866,7 +866,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("selector", "a=b") @@ -886,7 +886,7 @@ baz ClusterIP func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { pods, svc, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -910,7 +910,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("field-selector", "a=b") @@ -938,7 +938,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { }, } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -959,7 +959,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Run(cmd, []string{"services/bar", "node/foo"}) @@ -977,7 +977,7 @@ foo Unknown func TestGetByFormatForcesFlag(t *testing.T) { pods, _, _ := testData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -988,7 +988,7 @@ func TestGetByFormatForcesFlag(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Lookup("output").Value.Set("yaml") cmd.Run(cmd, []string{"pods"}) @@ -1072,7 +1072,7 @@ func watchTestData() ([]api.Pod, []watch.Event) { func TestWatchLabelSelector(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) podList := &api.PodList{ @@ -1103,7 +1103,7 @@ func TestWatchLabelSelector(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch", "true") @@ -1124,7 +1124,7 @@ foo 0/0 0 func TestWatchFieldSelector(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) podList := &api.PodList{ @@ -1155,7 +1155,7 @@ func TestWatchFieldSelector(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch", "true") @@ -1176,7 +1176,7 @@ foo 0/0 0 func TestWatchResource(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -1201,7 +1201,7 @@ func TestWatchResource(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch", "true") @@ -1220,7 +1220,7 @@ foo 0/0 0 func TestWatchResourceIdentifiedByFile(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -1245,7 +1245,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch", "true") @@ -1265,7 +1265,7 @@ foo 0/0 0 func TestWatchOnlyResource(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.UnstructuredClient = &fake.RESTClient{ @@ -1290,7 +1290,7 @@ func TestWatchOnlyResource(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch-only", "true") @@ -1308,7 +1308,7 @@ foo 0/0 0 func TestWatchOnlyList(t *testing.T) { pods, events := watchTestData() - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) podList := &api.PodList{ @@ -1336,7 +1336,7 @@ func TestWatchOnlyList(t *testing.T) { buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdGet(f, buf, errBuf) + cmd := NewCmdGet(tf, buf, errBuf) cmd.SetOutput(buf) cmd.Flags().Set("watch-only", "true") diff --git a/pkg/kubectl/cmd/rollingupdate_test.go b/pkg/kubectl/cmd/rollingupdate_test.go index 4260473580b..553afb29a00 100644 --- a/pkg/kubectl/cmd/rollingupdate_test.go +++ b/pkg/kubectl/cmd/rollingupdate_test.go @@ -24,7 +24,7 @@ import ( ) func TestValidateArgs(t *testing.T) { - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() tests := []struct { testName string diff --git a/pkg/kubectl/cmd/run_test.go b/pkg/kubectl/cmd/run_test.go index dc701ea526e..5b47b087876 100644 --- a/pkg/kubectl/cmd/run_test.go +++ b/pkg/kubectl/cmd/run_test.go @@ -168,7 +168,7 @@ func TestRunArgsFollowDashRules(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -186,11 +186,11 @@ func TestRunArgsFollowDashRules(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{} - cmd := NewCmdRun(f, os.Stdin, os.Stdout, os.Stderr) + tf.ClientConfigVal = &restclient.Config{} + cmd := NewCmdRun(tf, os.Stdin, os.Stdout, os.Stderr) cmd.Flags().Set("image", "nginx") cmd.Flags().Set("generator", "run/v1") - err := RunRun(f, os.Stdin, os.Stdout, os.Stderr, cmd, test.args, test.argsLenAtDash) + err := RunRun(tf, os.Stdin, os.Stdout, os.Stderr, cmd, test.args, test.argsLenAtDash) if test.expectError && err == nil { t.Errorf("unexpected non-error (%s)", test.name) } @@ -293,11 +293,11 @@ func TestGenerateService(t *testing.T) { } for _, test := range tests { sawPOST := false - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: "v1"}, NegotiatedSerializer: ns, @@ -346,7 +346,7 @@ func TestGenerateService(t *testing.T) { } buff := &bytes.Buffer{} - _, err := generateService(f, cmd, test.args, test.serviceGenerator, test.params, "namespace", buff) + _, err := generateService(tf, cmd, test.args, test.serviceGenerator, test.params, "namespace", buff) if test.expectErr { if err == nil { t.Error("unexpected non-error") @@ -437,23 +437,23 @@ func TestRunValidations(t *testing.T) { }, } for _, test := range tests { - f, tf := cmdtesting.NewTestFactory() + tf := cmdtesting.NewTestFactory() _, _, codec := cmdtesting.NewExternalScheme() tf.Client = &fake.RESTClient{ NegotiatedSerializer: scheme.Codecs, Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", ""))}, } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() inBuf := bytes.NewReader([]byte{}) outBuf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) - cmd := NewCmdRun(f, inBuf, outBuf, errBuf) + cmd := NewCmdRun(tf, inBuf, outBuf, errBuf) for flagName, flagValue := range test.flags { cmd.Flags().Set(flagName, flagValue) } - err := RunRun(f, inBuf, outBuf, errBuf, cmd, test.args, cmd.ArgsLenAtDash()) + err := RunRun(tf, inBuf, outBuf, errBuf, cmd, test.args, cmd.ArgsLenAtDash()) if err != nil && len(test.expectedErr) > 0 { if !strings.Contains(err.Error(), test.expectedErr) { t.Errorf("unexpected error: %v", err) diff --git a/pkg/kubectl/cmd/set/BUILD b/pkg/kubectl/cmd/set/BUILD index 75ef3e4da79..d7251dbc682 100644 --- a/pkg/kubectl/cmd/set/BUILD +++ b/pkg/kubectl/cmd/set/BUILD @@ -61,7 +61,6 @@ go_test( "//pkg/api/legacyscheme:go_default_library", "//pkg/api/testapi:go_default_library", "//pkg/apis/rbac:go_default_library", - "//pkg/kubectl/categories:go_default_library", "//pkg/kubectl/cmd/testing:go_default_library", "//pkg/kubectl/cmd/util:go_default_library", "//pkg/kubectl/resource:go_default_library", diff --git a/pkg/kubectl/cmd/set/set_env_test.go b/pkg/kubectl/cmd/set/set_env_test.go index 484064a6c45..d02035d11d1 100644 --- a/pkg/kubectl/cmd/set/set_env_test.go +++ b/pkg/kubectl/cmd/set/set_env_test.go @@ -40,14 +40,13 @@ import ( "k8s.io/client-go/rest/fake" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/testapi" - "k8s.io/kubernetes/pkg/kubectl/categories" cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" ) func TestSetEnvLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: ""}, @@ -58,10 +57,10 @@ func TestSetEnvLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdEnv(f, os.Stdin, buf, buf) + cmd := NewCmdEnv(tf, os.Stdin, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -70,10 +69,10 @@ func TestSetEnvLocal(t *testing.T) { Filenames: []string{"../../../../examples/storage/cassandra/cassandra-controller.yaml"}}, Out: buf, Local: true} - opts.Complete(f, cmd) + opts.Complete(tf, cmd) err := opts.Validate([]string{"env=prod"}) if err == nil { - err = opts.RunEnv(f) + err = opts.RunEnv(tf) } if err != nil { t.Fatalf("unexpected error: %v", err) @@ -84,7 +83,7 @@ func TestSetEnvLocal(t *testing.T) { } func TestSetMultiResourcesEnvLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -96,10 +95,10 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdEnv(f, os.Stdin, buf, buf) + cmd := NewCmdEnv(tf, os.Stdin, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -108,10 +107,10 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) { Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}}, Out: buf, Local: true} - opts.Complete(f, cmd) + opts.Complete(tf, cmd) err := opts.Validate([]string{"env=prod"}) if err == nil { - err = opts.RunEnv(f) + err = opts.RunEnv(tf) } if err != nil { t.Fatalf("unexpected error: %v", err) @@ -498,11 +497,10 @@ func TestSetEnvRemote(t *testing.T) { for _, input := range inputs { groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} testapi.Default = testapi.Groups[input.testAPIGroup] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) ns := legacyscheme.Codecs tf.Namespace = "test" - tf.CategoryExpander = categories.LegacyCategoryExpander tf.Client = &fake.RESTClient{ GroupVersion: groupVersion, NegotiatedSerializer: ns, @@ -529,14 +527,14 @@ func TestSetEnvRemote(t *testing.T) { }), VersionedAPIPath: path.Join(input.apiPrefix, testapi.Default.GroupVersion().String()), } - cmd := NewCmdEnv(f, out, out, out) + cmd := NewCmdEnv(tf, out, out, out) cmd.SetOutput(out) cmd.Flags().Set("output", "yaml") opts := input.opts - opts.Complete(f, cmd) + opts.Complete(tf, cmd) err := opts.Validate(input.args) assert.NoError(t, err) - err = opts.RunEnv(f) + err = opts.RunEnv(tf) assert.NoError(t, err) } // TODO This global state restoration needs fixing, b/c it's wrong. Tests should not modify global state diff --git a/pkg/kubectl/cmd/set/set_image_test.go b/pkg/kubectl/cmd/set/set_image_test.go index 25b7ce69a5e..93003f01826 100644 --- a/pkg/kubectl/cmd/set/set_image_test.go +++ b/pkg/kubectl/cmd/set/set_image_test.go @@ -39,14 +39,13 @@ import ( "k8s.io/client-go/rest/fake" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/testapi" - "k8s.io/kubernetes/pkg/kubectl/categories" cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" ) func TestImageLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -58,10 +57,10 @@ func TestImageLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdImage(f, buf, buf) + cmd := NewCmdImage(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -70,7 +69,7 @@ func TestImageLocal(t *testing.T) { Filenames: []string{"../../../../examples/storage/cassandra/cassandra-controller.yaml"}}, Out: buf, Local: true} - err := opts.Complete(f, cmd, []string{"cassandra=thingy"}) + err := opts.Complete(tf, cmd, []string{"cassandra=thingy"}) if err == nil { err = opts.Validate() } @@ -149,7 +148,7 @@ func TestSetImageValidation(t *testing.T) { } func TestSetMultiResourcesImageLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -161,10 +160,10 @@ func TestSetMultiResourcesImageLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdImage(f, buf, buf) + cmd := NewCmdImage(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -173,7 +172,7 @@ func TestSetMultiResourcesImageLocal(t *testing.T) { Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}}, Out: buf, Local: true} - err := opts.Complete(f, cmd, []string{"*=thingy"}) + err := opts.Complete(tf, cmd, []string{"*=thingy"}) if err == nil { err = opts.Validate() } @@ -500,11 +499,10 @@ func TestSetImageRemote(t *testing.T) { for _, input := range inputs { groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} testapi.Default = testapi.Groups[input.testAPIGroup] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) ns := legacyscheme.Codecs tf.Namespace = "test" - tf.CategoryExpander = categories.LegacyCategoryExpander tf.Client = &fake.RESTClient{ GroupVersion: groupVersion, NegotiatedSerializer: ns, @@ -532,13 +530,13 @@ func TestSetImageRemote(t *testing.T) { VersionedAPIPath: path.Join(input.apiPrefix, testapi.Default.GroupVersion().String()), } out := new(bytes.Buffer) - cmd := NewCmdImage(f, out, out) + cmd := NewCmdImage(tf, out, out) cmd.SetOutput(out) cmd.Flags().Set("output", "yaml") opts := ImageOptions{ Out: out, Local: false} - err := opts.Complete(f, cmd, input.args) + err := opts.Complete(tf, cmd, input.args) assert.NoError(t, err) err = opts.Run() assert.NoError(t, err) diff --git a/pkg/kubectl/cmd/set/set_resources_test.go b/pkg/kubectl/cmd/set/set_resources_test.go index 16713873d8a..7d285e02c1d 100644 --- a/pkg/kubectl/cmd/set/set_resources_test.go +++ b/pkg/kubectl/cmd/set/set_resources_test.go @@ -39,14 +39,13 @@ import ( "k8s.io/client-go/rest/fake" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/testapi" - "k8s.io/kubernetes/pkg/kubectl/categories" cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" ) func TestResourcesLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -58,10 +57,10 @@ func TestResourcesLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdResources(f, buf, buf) + cmd := NewCmdResources(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -74,7 +73,7 @@ func TestResourcesLocal(t *testing.T) { Requests: "cpu=200m,memory=512Mi", ContainerSelector: "*"} - err := opts.Complete(f, cmd, []string{}) + err := opts.Complete(tf, cmd, []string{}) if err == nil { err = opts.Validate() } @@ -90,7 +89,7 @@ func TestResourcesLocal(t *testing.T) { } func TestSetMultiResourcesLimitsLocal(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -102,10 +101,10 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdResources(f, buf, buf) + cmd := NewCmdResources(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -118,7 +117,7 @@ func TestSetMultiResourcesLimitsLocal(t *testing.T) { Requests: "cpu=200m,memory=512Mi", ContainerSelector: "*"} - err := opts.Complete(f, cmd, []string{}) + err := opts.Complete(tf, cmd, []string{}) if err == nil { err = opts.Validate() } @@ -446,11 +445,10 @@ func TestSetResourcesRemote(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} testapi.Default = testapi.Groups[input.testAPIGroup] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) ns := legacyscheme.Codecs tf.Namespace = "test" - tf.CategoryExpander = categories.LegacyCategoryExpander tf.Client = &fake.RESTClient{ GroupVersion: groupVersion, NegotiatedSerializer: ns, @@ -478,14 +476,14 @@ func TestSetResourcesRemote(t *testing.T) { VersionedAPIPath: path.Join(input.apiPrefix, testapi.Default.GroupVersion().String()), } buf := new(bytes.Buffer) - cmd := NewCmdResources(f, buf, buf) + cmd := NewCmdResources(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "yaml") opts := ResourcesOptions{ Out: buf, Limits: "cpu=200m,memory=512Mi", ContainerSelector: "*"} - err := opts.Complete(f, cmd, input.args) + err := opts.Complete(tf, cmd, input.args) if err == nil { err = opts.Validate() } diff --git a/pkg/kubectl/cmd/set/set_selector_test.go b/pkg/kubectl/cmd/set/set_selector_test.go index 91c2cd381bd..1b832240bea 100644 --- a/pkg/kubectl/cmd/set/set_selector_test.go +++ b/pkg/kubectl/cmd/set/set_selector_test.go @@ -316,7 +316,7 @@ func TestGetResourcesAndSelector(t *testing.T) { } func TestSelectorTest(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: ""}, @@ -327,10 +327,10 @@ func TestSelectorTest(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdSelector(f, buf) + cmd := NewCmdSelector(tf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") diff --git a/pkg/kubectl/cmd/set/set_serviceaccount_test.go b/pkg/kubectl/cmd/set/set_serviceaccount_test.go index f6b5451ef07..381b7c7ee8b 100644 --- a/pkg/kubectl/cmd/set/set_serviceaccount_test.go +++ b/pkg/kubectl/cmd/set/set_serviceaccount_test.go @@ -39,7 +39,6 @@ import ( "k8s.io/client-go/rest/fake" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/testapi" - "k8s.io/kubernetes/pkg/kubectl/categories" cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" @@ -68,7 +67,7 @@ func TestSetServiceAccountLocal(t *testing.T) { for i, input := range inputs { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: "v1"}, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -78,7 +77,7 @@ func TestSetServiceAccountLocal(t *testing.T) { } tf.Namespace = "test" out := new(bytes.Buffer) - cmd := NewCmdServiceAccount(f, out, out) + cmd := NewCmdServiceAccount(tf, out, out) cmd.SetOutput(out) cmd.Flags().Set("output", "yaml") cmd.Flags().Set("local", "true") @@ -87,7 +86,7 @@ func TestSetServiceAccountLocal(t *testing.T) { Filenames: []string{input.yaml}}, out: out, local: true} - err := saConfig.Complete(f, cmd, []string{serviceAccount}) + err := saConfig.Complete(tf, cmd, []string{serviceAccount}) assert.NoError(t, err) err = saConfig.Run() assert.NoError(t, err) @@ -98,7 +97,7 @@ func TestSetServiceAccountLocal(t *testing.T) { func TestSetServiceAccountMultiLocal(t *testing.T) { testapi.Default = testapi.Groups[""] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: ""}, @@ -109,10 +108,10 @@ func TestSetServiceAccountMultiLocal(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} + tf.ClientConfigVal = &restclient.Config{ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Version: ""}}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdServiceAccount(f, buf, buf) + cmd := NewCmdServiceAccount(tf, buf, buf) cmd.SetOutput(buf) cmd.Flags().Set("output", "name") cmd.Flags().Set("local", "true") @@ -121,7 +120,7 @@ func TestSetServiceAccountMultiLocal(t *testing.T) { out: buf, local: true} - err := opts.Complete(f, cmd, []string{serviceAccount}) + err := opts.Complete(tf, cmd, []string{serviceAccount}) if err == nil { err = opts.Run() } @@ -313,11 +312,10 @@ func TestSetServiceAccountRemote(t *testing.T) { for _, input := range inputs { groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} testapi.Default = testapi.Groups[input.testAPIGroup] - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) ns := legacyscheme.Codecs tf.Namespace = "test" - tf.CategoryExpander = categories.LegacyCategoryExpander tf.Client = &fake.RESTClient{ GroupVersion: groupVersion, NegotiatedSerializer: ns, @@ -345,13 +343,13 @@ func TestSetServiceAccountRemote(t *testing.T) { VersionedAPIPath: path.Join(input.apiPrefix, testapi.Default.GroupVersion().String()), } out := new(bytes.Buffer) - cmd := NewCmdServiceAccount(f, out, out) + cmd := NewCmdServiceAccount(tf, out, out) cmd.SetOutput(out) cmd.Flags().Set("output", "yaml") saConfig := serviceAccountConfig{ out: out, local: false} - err := saConfig.Complete(f, cmd, input.args) + err := saConfig.Complete(tf, cmd, input.args) assert.NoError(t, err) err = saConfig.Run() assert.NoError(t, err) @@ -367,7 +365,7 @@ func TestServiceAccountValidation(t *testing.T) { {args: []string{serviceAccount}, errorString: resourceMissingErrString}, } for _, input := range inputs { - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Client = &fake.RESTClient{ GroupVersion: schema.GroupVersion{Version: "v1"}, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { @@ -377,11 +375,11 @@ func TestServiceAccountValidation(t *testing.T) { } tf.Namespace = "test" out := bytes.NewBuffer([]byte{}) - cmd := NewCmdServiceAccount(f, out, out) + cmd := NewCmdServiceAccount(tf, out, out) cmd.SetOutput(out) saConfig := &serviceAccountConfig{} - err := saConfig.Complete(f, cmd, input.args) + err := saConfig.Complete(tf, cmd, input.args) assert.EqualError(t, err, input.errorString) } } diff --git a/pkg/kubectl/cmd/set/set_subject_test.go b/pkg/kubectl/cmd/set/set_subject_test.go index 66a4ef72064..27658d33766 100644 --- a/pkg/kubectl/cmd/set/set_subject_test.go +++ b/pkg/kubectl/cmd/set/set_subject_test.go @@ -28,7 +28,7 @@ import ( ) func TestValidate(t *testing.T) { - _, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() tf.Namespace = "test" tests := map[string]struct { diff --git a/pkg/kubectl/cmd/taint_test.go b/pkg/kubectl/cmd/taint_test.go index bc3079b9b28..fc6f9fa4e0b 100644 --- a/pkg/kubectl/cmd/taint_test.go +++ b/pkg/kubectl/cmd/taint_test.go @@ -239,7 +239,7 @@ func TestTaint(t *testing.T) { oldNode, expectNewNode := generateNodeAndTaintedNode(test.oldTaints, test.newTaints) new_node := &v1.Node{} tainted := false - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -298,10 +298,10 @@ func TestTaint(t *testing.T) { } }), } - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTaint(f, buf) + cmd := NewCmdTaint(tf, buf) saw_fatal := false func() { diff --git a/pkg/kubectl/cmd/testing/BUILD b/pkg/kubectl/cmd/testing/BUILD index 68152e62d8b..0046490faba 100644 --- a/pkg/kubectl/cmd/testing/BUILD +++ b/pkg/kubectl/cmd/testing/BUILD @@ -22,14 +22,11 @@ go_library( "//pkg/kubectl/cmd/util:go_default_library", "//pkg/kubectl/cmd/util/openapi:go_default_library", "//pkg/kubectl/cmd/util/openapi/testing:go_default_library", - "//pkg/kubectl/plugins:go_default_library", "//pkg/kubectl/resource:go_default_library", "//pkg/kubectl/scheme:go_default_library", "//pkg/kubectl/validation:go_default_library", "//pkg/printers:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library", - "//vendor/github.com/spf13/pflag:go_default_library", - "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library", diff --git a/pkg/kubectl/cmd/testing/fake.go b/pkg/kubectl/cmd/testing/fake.go index 5f6a180ab6f..0098607e019 100644 --- a/pkg/kubectl/cmd/testing/fake.go +++ b/pkg/kubectl/cmd/testing/fake.go @@ -23,9 +23,7 @@ import ( "time" "github.com/spf13/cobra" - "github.com/spf13/pflag" - "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -44,7 +42,6 @@ import ( cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi" openapitesting "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing" - "k8s.io/kubernetes/pkg/kubectl/plugins" "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/scheme" "k8s.io/kubernetes/pkg/kubectl/validation" @@ -234,209 +231,72 @@ func (d *fakeCachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList } type TestFactory struct { + cmdutil.Factory + Client kubectl.RESTClient UnstructuredClient kubectl.RESTClient - Describer printers.Describer - Validator validation.Schema + DescriberVal printers.Describer Namespace string - ClientConfig *restclient.Config - Err error - Command string - TmpDir string - CategoryExpander categories.CategoryExpander + ClientConfigVal *restclient.Config + CommandVal string - ClientForMappingFunc func(mapping *meta.RESTMapping) (resource.RESTClient, error) UnstructuredClientForMappingFunc func(mapping *meta.RESTMapping) (resource.RESTClient, error) OpenAPISchemaFunc func() (openapi.Resources, error) } -type FakeFactory struct { - tf *TestFactory -} - -func NewTestFactory() (cmdutil.Factory, *TestFactory) { - t := &TestFactory{ - Validator: validation.NullSchema{}, +func NewTestFactory() *TestFactory { + return &TestFactory{ + Factory: cmdutil.NewFactory(nil), } - return &FakeFactory{ - tf: t, - }, t } -func (f *FakeFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) { - discoveryClient, err := discovery.NewDiscoveryClientForConfig(f.tf.ClientConfig) - if err != nil { - return nil, err - } - return &fakeCachedDiscoveryClient{DiscoveryInterface: discoveryClient}, nil -} - -func (f *FakeFactory) FlagSet() *pflag.FlagSet { - return nil -} - -func (f *FakeFactory) Object() (meta.RESTMapper, runtime.ObjectTyper) { - groupResources := testDynamicResources() - mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructuredConversion(legacyscheme.Registry.InterfacesFor)) - typer := discovery.NewUnstructuredObjectTyper(groupResources, legacyscheme.Scheme) - - fakeDs := &fakeCachedDiscoveryClient{} - expander := cmdutil.NewShortcutExpander(mapper, fakeDs) - return expander, typer -} - -func (f *FakeFactory) CategoryExpander() categories.CategoryExpander { +func (f *TestFactory) CategoryExpander() categories.CategoryExpander { return categories.LegacyCategoryExpander } -func (f *FakeFactory) RESTClient() (*restclient.RESTClient, error) { - return nil, nil +func (f *TestFactory) ClientConfig() (*restclient.Config, error) { + return f.ClientConfigVal, nil } -func (f *FakeFactory) KubernetesClientSet() (*kubernetes.Clientset, error) { - return nil, nil +func (f *TestFactory) BareClientConfig() (*restclient.Config, error) { + return f.ClientConfigVal, nil } -func (f *FakeFactory) ClientSet() (internalclientset.Interface, error) { - return nil, nil +func (f *TestFactory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { + return f.Client, nil } -func (f *FakeFactory) ClientConfig() (*restclient.Config, error) { - return f.tf.ClientConfig, f.tf.Err -} - -func (f *FakeFactory) BareClientConfig() (*restclient.Config, error) { - return f.tf.ClientConfig, f.tf.Err -} - -func (f *FakeFactory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { - if f.tf.ClientForMappingFunc != nil { - return f.tf.ClientForMappingFunc(mapping) +func (f *TestFactory) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { + if f.UnstructuredClientForMappingFunc != nil { + return f.UnstructuredClientForMappingFunc(mapping) } - return f.tf.Client, f.tf.Err + return f.UnstructuredClient, nil } -func (f *FakeFactory) UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) { - if f.tf.UnstructuredClientForMappingFunc != nil { - return f.tf.UnstructuredClientForMappingFunc(mapping) +func (f *TestFactory) Describer(*meta.RESTMapping) (printers.Describer, error) { + return f.DescriberVal, nil +} + +func (f *TestFactory) Validator(validate bool) (validation.Schema, error) { + return validation.NullSchema{}, nil +} + +func (f *TestFactory) DefaultNamespace() (string, bool, error) { + return f.Namespace, false, nil +} + +func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) { + if f.OpenAPISchemaFunc != nil { + return f.OpenAPISchemaFunc() } - return f.tf.UnstructuredClient, f.tf.Err + return openapitesting.EmptyResources{}, nil } -func (f *FakeFactory) Describer(*meta.RESTMapping) (printers.Describer, error) { - return f.tf.Describer, f.tf.Err +func (f *TestFactory) Command(*cobra.Command, bool) string { + return f.CommandVal } -func (f *FakeFactory) Scaler(*meta.RESTMapping) (kubectl.Scaler, error) { - return nil, nil -} - -func (f *FakeFactory) Reaper(*meta.RESTMapping) (kubectl.Reaper, error) { - return nil, nil -} - -func (f *FakeFactory) HistoryViewer(*meta.RESTMapping) (kubectl.HistoryViewer, error) { - return nil, nil -} - -func (f *FakeFactory) Rollbacker(*meta.RESTMapping) (kubectl.Rollbacker, error) { - return nil, nil -} - -func (f *FakeFactory) StatusViewer(*meta.RESTMapping) (kubectl.StatusViewer, error) { - return nil, nil -} - -func (f *FakeFactory) MapBasedSelectorForObject(runtime.Object) (string, error) { - return "", nil -} - -func (f *FakeFactory) PortsForObject(runtime.Object) ([]string, error) { - return nil, nil -} - -func (f *FakeFactory) ProtocolsForObject(runtime.Object) (map[string]string, error) { - return nil, nil -} - -func (f *FakeFactory) LabelsForObject(runtime.Object) (map[string]string, error) { - return nil, nil -} - -func (f *FakeFactory) LogsForObject(object, options runtime.Object, timeout time.Duration) (*restclient.Request, error) { - return nil, nil -} - -func (f *FakeFactory) Pauser(info *resource.Info) ([]byte, error) { - return nil, nil -} - -func (f *FakeFactory) Resumer(info *resource.Info) ([]byte, error) { - return nil, nil -} - -func (f *FakeFactory) ResolveImage(name string) (string, error) { - return name, nil -} - -func (f *FakeFactory) Validator(validate bool) (validation.Schema, error) { - return f.tf.Validator, f.tf.Err -} - -func (f *FakeFactory) OpenAPISchema() (openapi.Resources, error) { - return nil, nil -} - -func (f *FakeFactory) DefaultNamespace() (string, bool, error) { - return f.tf.Namespace, false, f.tf.Err -} - -func (f *FakeFactory) Generators(cmdName string) map[string]kubectl.Generator { - var generator map[string]kubectl.Generator - switch cmdName { - case "run": - generator = map[string]kubectl.Generator{ - cmdutil.DeploymentV1Beta1GeneratorName: kubectl.DeploymentV1Beta1{}, - } - } - return generator -} - -func (f *FakeFactory) CanBeExposed(schema.GroupKind) error { - return nil -} - -func (f *FakeFactory) CanBeAutoscaled(schema.GroupKind) error { - return nil -} - -func (f *FakeFactory) AttachablePodForObject(ob runtime.Object, timeout time.Duration) (*api.Pod, error) { - return nil, nil -} - -func (f *FakeFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) { - return f.ApproximatePodTemplateForObject(obj) -} - -func (f *FakeFactory) UpdatePodSpecForObject(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) { - return false, nil -} - -func (f *FakeFactory) EditorEnvs() []string { - return nil -} - -func (f *FakeFactory) Command(*cobra.Command, bool) string { - return f.tf.Command -} - -func (f *FakeFactory) BindFlags(flags *pflag.FlagSet) { -} - -func (f *FakeFactory) BindExternalFlags(flags *pflag.FlagSet) { -} - -func (f *FakeFactory) NewBuilder() *resource.Builder { +func (f *TestFactory) NewBuilder() *resource.Builder { mapper, typer := f.Object() return resource.NewBuilder( @@ -456,68 +316,9 @@ func (f *FakeFactory) NewBuilder() *resource.Builder { ) } -func (f *FakeFactory) DefaultResourceFilterOptions(cmd *cobra.Command, withNamespace bool) *printers.PrintOptions { - return &printers.PrintOptions{} -} - -func (f *FakeFactory) DefaultResourceFilterFunc() kubectl.Filters { - return nil -} - -func (f *FakeFactory) SuggestedPodTemplateResources() []schema.GroupResource { - return []schema.GroupResource{} -} - -func (f *FakeFactory) PluginLoader() plugins.PluginLoader { - return &plugins.DummyPluginLoader{} -} - -func (f *FakeFactory) PluginRunner() plugins.PluginRunner { - return &plugins.ExecPluginRunner{} -} - -type fakeAPIFactory struct { - cmdutil.Factory - tf *TestFactory -} - -func (f *fakeAPIFactory) Object() (meta.RESTMapper, runtime.ObjectTyper) { - groupResources := testDynamicResources() - mapper := discovery.NewRESTMapper( - groupResources, - meta.InterfacesForUnstructuredConversion(func(version schema.GroupVersion) (*meta.VersionInterfaces, error) { - switch version { - // provide typed objects for these two versions - case ValidVersionGV, UnlikelyGV: - return &meta.VersionInterfaces{ - ObjectConvertor: scheme.Scheme, - MetadataAccessor: meta.NewAccessor(), - }, nil - // otherwise fall back to the legacy scheme - default: - return legacyscheme.Registry.InterfacesFor(version) - } - }), - ) - // for backwards compatibility with existing tests, allow rest mappings from the scheme to show up - // TODO: make this opt-in? - mapper = meta.FirstHitRESTMapper{ - MultiRESTMapper: meta.MultiRESTMapper{ - mapper, - legacyscheme.Registry.RESTMapper(), - }, - } - - // TODO: should probably be the external scheme - typer := discovery.NewUnstructuredObjectTyper(groupResources, legacyscheme.Scheme) - fakeDs := &fakeCachedDiscoveryClient{} - expander := cmdutil.NewShortcutExpander(mapper, fakeDs) - return expander, typer -} - -func (f *fakeAPIFactory) KubernetesClientSet() (*kubernetes.Clientset, error) { - fakeClient := f.tf.Client.(*fake.RESTClient) - clientset := kubernetes.NewForConfigOrDie(f.tf.ClientConfig) +func (f *TestFactory) KubernetesClientSet() (*kubernetes.Clientset, error) { + fakeClient := f.Client.(*fake.RESTClient) + clientset := kubernetes.NewForConfigOrDie(f.ClientConfigVal) clientset.CoreV1().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.AuthorizationV1().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client @@ -539,14 +340,14 @@ func (f *fakeAPIFactory) KubernetesClientSet() (*kubernetes.Clientset, error) { clientset.PolicyV1beta1().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.DiscoveryClient.RESTClient().(*restclient.RESTClient).Client = fakeClient.Client - return clientset, f.tf.Err + return clientset, nil } -func (f *fakeAPIFactory) ClientSet() (internalclientset.Interface, error) { +func (f *TestFactory) ClientSet() (internalclientset.Interface, error) { // Swap the HTTP client out of the REST client with the fake // version. - fakeClient := f.tf.Client.(*fake.RESTClient) - clientset := internalclientset.NewForConfigOrDie(f.tf.ClientConfig) + fakeClient := f.Client.(*fake.RESTClient) + clientset := internalclientset.NewForConfigOrDie(f.ClientConfigVal) clientset.Core().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.Authentication().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.Authorization().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client @@ -559,59 +360,68 @@ func (f *fakeAPIFactory) ClientSet() (internalclientset.Interface, error) { clientset.Apps().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.Policy().RESTClient().(*restclient.RESTClient).Client = fakeClient.Client clientset.DiscoveryClient.RESTClient().(*restclient.RESTClient).Client = fakeClient.Client - return clientset, f.tf.Err + return clientset, nil } -func (f *fakeAPIFactory) RESTClient() (*restclient.RESTClient, error) { +func (f *TestFactory) RESTClient() (*restclient.RESTClient, error) { // Swap out the HTTP client out of the client with the fake's version. - fakeClient := f.tf.Client.(*fake.RESTClient) - restClient, err := restclient.RESTClientFor(f.tf.ClientConfig) + fakeClient := f.Client.(*fake.RESTClient) + restClient, err := restclient.RESTClientFor(f.ClientConfigVal) if err != nil { panic(err) } restClient.Client = fakeClient.Client - return restClient, f.tf.Err + return restClient, nil } -func (f *fakeAPIFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) { - fakeClient := f.tf.Client.(*fake.RESTClient) - discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(f.tf.ClientConfig) +func (f *TestFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) { + fakeClient := f.Client.(*fake.RESTClient) + discoveryClient := discovery.NewDiscoveryClientForConfigOrDie(f.ClientConfigVal) discoveryClient.RESTClient().(*restclient.RESTClient).Client = fakeClient.Client - cacheDir := filepath.Join(f.tf.TmpDir, ".kube", "cache", "discovery") + cacheDir := filepath.Join("", ".kube", "cache", "discovery") return cmdutil.NewCachedDiscoveryClient(discoveryClient, cacheDir, time.Duration(10*time.Minute)), nil } -func (f *fakeAPIFactory) CategoryExpander() categories.CategoryExpander { - if f.tf.CategoryExpander != nil { - return f.tf.CategoryExpander +func (f *TestFactory) ClientSetForVersion(requiredVersion *schema.GroupVersion) (internalclientset.Interface, error) { + return f.ClientSet() +} + +func (f *TestFactory) Object() (meta.RESTMapper, runtime.ObjectTyper) { + groupResources := testDynamicResources() + mapper := discovery.NewRESTMapper( + groupResources, + meta.InterfacesForUnstructuredConversion(func(version schema.GroupVersion) (*meta.VersionInterfaces, error) { + switch version { + // provide typed objects for these two versions + case ValidVersionGV, UnlikelyGV: + return &meta.VersionInterfaces{ + ObjectConvertor: scheme.Scheme, + MetadataAccessor: meta.NewAccessor(), + }, nil + // otherwise fall back to the legacy scheme + default: + return legacyscheme.Registry.InterfacesFor(version) + } + }), + ) + // for backwards compatibility with existing tests, allow rest mappings from the scheme to show up + // TODO: make this opt-in? + mapper = meta.FirstHitRESTMapper{ + MultiRESTMapper: meta.MultiRESTMapper{ + mapper, + legacyscheme.Registry.RESTMapper(), + }, } - return f.Factory.CategoryExpander() + + // TODO: should probably be the external scheme + typer := discovery.NewUnstructuredObjectTyper(groupResources, legacyscheme.Scheme) + fakeDs := &fakeCachedDiscoveryClient{} + expander := cmdutil.NewShortcutExpander(mapper, fakeDs) + return expander, typer } -func (f *fakeAPIFactory) ClientConfig() (*restclient.Config, error) { - return f.tf.ClientConfig, f.tf.Err -} - -func (f *fakeAPIFactory) ClientForMapping(m *meta.RESTMapping) (resource.RESTClient, error) { - if f.tf.ClientForMappingFunc != nil { - return f.tf.ClientForMappingFunc(m) - } - return f.tf.Client, f.tf.Err -} - -func (f *fakeAPIFactory) UnstructuredClientForMapping(m *meta.RESTMapping) (resource.RESTClient, error) { - if f.tf.UnstructuredClientForMappingFunc != nil { - return f.tf.UnstructuredClientForMappingFunc(m) - } - return f.tf.UnstructuredClient, f.tf.Err -} - -func (f *fakeAPIFactory) Describer(*meta.RESTMapping) (printers.Describer, error) { - return f.tf.Describer, f.tf.Err -} - -func (f *fakeAPIFactory) LogsForObject(object, options runtime.Object, timeout time.Duration) (*restclient.Request, error) { +func (f *TestFactory) LogsForObject(object, options runtime.Object, timeout time.Duration) (*restclient.Request, error) { c, err := f.ClientSet() if err != nil { panic(err) @@ -623,83 +433,12 @@ func (f *fakeAPIFactory) LogsForObject(object, options runtime.Object, timeout t if !ok { return nil, errors.New("provided options object is not a PodLogOptions") } - return c.Core().Pods(f.tf.Namespace).GetLogs(t.Name, opts), nil + return c.Core().Pods(f.Namespace).GetLogs(t.Name, opts), nil default: return nil, fmt.Errorf("cannot get the logs from %T", object) } } -func (f *fakeAPIFactory) AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error) { - switch t := object.(type) { - case *api.Pod: - return t, nil - default: - return nil, fmt.Errorf("cannot attach to %T: not implemented", object) - } -} - -func (f *fakeAPIFactory) ApproximatePodTemplateForObject(obj runtime.Object) (*api.PodTemplateSpec, error) { - return f.Factory.ApproximatePodTemplateForObject(obj) -} - -func (f *fakeAPIFactory) Validator(validate bool) (validation.Schema, error) { - return f.tf.Validator, f.tf.Err -} - -func (f *fakeAPIFactory) DefaultNamespace() (string, bool, error) { - return f.tf.Namespace, false, f.tf.Err -} - -func (f *fakeAPIFactory) Command(*cobra.Command, bool) string { - return f.tf.Command -} - -func (f *fakeAPIFactory) Generators(cmdName string) map[string]kubectl.Generator { - return cmdutil.DefaultGenerators(cmdName) -} - -func (f *fakeAPIFactory) NewBuilder() *resource.Builder { - mapper, typer := f.Object() - - return resource.NewBuilder( - &resource.Mapper{ - RESTMapper: mapper, - ObjectTyper: typer, - ClientMapper: resource.ClientMapperFunc(f.ClientForMapping), - Decoder: cmdutil.InternalVersionDecoder(), - }, - &resource.Mapper{ - RESTMapper: mapper, - ObjectTyper: typer, - ClientMapper: resource.ClientMapperFunc(f.UnstructuredClientForMapping), - Decoder: unstructured.UnstructuredJSONScheme, - }, - f.CategoryExpander(), - ) -} - -func (f *fakeAPIFactory) SuggestedPodTemplateResources() []schema.GroupResource { - return []schema.GroupResource{} -} - -func (f *fakeAPIFactory) OpenAPISchema() (openapi.Resources, error) { - if f.tf.OpenAPISchemaFunc != nil { - return f.tf.OpenAPISchemaFunc() - } - return openapitesting.EmptyResources{}, nil -} - -func NewAPIFactory() (cmdutil.Factory, *TestFactory) { - t := &TestFactory{ - Validator: validation.NullSchema{}, - } - rf := cmdutil.NewFactory(nil) - return &fakeAPIFactory{ - Factory: rf, - tf: t, - }, t -} - func testDynamicResources() []*discovery.APIGroupResources { return []*discovery.APIGroupResources{ { diff --git a/pkg/kubectl/cmd/top_node_test.go b/pkg/kubectl/cmd/top_node_test.go index fdb0d40c340..2780ea3b96c 100644 --- a/pkg/kubectl/cmd/top_node_test.go +++ b/pkg/kubectl/cmd/top_node_test.go @@ -49,7 +49,7 @@ func TestTopNodeAllMetrics(t *testing.T) { expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", baseMetricsAddress, metricsApiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -76,10 +76,10 @@ func TestTopNodeAllMetrics(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) cmd.Run(cmd, []string{}) // Check the presence of node names in the output. @@ -100,7 +100,7 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { expectedMetricsPath := fmt.Sprintf("%s/%s/nodes", customBaseMetricsAddress, metricsApiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -127,7 +127,7 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) opts := &TopNodeOptions{ @@ -137,7 +137,7 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { Service: "custom-heapster-service", }, } - cmd := NewCmdTopNode(f, opts, buf) + cmd := NewCmdTopNode(tf, opts, buf) cmd.Run(cmd, []string{}) // Check the presence of node names in the output. @@ -161,7 +161,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) { expectedPath := fmt.Sprintf("%s/%s/nodes/%s", baseMetricsAddress, metricsApiVersion, expectedMetrics.Name) expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -188,10 +188,10 @@ func TestTopNodeWithNameMetrics(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) cmd.Run(cmd, []string{expectedMetrics.Name}) // Check the presence of node names in the output. @@ -226,7 +226,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) { expectedQuery := fmt.Sprintf("labelSelector=%s", url.QueryEscape(label)) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -253,10 +253,10 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) { }), } tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) cmd.Flags().Set("selector", label) cmd.Run(cmd, []string{}) @@ -279,7 +279,7 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) { expectedMetrics, nodes := testNodeV1beta1MetricsData() expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -304,15 +304,15 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) { return true, expectedMetrics, nil }) tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) // TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks // TODO then check the particular Run functionality and harvest results from fake clients cmdOptions := &TopNodeOptions{} - if err := cmdOptions.Complete(f, cmd, []string{}, buf); err != nil { + if err := cmdOptions.Complete(tf, cmd, []string{}, buf); err != nil { t.Fatal(err) } cmdOptions.MetricsClient = fakemetricsClientset @@ -343,7 +343,7 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) { } expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -368,15 +368,15 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) { return true, &expectedMetrics, nil }) tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) // TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks // TODO then check the particular Run functionality and harvest results from fake clients cmdOptions := &TopNodeOptions{} - if err := cmdOptions.Complete(f, cmd, []string{expectedMetrics.Name}, buf); err != nil { + if err := cmdOptions.Complete(tf, cmd, []string{expectedMetrics.Name}, buf); err != nil { t.Fatal(err) } cmdOptions.MetricsClient = fakemetricsClientset @@ -417,7 +417,7 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) { label := "key=value" expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) ns := legacyscheme.Codecs @@ -443,16 +443,16 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) { return true, expectedMetrics, nil }) tf.Namespace = "test" - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopNode(f, nil, buf) + cmd := NewCmdTopNode(tf, nil, buf) cmd.Flags().Set("selector", label) // TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks // TODO then check the particular Run functionality and harvest results from fake clients cmdOptions := &TopNodeOptions{} - if err := cmdOptions.Complete(f, cmd, []string{}, buf); err != nil { + if err := cmdOptions.Complete(tf, cmd, []string{}, buf); err != nil { t.Fatal(err) } cmdOptions.MetricsClient = fakemetricsClientset diff --git a/pkg/kubectl/cmd/top_pod_test.go b/pkg/kubectl/cmd/top_pod_test.go index 5edb9d52ddc..86b95936dd4 100644 --- a/pkg/kubectl/cmd/top_pod_test.go +++ b/pkg/kubectl/cmd/top_pod_test.go @@ -162,7 +162,7 @@ func TestTopPod(t *testing.T) { } } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -187,10 +187,10 @@ func TestTopPod(t *testing.T) { }), } tf.Namespace = testNS - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopPod(f, nil, buf) + cmd := NewCmdTopPod(tf, nil, buf) for name, value := range testCase.flags { cmd.Flags().Set(name, value) } @@ -304,7 +304,7 @@ func TestTopPodWithMetricsServer(t *testing.T) { }) } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -323,10 +323,10 @@ func TestTopPodWithMetricsServer(t *testing.T) { }), } tf.Namespace = testNS - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdTopPod(f, nil, buf) + cmd := NewCmdTopPod(tf, nil, buf) var cmdOptions *TopPodOptions if testCase.options != nil { cmdOptions = testCase.options @@ -336,7 +336,7 @@ func TestTopPodWithMetricsServer(t *testing.T) { // TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks // TODO then check the particular Run functionality and harvest results from fake clients. We probably end up skipping the factory altogether. - if err := cmdOptions.Complete(f, cmd, testCase.args, buf); err != nil { + if err := cmdOptions.Complete(tf, cmd, testCase.args, buf); err != nil { t.Fatal(err) } cmdOptions.MetricsClient = fakemetricsClientset @@ -499,7 +499,7 @@ func TestTopPodCustomDefaults(t *testing.T) { } } - f, tf := cmdtesting.NewAPIFactory() + tf := cmdtesting.NewTestFactory() ns := legacyscheme.Codecs tf.Client = &fake.RESTClient{ @@ -524,7 +524,7 @@ func TestTopPodCustomDefaults(t *testing.T) { }), } tf.Namespace = testNS - tf.ClientConfig = defaultClientConfig() + tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) opts := &TopPodOptions{ @@ -535,7 +535,7 @@ func TestTopPodCustomDefaults(t *testing.T) { }, DiscoveryClient: &fakeDiscovery{}, } - cmd := NewCmdTopPod(f, opts, buf) + cmd := NewCmdTopPod(tf, opts, buf) for name, value := range testCase.flags { cmd.Flags().Set(name, value) } diff --git a/pkg/kubectl/cmd/top_test.go b/pkg/kubectl/cmd/top_test.go index adbc1d619a9..f8a49115e4b 100644 --- a/pkg/kubectl/cmd/top_test.go +++ b/pkg/kubectl/cmd/top_test.go @@ -43,7 +43,7 @@ const ( func TestTopSubcommandsExist(t *testing.T) { initTestErrorHandler(t) - f, _ := cmdtesting.NewAPIFactory() + f := cmdtesting.NewTestFactory() buf := bytes.NewBuffer([]byte{}) cmd := NewCmdTop(f, buf, buf)