use temp kubeconfig for fake factory

parent 40143fd6
...@@ -417,7 +417,10 @@ func TestAnnotateErrors(t *testing.T) { ...@@ -417,7 +417,10 @@ func TestAnnotateErrors(t *testing.T) {
} }
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -435,11 +438,12 @@ func TestAnnotateErrors(t *testing.T) { ...@@ -435,11 +438,12 @@ func TestAnnotateErrors(t *testing.T) {
} }
if !testCase.errFn(err) { if !testCase.errFn(err) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
continue return
} }
if buf.Len() > 0 { if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes())) t.Errorf("buffer should be empty: %s", string(buf.Bytes()))
} }
})
} }
} }
...@@ -447,6 +451,8 @@ func TestAnnotateObject(t *testing.T) { ...@@ -447,6 +451,8 @@ func TestAnnotateObject(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -499,6 +505,8 @@ func TestAnnotateObjectFromFile(t *testing.T) { ...@@ -499,6 +505,8 @@ func TestAnnotateObjectFromFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -550,6 +558,8 @@ func TestAnnotateObjectFromFile(t *testing.T) { ...@@ -550,6 +558,8 @@ func TestAnnotateObjectFromFile(t *testing.T) {
func TestAnnotateLocal(t *testing.T) { func TestAnnotateLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"}, GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"},
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
...@@ -581,6 +591,8 @@ func TestAnnotateMultipleObjects(t *testing.T) { ...@@ -581,6 +591,8 @@ func TestAnnotateMultipleObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"}, GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"},
......
...@@ -69,6 +69,8 @@ func TestApplyExtraArgsFail(t *testing.T) { ...@@ -69,6 +69,8 @@ func TestApplyExtraArgsFail(t *testing.T) {
errBuf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{})
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
c := NewCmdApply("kubectl", f, buf, errBuf) c := NewCmdApply("kubectl", f, buf, errBuf)
if validateApplyArgs(c, []string{"rc"}) == nil { if validateApplyArgs(c, []string{"rc"}) == nil {
t.Fatalf("unexpected non-error") t.Fatalf("unexpected non-error")
...@@ -332,7 +334,10 @@ func TestRunApplyViewLastApplied(t *testing.T) { ...@@ -332,7 +334,10 @@ func TestRunApplyViewLastApplied(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -381,6 +386,7 @@ func TestRunApplyViewLastApplied(t *testing.T) { ...@@ -381,6 +386,7 @@ func TestRunApplyViewLastApplied(t *testing.T) {
if buf.String() != test.expectedOut { if buf.String() != test.expectedOut {
t.Fatalf("%s: unexpected output: %s\nexpected: %s", test.name, buf.String(), test.expectedOut) t.Fatalf("%s: unexpected output: %s\nexpected: %s", test.name, buf.String(), test.expectedOut)
} }
})
} }
} }
...@@ -390,6 +396,8 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) { ...@@ -390,6 +396,8 @@ func TestApplyObjectWithoutAnnotation(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -433,7 +441,10 @@ func TestApplyObject(t *testing.T) { ...@@ -433,7 +441,10 @@ func TestApplyObject(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply when a local object is specified", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -469,6 +480,7 @@ func TestApplyObject(t *testing.T) { ...@@ -469,6 +480,7 @@ func TestApplyObject(t *testing.T) {
if errBuf.String() != "" { if errBuf.String() != "" {
t.Fatalf("unexpected error output: %s", errBuf.String()) t.Fatalf("unexpected error output: %s", errBuf.String())
} }
})
} }
} }
...@@ -494,7 +506,10 @@ func TestApplyObjectOutput(t *testing.T) { ...@@ -494,7 +506,10 @@ func TestApplyObjectOutput(t *testing.T) {
} }
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply returns correct output", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -531,6 +546,7 @@ func TestApplyObjectOutput(t *testing.T) { ...@@ -531,6 +546,7 @@ func TestApplyObjectOutput(t *testing.T) {
if errBuf.String() != "" { if errBuf.String() != "" {
t.Fatalf("unexpected error output: %s", errBuf.String()) t.Fatalf("unexpected error output: %s", errBuf.String())
} }
})
} }
} }
...@@ -540,10 +556,13 @@ func TestApplyRetry(t *testing.T) { ...@@ -540,10 +556,13 @@ func TestApplyRetry(t *testing.T) {
pathRC := "/namespaces/test/replicationcontrollers/" + nameRC pathRC := "/namespaces/test/replicationcontrollers/" + nameRC
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply retries on conflict error", func(t *testing.T) {
firstPatch := true firstPatch := true
retry := false retry := false
getCount := 0 getCount := 0
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -592,6 +611,7 @@ func TestApplyRetry(t *testing.T) { ...@@ -592,6 +611,7 @@ func TestApplyRetry(t *testing.T) {
if errBuf.String() != "" { if errBuf.String() != "" {
t.Fatalf("unexpected error output: %s", errBuf.String()) t.Fatalf("unexpected error output: %s", errBuf.String())
} }
})
} }
} }
...@@ -601,6 +621,8 @@ func TestApplyNonExistObject(t *testing.T) { ...@@ -601,6 +621,8 @@ func TestApplyNonExistObject(t *testing.T) {
pathNameRC := pathRC + "/" + nameRC pathNameRC := pathRC + "/" + nameRC
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -645,6 +667,8 @@ func TestApplyEmptyPatch(t *testing.T) { ...@@ -645,6 +667,8 @@ func TestApplyEmptyPatch(t *testing.T) {
var body []byte var body []byte
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: "v1"}, GroupVersion: schema.GroupVersion{Version: "v1"},
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
...@@ -718,7 +742,10 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { ...@@ -718,7 +742,10 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
pathSVC := "/namespaces/test/services/" + nameSVC pathSVC := "/namespaces/test/services/" + nameSVC
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply on multiple objects", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -771,6 +798,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) { ...@@ -771,6 +798,7 @@ func testApplyMultipleObjects(t *testing.T, asList bool) {
if errBuf.String() != "" { if errBuf.String() != "" {
t.Fatalf("unexpected error output: %s", errBuf.String()) t.Fatalf("unexpected error output: %s", errBuf.String())
} }
})
} }
} }
...@@ -801,7 +829,10 @@ func TestApplyNULLPreservation(t *testing.T) { ...@@ -801,7 +829,10 @@ func TestApplyNULLPreservation(t *testing.T) {
deploymentBytes := readDeploymentFromFile(t, filenameDeployObjServerside) deploymentBytes := readDeploymentFromFile(t, filenameDeployObjServerside)
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply preserves NULL fields", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -861,6 +892,7 @@ func TestApplyNULLPreservation(t *testing.T) { ...@@ -861,6 +892,7 @@ func TestApplyNULLPreservation(t *testing.T) {
if !verifiedPatch { if !verifiedPatch {
t.Fatal("No server-side patch call detected") t.Fatal("No server-side patch call detected")
} }
})
} }
} }
...@@ -873,7 +905,10 @@ func TestUnstructuredApply(t *testing.T) { ...@@ -873,7 +905,10 @@ func TestUnstructuredApply(t *testing.T) {
verifiedPatch := false verifiedPatch := false
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply works correctly with unstructured objects", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -923,6 +958,7 @@ func TestUnstructuredApply(t *testing.T) { ...@@ -923,6 +958,7 @@ func TestUnstructuredApply(t *testing.T) {
if !verifiedPatch { if !verifiedPatch {
t.Fatal("No server-side patch call detected") t.Fatal("No server-side patch call detected")
} }
})
} }
} }
...@@ -940,7 +976,10 @@ func TestUnstructuredIdempotentApply(t *testing.T) { ...@@ -940,7 +976,10 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
verifiedPatch := false verifiedPatch := false
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test repeated apply operations on an unstructured object", func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -1013,6 +1052,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) { ...@@ -1013,6 +1052,7 @@ func TestUnstructuredIdempotentApply(t *testing.T) {
if !verifiedPatch { if !verifiedPatch {
t.Fatal("No server-side patch call detected") t.Fatal("No server-side patch call detected")
} }
})
} }
} }
...@@ -1069,6 +1109,8 @@ func TestRunApplySetLastApplied(t *testing.T) { ...@@ -1069,6 +1109,8 @@ func TestRunApplySetLastApplied(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1158,10 +1200,13 @@ func TestForceApply(t *testing.T) { ...@@ -1158,10 +1200,13 @@ func TestForceApply(t *testing.T) {
} }
for _, fn := range testingOpenAPISchemaFns { for _, fn := range testingOpenAPISchemaFns {
t.Run("test apply with --force", func(t *testing.T) {
deleted := false deleted := false
isScaledDownToZero := false isScaledDownToZero := false
counts := map[string]int{} counts := map[string]int{}
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -1257,5 +1302,6 @@ func TestForceApply(t *testing.T) { ...@@ -1257,5 +1302,6 @@ func TestForceApply(t *testing.T) {
if errBuf.String() != "" { if errBuf.String() != "" {
t.Fatalf("unexpected error output: %s", errBuf.String()) t.Fatalf("unexpected error output: %s", errBuf.String())
} }
})
} }
} }
...@@ -139,7 +139,10 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -139,7 +139,10 @@ func TestPodAndContainerAttach(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -168,7 +171,7 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -168,7 +171,7 @@ func TestPodAndContainerAttach(t *testing.T) {
t.Errorf("%s: unexpected error: %v", test.name, err) t.Errorf("%s: unexpected error: %v", test.name, err)
} }
if err != nil { if err != nil {
continue return
} }
if options.PodName != test.expectedPod { if options.PodName != test.expectedPod {
t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedPod, options.PodName) t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedPod, options.PodName)
...@@ -176,6 +179,7 @@ func TestPodAndContainerAttach(t *testing.T) { ...@@ -176,6 +179,7 @@ func TestPodAndContainerAttach(t *testing.T) {
if options.ContainerName != test.expectedContainer { if options.ContainerName != test.expectedContainer {
t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedContainer, options.ContainerName) t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedContainer, options.ContainerName)
} }
})
} }
} }
...@@ -219,7 +223,10 @@ func TestAttach(t *testing.T) { ...@@ -219,7 +223,10 @@ func TestAttach(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -268,18 +275,18 @@ func TestAttach(t *testing.T) { ...@@ -268,18 +275,18 @@ func TestAttach(t *testing.T) {
err := params.Run() err := params.Run()
if test.exepctedErr != "" && err.Error() != test.exepctedErr { if test.exepctedErr != "" && err.Error() != test.exepctedErr {
t.Errorf("%s: Unexpected exec error: %v", test.name, err) t.Errorf("%s: Unexpected exec error: %v", test.name, err)
continue return
} }
if test.exepctedErr == "" && err != nil { if test.exepctedErr == "" && err != nil {
t.Errorf("%s: Unexpected error: %v", test.name, err) t.Errorf("%s: Unexpected error: %v", test.name, err)
continue return
} }
if test.exepctedErr != "" { if test.exepctedErr != "" {
continue return
} }
if remoteAttach.url.Path != test.attachPath { if remoteAttach.url.Path != test.attachPath {
t.Errorf("%s: Did not get expected path for exec request: %q %q", test.name, test.attachPath, remoteAttach.url.Path) t.Errorf("%s: Did not get expected path for exec request: %q %q", test.name, test.attachPath, remoteAttach.url.Path)
continue return
} }
if remoteAttach.method != "POST" { if remoteAttach.method != "POST" {
t.Errorf("%s: Did not get method for attach request: %s", test.name, remoteAttach.method) t.Errorf("%s: Did not get method for attach request: %s", test.name, remoteAttach.method)
...@@ -287,6 +294,7 @@ func TestAttach(t *testing.T) { ...@@ -287,6 +294,7 @@ func TestAttach(t *testing.T) {
if remoteAttach.url.Query().Get("container") != "bar" { if remoteAttach.url.Query().Get("container") != "bar" {
t.Errorf("%s: Did not have query parameters: %s", test.name, remoteAttach.url.Query()) t.Errorf("%s: Did not have query parameters: %s", test.name, remoteAttach.url.Query())
} }
})
} }
} }
...@@ -309,7 +317,10 @@ func TestAttachWarnings(t *testing.T) { ...@@ -309,7 +317,10 @@ func TestAttachWarnings(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -361,10 +372,11 @@ func TestAttachWarnings(t *testing.T) { ...@@ -361,10 +372,11 @@ func TestAttachWarnings(t *testing.T) {
if !test.pod.Spec.Containers[0].TTY { if !test.pod.Spec.Containers[0].TTY {
if !strings.Contains(bufErr.String(), test.expectedErr) { if !strings.Contains(bufErr.String(), test.expectedErr) {
t.Errorf("%s: Expected TTY fallback warning for attach request: %s", test.name, bufErr.String()) t.Errorf("%s: Expected TTY fallback warning for attach request: %s", test.name, bufErr.String())
continue return
} }
} }
} }
})
} }
} }
......
...@@ -117,10 +117,13 @@ func TestRunAccessCheck(t *testing.T) { ...@@ -117,10 +117,13 @@ func TestRunAccessCheck(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
test.o.Out = ioutil.Discard test.o.Out = ioutil.Discard
test.o.Err = ioutil.Discard test.o.Err = ioutil.Discard
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -159,7 +162,7 @@ func TestRunAccessCheck(t *testing.T) { ...@@ -159,7 +162,7 @@ func TestRunAccessCheck(t *testing.T) {
if err := test.o.Complete(tf, test.args); err != nil { if err := test.o.Complete(tf, test.args); err != nil {
t.Errorf("%s: %v", test.name, err) t.Errorf("%s: %v", test.name, err)
continue return
} }
actualAllowed, err := test.o.RunAccessCheck() actualAllowed, err := test.o.RunAccessCheck()
...@@ -170,11 +173,12 @@ func TestRunAccessCheck(t *testing.T) { ...@@ -170,11 +173,12 @@ func TestRunAccessCheck(t *testing.T) {
// pass // pass
default: default:
t.Errorf("%s: expected %v, got %v", test.name, test.serverErr, err) t.Errorf("%s: expected %v, got %v", test.name, test.serverErr, err)
continue return
} }
if actualAllowed != test.allowed { if actualAllowed != test.allowed {
t.Errorf("%s: expected %v, got %v", test.name, test.allowed, actualAllowed) t.Errorf("%s: expected %v, got %v", test.name, test.allowed, actualAllowed)
continue return
} }
})
} }
} }
...@@ -31,6 +31,8 @@ func TestSetupOutputWriterNoOp(t *testing.T) { ...@@ -31,6 +31,8 @@ func TestSetupOutputWriterNoOp(t *testing.T) {
for _, test := range tests { for _, test := range tests {
out := &bytes.Buffer{} out := &bytes.Buffer{}
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
cmd := NewCmdClusterInfoDump(f, os.Stdout) cmd := NewCmdClusterInfoDump(f, os.Stdout)
cmd.Flag("output-directory").Value.Set(test) cmd.Flag("output-directory").Value.Set(test)
writer := setupOutputWriter(cmd, out, "/some/file/that/should/be/ignored") writer := setupOutputWriter(cmd, out, "/some/file/that/should/be/ignored")
...@@ -51,6 +53,8 @@ func TestSetupOutputWriterFile(t *testing.T) { ...@@ -51,6 +53,8 @@ func TestSetupOutputWriterFile(t *testing.T) {
out := &bytes.Buffer{} out := &bytes.Buffer{}
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
cmd := NewCmdClusterInfoDump(f, os.Stdout) cmd := NewCmdClusterInfoDump(f, os.Stdout)
cmd.Flag("output-directory").Value.Set(dir) cmd.Flag("output-directory").Value.Set(dir)
writer := setupOutputWriter(cmd, out, file) writer := setupOutputWriter(cmd, out, file)
......
...@@ -178,6 +178,8 @@ func stringBody(body string) io.ReadCloser { ...@@ -178,6 +178,8 @@ func stringBody(body string) io.ReadCloser {
func Example_printMultiContainersReplicationControllerWithWide() { func Example_printMultiContainersReplicationControllerWithWide() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -228,6 +230,8 @@ func Example_printMultiContainersReplicationControllerWithWide() { ...@@ -228,6 +230,8 @@ func Example_printMultiContainersReplicationControllerWithWide() {
func Example_printReplicationController() { func Example_printReplicationController() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -277,6 +281,8 @@ func Example_printReplicationController() { ...@@ -277,6 +281,8 @@ func Example_printReplicationController() {
func Example_printPodWithWideFormat() { func Example_printPodWithWideFormat() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -315,6 +321,8 @@ func Example_printPodWithWideFormat() { ...@@ -315,6 +321,8 @@ func Example_printPodWithWideFormat() {
func Example_printPodWithShowLabels() { func Example_printPodWithShowLabels() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -448,6 +456,8 @@ func newAllPhasePodList() *api.PodList { ...@@ -448,6 +456,8 @@ func newAllPhasePodList() *api.PodList {
func Example_printPodShowTerminated() { func Example_printPodShowTerminated() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -484,6 +494,8 @@ func Example_printPodShowTerminated() { ...@@ -484,6 +494,8 @@ func Example_printPodShowTerminated() {
func Example_printPodShowAll() { func Example_printPodShowAll() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -507,6 +519,8 @@ func Example_printPodShowAll() { ...@@ -507,6 +519,8 @@ func Example_printPodShowAll() {
func Example_printServiceWithLabels() { func Example_printServiceWithLabels() {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
......
...@@ -102,6 +102,8 @@ func TestConvertObject(t *testing.T) { ...@@ -102,6 +102,8 @@ func TestConvertObject(t *testing.T) {
for _, field := range tc.fields { for _, field := range tc.fields {
t.Run(fmt.Sprintf("%s %s", tc.name, field), func(t *testing.T) { t.Run(fmt.Sprintf("%s %s", tc.name, field), func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req) t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
......
...@@ -33,6 +33,8 @@ func TestCreateClusterRole(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateClusterRole(t *testing.T) {
clusterRoleName := "my-cluster-role" clusterRoleName := "my-cluster-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -148,6 +150,8 @@ func TestCreateClusterRole(t *testing.T) { ...@@ -148,6 +150,8 @@ func TestCreateClusterRole(t *testing.T) {
func TestClusterRoleValidate(t *testing.T) { func TestClusterRoleValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
......
...@@ -68,6 +68,8 @@ func TestCreateClusterRoleBinding(t *testing.T) { ...@@ -68,6 +68,8 @@ func TestCreateClusterRoleBinding(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
......
...@@ -33,6 +33,8 @@ func TestCreateConfigMap(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateConfigMap(t *testing.T) {
configMap := &v1.ConfigMap{} configMap := &v1.ConfigMap{}
configMap.Name = "my-configmap" configMap.Name = "my-configmap"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -75,6 +75,8 @@ func Test_generatorFromName(t *testing.T) { ...@@ -75,6 +75,8 @@ func Test_generatorFromName(t *testing.T) {
func TestCreateDeployment(t *testing.T) { func TestCreateDeployment(t *testing.T) {
depName := "jonny-dep" depName := "jonny-dep"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -104,6 +106,8 @@ func TestCreateDeployment(t *testing.T) { ...@@ -104,6 +106,8 @@ func TestCreateDeployment(t *testing.T) {
func TestCreateDeploymentNoImage(t *testing.T) { func TestCreateDeploymentNoImage(t *testing.T) {
depName := "jonny-dep" depName := "jonny-dep"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
......
...@@ -82,6 +82,8 @@ func TestCreateJobFromCronJob(t *testing.T) { ...@@ -82,6 +82,8 @@ func TestCreateJobFromCronJob(t *testing.T) {
return true, expectJob, nil return true, expectJob, nil
}) })
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmdOptions := &CreateJobOptions{ cmdOptions := &CreateJobOptions{
Name: testJobName, Name: testJobName,
......
...@@ -33,6 +33,8 @@ func TestCreateNamespace(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateNamespace(t *testing.T) {
namespaceObject := &v1.Namespace{} namespaceObject := &v1.Namespace{}
namespaceObject.Name = "my-namespace" namespaceObject.Name = "my-namespace"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -32,6 +32,8 @@ import ( ...@@ -32,6 +32,8 @@ import (
func TestCreatePdb(t *testing.T) { func TestCreatePdb(t *testing.T) {
pdbName := "my-pdb" pdbName := "my-pdb"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
......
...@@ -32,6 +32,8 @@ import ( ...@@ -32,6 +32,8 @@ import (
func TestCreatePriorityClass(t *testing.T) { func TestCreatePriorityClass(t *testing.T) {
pcName := "my-pc" pcName := "my-pc"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
......
...@@ -33,6 +33,8 @@ func TestCreateQuota(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateQuota(t *testing.T) {
resourceQuotaObject := &v1.ResourceQuota{} resourceQuotaObject := &v1.ResourceQuota{}
resourceQuotaObject.Name = "my-quota" resourceQuotaObject.Name = "my-quota"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -35,6 +35,8 @@ func TestCreateRole(t *testing.T) { ...@@ -35,6 +35,8 @@ func TestCreateRole(t *testing.T) {
roleName := "my-role" roleName := "my-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -147,6 +149,8 @@ func TestCreateRole(t *testing.T) { ...@@ -147,6 +149,8 @@ func TestCreateRole(t *testing.T) {
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
...@@ -346,6 +350,8 @@ func TestComplete(t *testing.T) { ...@@ -346,6 +350,8 @@ func TestComplete(t *testing.T) {
roleName := "my-role" roleName := "my-role"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.Client = &fake.RESTClient{} tf.Client = &fake.RESTClient{}
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
......
...@@ -70,6 +70,8 @@ func TestCreateRoleBinding(t *testing.T) { ...@@ -70,6 +70,8 @@ func TestCreateRoleBinding(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
......
...@@ -38,6 +38,8 @@ func TestCreateSecretGeneric(t *testing.T) { ...@@ -38,6 +38,8 @@ func TestCreateSecretGeneric(t *testing.T) {
} }
secretObject.Name = "my-secret" secretObject.Name = "my-secret"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -33,6 +33,8 @@ func TestCreateService(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateService(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-service" service.Name = "my-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
negSer := legacyscheme.Codecs negSer := legacyscheme.Codecs
...@@ -65,6 +67,8 @@ func TestCreateServiceNodePort(t *testing.T) { ...@@ -65,6 +67,8 @@ func TestCreateServiceNodePort(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-node-port-service" service.Name = "my-node-port-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
negSer := legacyscheme.Codecs negSer := legacyscheme.Codecs
...@@ -97,6 +101,8 @@ func TestCreateServiceExternalName(t *testing.T) { ...@@ -97,6 +101,8 @@ func TestCreateServiceExternalName(t *testing.T) {
service := &v1.Service{} service := &v1.Service{}
service.Name = "my-external-name-service" service.Name = "my-external-name-service"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
negSer := legacyscheme.Codecs negSer := legacyscheme.Codecs
......
...@@ -33,6 +33,8 @@ func TestCreateServiceAccount(t *testing.T) { ...@@ -33,6 +33,8 @@ func TestCreateServiceAccount(t *testing.T) {
serviceAccountObject := &v1.ServiceAccount{} serviceAccountObject := &v1.ServiceAccount{}
serviceAccountObject.Name = "my-service-account" serviceAccountObject.Name = "my-service-account"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -34,6 +34,8 @@ func TestExtraArgsFail(t *testing.T) { ...@@ -34,6 +34,8 @@ func TestExtraArgsFail(t *testing.T) {
errBuf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{})
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
c := NewCmdCreate(f, buf, errBuf) c := NewCmdCreate(f, buf, errBuf)
options := CreateOptions{} options := CreateOptions{}
if options.ValidateArgs(c, []string{"rc"}) == nil { if options.ValidateArgs(c, []string{"rc"}) == nil {
...@@ -47,6 +49,8 @@ func TestCreateObject(t *testing.T) { ...@@ -47,6 +49,8 @@ func TestCreateObject(t *testing.T) {
rc.Items[0].Name = "redis-master-controller" rc.Items[0].Name = "redis-master-controller"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -82,6 +86,8 @@ func TestCreateMultipleObject(t *testing.T) { ...@@ -82,6 +86,8 @@ func TestCreateMultipleObject(t *testing.T) {
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -121,6 +127,8 @@ func TestCreateDirectory(t *testing.T) { ...@@ -121,6 +127,8 @@ func TestCreateDirectory(t *testing.T) {
rc.Items[0].Name = "name" rc.Items[0].Name = "name"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
......
...@@ -57,6 +57,8 @@ func TestDeleteObjectByTuple(t *testing.T) { ...@@ -57,6 +57,8 @@ func TestDeleteObjectByTuple(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -121,6 +123,8 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) { ...@@ -121,6 +123,8 @@ func TestOrphanDependentsInDeleteObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
var expectedOrphanDependents *bool var expectedOrphanDependents *bool
...@@ -171,6 +175,8 @@ func TestDeleteNamedObject(t *testing.T) { ...@@ -171,6 +175,8 @@ func TestDeleteNamedObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -222,6 +228,8 @@ func TestDeleteObject(t *testing.T) { ...@@ -222,6 +228,8 @@ func TestDeleteObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -281,6 +289,8 @@ func TestDeleteObjectGraceZero(t *testing.T) { ...@@ -281,6 +289,8 @@ func TestDeleteObjectGraceZero(t *testing.T) {
objectDeletionWaitInterval = time.Millisecond objectDeletionWaitInterval = time.Millisecond
count := 0 count := 0
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -331,6 +341,8 @@ func TestDeleteObjectGraceZero(t *testing.T) { ...@@ -331,6 +341,8 @@ func TestDeleteObjectGraceZero(t *testing.T) {
func TestDeleteObjectNotFound(t *testing.T) { func TestDeleteObjectNotFound(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -367,6 +379,8 @@ func TestDeleteObjectNotFound(t *testing.T) { ...@@ -367,6 +379,8 @@ func TestDeleteObjectNotFound(t *testing.T) {
func TestDeleteObjectIgnoreNotFound(t *testing.T) { func TestDeleteObjectIgnoreNotFound(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -402,6 +416,8 @@ func TestDeleteAllNotFound(t *testing.T) { ...@@ -402,6 +416,8 @@ func TestDeleteAllNotFound(t *testing.T) {
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -447,6 +463,8 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) { ...@@ -447,6 +463,8 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
// Add an item to the list which will result in a 404 on delete // Add an item to the list which will result in a 404 on delete
...@@ -488,6 +506,8 @@ func TestDeleteMultipleObject(t *testing.T) { ...@@ -488,6 +506,8 @@ func TestDeleteMultipleObject(t *testing.T) {
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -524,6 +544,8 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) { ...@@ -524,6 +544,8 @@ func TestDeleteMultipleObjectContinueOnMissing(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -569,6 +591,8 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) { ...@@ -569,6 +591,8 @@ func TestDeleteMultipleResourcesWithTheSameName(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -608,6 +632,8 @@ func TestDeleteDirectory(t *testing.T) { ...@@ -608,6 +632,8 @@ func TestDeleteDirectory(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -641,6 +667,8 @@ func TestDeleteMultipleSelector(t *testing.T) { ...@@ -641,6 +667,8 @@ func TestDeleteMultipleSelector(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -706,7 +734,10 @@ func TestResourceErrors(t *testing.T) { ...@@ -706,7 +734,10 @@ func TestResourceErrors(t *testing.T) {
} }
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -721,11 +752,12 @@ func TestResourceErrors(t *testing.T) { ...@@ -721,11 +752,12 @@ func TestResourceErrors(t *testing.T) {
err := options.Complete(tf, buf, errBuf, testCase.args, fakecmd) err := options.Complete(tf, buf, errBuf, testCase.args, fakecmd)
if !testCase.errFn(err) { if !testCase.errFn(err) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
continue return
} }
if buf.Len() > 0 { if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes())) t.Errorf("buffer should be empty: %s", string(buf.Bytes()))
} }
})
} }
} }
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
func TestDescribeUnknownSchemaObject(t *testing.T) { func TestDescribeUnknownSchemaObject(t *testing.T) {
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
tf.DescriberVal = d tf.DescriberVal = d
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -58,6 +59,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) { ...@@ -58,6 +59,7 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
tf.DescriberVal = d tf.DescriberVal = d
...@@ -83,6 +85,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) { ...@@ -83,6 +85,7 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
func TestDescribeObject(t *testing.T) { func TestDescribeObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
...@@ -118,6 +121,7 @@ func TestDescribeObject(t *testing.T) { ...@@ -118,6 +121,7 @@ func TestDescribeObject(t *testing.T) {
func TestDescribeListObjects(t *testing.T) { func TestDescribeListObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
...@@ -140,6 +144,7 @@ func TestDescribeListObjects(t *testing.T) { ...@@ -140,6 +144,7 @@ func TestDescribeListObjects(t *testing.T) {
func TestDescribeObjectShowEvents(t *testing.T) { func TestDescribeObjectShowEvents(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
...@@ -163,6 +168,7 @@ func TestDescribeObjectShowEvents(t *testing.T) { ...@@ -163,6 +168,7 @@ func TestDescribeObjectShowEvents(t *testing.T) {
func TestDescribeObjectSkipEvents(t *testing.T) { func TestDescribeObjectSkipEvents(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
d := &testDescriber{Output: "test output"} d := &testDescriber{Output: "test output"}
...@@ -185,6 +191,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) { ...@@ -185,6 +191,7 @@ func TestDescribeObjectSkipEvents(t *testing.T) {
func TestDescribeHelpMessage(t *testing.T) { func TestDescribeHelpMessage(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
buferr := bytes.NewBuffer([]byte{}) buferr := bytes.NewBuffer([]byte{})
......
...@@ -150,7 +150,10 @@ func TestCordon(t *testing.T) { ...@@ -150,7 +150,10 @@ func TestCordon(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -230,6 +233,7 @@ func TestCordon(t *testing.T) { ...@@ -230,6 +233,7 @@ func TestCordon(t *testing.T) {
if !reflect.DeepEqual(test.expected.Spec, test.node.Spec) && !updated { if !reflect.DeepEqual(test.expected.Spec, test.node.Spec) && !updated {
t.Fatalf("%s: node never updated", test.description) t.Fatalf("%s: node never updated", test.description)
} }
})
} }
} }
...@@ -597,10 +601,13 @@ func TestDrain(t *testing.T) { ...@@ -597,10 +601,13 @@ func TestDrain(t *testing.T) {
currMethod = DeleteMethod currMethod = DeleteMethod
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
new_node := &corev1.Node{} new_node := &corev1.Node{}
deleted := false deleted := false
evicted := false evicted := false
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -755,6 +762,7 @@ func TestDrain(t *testing.T) { ...@@ -755,6 +762,7 @@ func TestDrain(t *testing.T) {
t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting: %s\n Got: %s", test.description, test.expectWarning, errBuf.String()) t.Fatalf("%s: actual warning message did not match expected warning message.\n Expecting: %s\n Got: %s", test.description, test.expectWarning, errBuf.String())
} }
} }
})
} }
} }
} }
...@@ -824,7 +832,10 @@ func TestDeletePods(t *testing.T) { ...@@ -824,7 +832,10 @@ func TestDeletePods(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
o := DrainOptions{Factory: tf} o := DrainOptions{Factory: tf}
o.mapper, _ = tf.Object() o.mapper, _ = tf.Object()
o.Out = os.Stdout o.Out = os.Stdout
...@@ -849,6 +860,7 @@ func TestDeletePods(t *testing.T) { ...@@ -849,6 +860,7 @@ func TestDeletePods(t *testing.T) {
if !test.expectPendingPods && len(pendingPods) > 0 { if !test.expectPendingPods && len(pendingPods) > 0 {
t.Fatalf("%s: unexpected pending pods", test.description) t.Fatalf("%s: unexpected pending pods", test.description)
} }
})
} }
} }
......
...@@ -207,6 +207,8 @@ func TestEdit(t *testing.T) { ...@@ -207,6 +207,8 @@ func TestEdit(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) { tf.UnstructuredClientForMappingFunc = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
versionedAPIPath := "" versionedAPIPath := ""
if mapping.GroupVersionKind.Group == "" { if mapping.GroupVersionKind.Group == "" {
......
...@@ -130,7 +130,10 @@ func TestPodAndContainer(t *testing.T) { ...@@ -130,7 +130,10 @@ func TestPodAndContainer(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -151,7 +154,7 @@ func TestPodAndContainer(t *testing.T) { ...@@ -151,7 +154,7 @@ func TestPodAndContainer(t *testing.T) {
t.Errorf("%s: unexpected error: %v", test.name, err) t.Errorf("%s: unexpected error: %v", test.name, err)
} }
if err != nil { if err != nil {
continue return
} }
if options.PodName != test.expectedPod { if options.PodName != test.expectedPod {
t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedPod, options.PodName) t.Errorf("%s: expected: %s, got: %s", test.name, test.expectedPod, options.PodName)
...@@ -162,6 +165,7 @@ func TestPodAndContainer(t *testing.T) { ...@@ -162,6 +165,7 @@ func TestPodAndContainer(t *testing.T) {
if !reflect.DeepEqual(test.expectedArgs, options.Command) { if !reflect.DeepEqual(test.expectedArgs, options.Command) {
t.Errorf("%s: expected: %v, got %v", test.name, test.expectedArgs, options.Command) t.Errorf("%s: expected: %v, got %v", test.name, test.expectedArgs, options.Command)
} }
})
} }
} }
...@@ -187,7 +191,10 @@ func TestExec(t *testing.T) { ...@@ -187,7 +191,10 @@ func TestExec(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -232,22 +239,23 @@ func TestExec(t *testing.T) { ...@@ -232,22 +239,23 @@ func TestExec(t *testing.T) {
err := params.Run() err := params.Run()
if test.execErr && err != ex.execErr { if test.execErr && err != ex.execErr {
t.Errorf("%s: Unexpected exec error: %v", test.name, err) t.Errorf("%s: Unexpected exec error: %v", test.name, err)
continue return
} }
if !test.execErr && err != nil { if !test.execErr && err != nil {
t.Errorf("%s: Unexpected error: %v", test.name, err) t.Errorf("%s: Unexpected error: %v", test.name, err)
continue return
} }
if test.execErr { if test.execErr {
continue return
} }
if ex.url.Path != test.execPath { if ex.url.Path != test.execPath {
t.Errorf("%s: Did not get expected path for exec request", test.name) t.Errorf("%s: Did not get expected path for exec request", test.name)
continue return
} }
if ex.method != "POST" { if ex.method != "POST" {
t.Errorf("%s: Did not get method for exec request: %s", test.name, ex.method) t.Errorf("%s: Did not get method for exec request: %s", test.name, ex.method)
} }
})
} }
} }
......
...@@ -466,7 +466,10 @@ func TestRunExposeService(t *testing.T) { ...@@ -466,7 +466,10 @@ func TestRunExposeService(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -503,5 +506,6 @@ func TestRunExposeService(t *testing.T) { ...@@ -503,5 +506,6 @@ func TestRunExposeService(t *testing.T) {
if !strings.Contains(out, test.expected) { if !strings.Contains(out, test.expected) {
t.Errorf("%s: Unexpected output! Expected\n%s\ngot\n%s", test.name, test.expected, out) t.Errorf("%s: Unexpected output! Expected\n%s\ngot\n%s", test.name, test.expected, out)
} }
})
} }
} }
...@@ -321,7 +321,10 @@ func TestLabelErrors(t *testing.T) { ...@@ -321,7 +321,10 @@ func TestLabelErrors(t *testing.T) {
} }
for k, testCase := range testCases { for k, testCase := range testCases {
t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig() tf.ClientConfigVal = defaultClientConfig()
...@@ -342,17 +345,20 @@ func TestLabelErrors(t *testing.T) { ...@@ -342,17 +345,20 @@ func TestLabelErrors(t *testing.T) {
} }
if !testCase.errFn(err) { if !testCase.errFn(err) {
t.Errorf("%s: unexpected error: %v", k, err) t.Errorf("%s: unexpected error: %v", k, err)
continue return
} }
if buf.Len() > 0 { if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes())) t.Errorf("buffer should be empty: %s", string(buf.Bytes()))
} }
})
} }
} }
func TestLabelForResourceFromFile(t *testing.T) { func TestLabelForResourceFromFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -405,6 +411,8 @@ func TestLabelForResourceFromFile(t *testing.T) { ...@@ -405,6 +411,8 @@ func TestLabelForResourceFromFile(t *testing.T) {
func TestLabelLocal(t *testing.T) { func TestLabelLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -438,6 +446,8 @@ func TestLabelLocal(t *testing.T) { ...@@ -438,6 +446,8 @@ func TestLabelLocal(t *testing.T) {
func TestLabelMultipleObjects(t *testing.T) { func TestLabelMultipleObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
......
...@@ -48,8 +48,11 @@ func TestLog(t *testing.T) { ...@@ -48,8 +48,11 @@ func TestLog(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
logContent := "test log content" logContent := "test log content"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -81,6 +84,7 @@ func TestLog(t *testing.T) { ...@@ -81,6 +84,7 @@ func TestLog(t *testing.T) {
if buf.String() != logContent { if buf.String() != logContent {
t.Errorf("%s: did not get expected log content. Got: %s", test.name, buf.String()) t.Errorf("%s: did not get expected log content. Got: %s", test.name, buf.String())
} }
})
} }
} }
...@@ -101,6 +105,7 @@ func testPod() *api.Pod { ...@@ -101,6 +105,7 @@ func testPod() *api.Pod {
func TestValidateLogFlags(t *testing.T) { func TestValidateLogFlags(t *testing.T) {
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
tests := []struct { tests := []struct {
name string name string
...@@ -152,6 +157,7 @@ func TestValidateLogFlags(t *testing.T) { ...@@ -152,6 +157,7 @@ func TestValidateLogFlags(t *testing.T) {
func TestLogComplete(t *testing.T) { func TestLogComplete(t *testing.T) {
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
tests := []struct { tests := []struct {
name string name string
......
...@@ -32,6 +32,8 @@ func TestPatchObject(t *testing.T) { ...@@ -32,6 +32,8 @@ func TestPatchObject(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -72,6 +74,8 @@ func TestPatchObjectFromFile(t *testing.T) { ...@@ -72,6 +74,8 @@ func TestPatchObjectFromFile(t *testing.T) {
_, svc, _ := testData() _, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -108,6 +112,8 @@ func TestPatchNoop(t *testing.T) { ...@@ -108,6 +112,8 @@ func TestPatchNoop(t *testing.T) {
patchObject := &svc.Items[0] patchObject := &svc.Items[0]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -154,6 +160,8 @@ func TestPatchObjectFromFileOutput(t *testing.T) { ...@@ -154,6 +160,8 @@ func TestPatchObjectFromFileOutput(t *testing.T) {
svcCopy.Labels["post-patch"] = "post-patch-value" svcCopy.Labels["post-patch"] = "post-patch-value"
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
......
...@@ -80,6 +80,7 @@ func TestPluginCmd(t *testing.T) { ...@@ -80,6 +80,7 @@ func TestPluginCmd(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
inBuf := bytes.NewBuffer([]byte{}) inBuf := bytes.NewBuffer([]byte{})
outBuf := bytes.NewBuffer([]byte{}) outBuf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{})
...@@ -93,12 +94,14 @@ func TestPluginCmd(t *testing.T) { ...@@ -93,12 +94,14 @@ func TestPluginCmd(t *testing.T) {
} }
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
cmd := NewCmdForPlugin(f, test.plugin, runner, inBuf, outBuf, errBuf) cmd := NewCmdForPlugin(f, test.plugin, runner, inBuf, outBuf, errBuf)
if cmd == nil { if cmd == nil {
if !test.expectedNilCmd { if !test.expectedNilCmd {
t.Fatalf("%s: command was unexpectedly not registered", test.name) t.Fatalf("%s: command was unexpectedly not registered", test.name)
} }
continue return
} }
cmd.Run(cmd, []string{}) cmd.Run(cmd, []string{})
...@@ -109,5 +112,6 @@ func TestPluginCmd(t *testing.T) { ...@@ -109,5 +112,6 @@ func TestPluginCmd(t *testing.T) {
if !test.expectedSuccess && errBuf.String() != fmt.Sprintf("error: oops %s", test.plugin.Name) { if !test.expectedSuccess && errBuf.String() != fmt.Sprintf("error: oops %s", test.plugin.Name) {
t.Errorf("%s: unexpected err output: %q", test.name, errBuf.String()) t.Errorf("%s: unexpected err output: %q", test.name, errBuf.String())
} }
})
} }
} }
...@@ -71,8 +71,11 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { ...@@ -71,8 +71,11 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var err error var err error
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -124,15 +127,16 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) { ...@@ -124,15 +127,16 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
t.Errorf("%s: Unexpected error: %v", test.name, err) t.Errorf("%s: Unexpected error: %v", test.name, err)
} }
if test.pfErr { if test.pfErr {
continue return
} }
if ff.url.Path != test.pfPath { if ff.url == nil || ff.url.Path != test.pfPath {
t.Errorf("%s: Did not get expected path for portforward request", test.name) t.Errorf("%s: Did not get expected path for portforward request", test.name)
} }
if ff.method != "POST" { if ff.method != "POST" {
t.Errorf("%s: Did not get method for attach request: %s", test.name, ff.method) t.Errorf("%s: Did not get method for attach request: %s", test.name, ff.method)
} }
})
} }
} }
......
...@@ -33,6 +33,7 @@ func TestReplaceObject(t *testing.T) { ...@@ -33,6 +33,7 @@ func TestReplaceObject(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
deleted := false deleted := false
...@@ -89,6 +90,7 @@ func TestReplaceMultipleObject(t *testing.T) { ...@@ -89,6 +90,7 @@ func TestReplaceMultipleObject(t *testing.T) {
_, svc, rc := testData() _, svc, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
redisMasterDeleted := false redisMasterDeleted := false
...@@ -159,6 +161,7 @@ func TestReplaceDirectory(t *testing.T) { ...@@ -159,6 +161,7 @@ func TestReplaceDirectory(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
created := map[string]bool{} created := map[string]bool{}
...@@ -216,6 +219,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) { ...@@ -216,6 +219,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
_, _, rc := testData() _, _, rc := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
......
...@@ -198,6 +198,7 @@ func testComponentStatusData() *api.ComponentStatusList { ...@@ -198,6 +198,7 @@ func testComponentStatusData() *api.ComponentStatusList {
func TestGetUnknownSchemaObject(t *testing.T) { func TestGetUnknownSchemaObject(t *testing.T) {
t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!") t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!")
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath) tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath)
...@@ -272,6 +273,7 @@ func TestGetUnknownSchemaObject(t *testing.T) { ...@@ -272,6 +273,7 @@ func TestGetUnknownSchemaObject(t *testing.T) {
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get. // Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func TestGetSchemaObject(t *testing.T) { func TestGetSchemaObject(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := testapi.Default.Codec() codec := testapi.Default.Codec()
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
NegotiatedSerializer: unstructuredSerializer, NegotiatedSerializer: unstructuredSerializer,
...@@ -294,6 +296,7 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) { ...@@ -294,6 +296,7 @@ func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
// overide the openAPISchema function to return custom output // overide the openAPISchema function to return custom output
...@@ -351,6 +354,7 @@ func TestGetObjects(t *testing.T) { ...@@ -351,6 +354,7 @@ func TestGetObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -417,6 +421,8 @@ func TestGetObjectsFiltered(t *testing.T) { ...@@ -417,6 +421,8 @@ func TestGetObjectsFiltered(t *testing.T) {
for i, test := range testCases { for i, test := range testCases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -458,6 +464,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) { ...@@ -458,6 +464,7 @@ func TestGetObjectIgnoreNotFound(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -511,6 +518,7 @@ func TestGetSortedObjects(t *testing.T) { ...@@ -511,6 +518,7 @@ func TestGetSortedObjects(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -544,6 +552,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) { ...@@ -544,6 +552,7 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -571,6 +580,7 @@ func TestGetListObjects(t *testing.T) { ...@@ -571,6 +580,7 @@ func TestGetListObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -598,6 +608,7 @@ func TestGetAllListObjects(t *testing.T) { ...@@ -598,6 +608,7 @@ func TestGetAllListObjects(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -626,6 +637,7 @@ func TestGetListComponentStatus(t *testing.T) { ...@@ -626,6 +637,7 @@ func TestGetListComponentStatus(t *testing.T) {
statuses := testComponentStatusData() statuses := testComponentStatusData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -667,6 +679,7 @@ func TestGetMixedGenericObjects(t *testing.T) { ...@@ -667,6 +679,7 @@ func TestGetMixedGenericObjects(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -717,6 +730,7 @@ func TestGetMultipleTypeObjects(t *testing.T) { ...@@ -717,6 +730,7 @@ func TestGetMultipleTypeObjects(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -756,6 +770,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { ...@@ -756,6 +770,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -858,6 +873,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { ...@@ -858,6 +873,7 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -902,6 +918,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { ...@@ -902,6 +918,7 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) {
pods, svc, _ := testData() pods, svc, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -954,6 +971,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { ...@@ -954,6 +971,7 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -993,6 +1011,7 @@ func TestGetByFormatForcesFlag(t *testing.T) { ...@@ -993,6 +1011,7 @@ func TestGetByFormatForcesFlag(t *testing.T) {
pods, _, _ := testData() pods, _, _ := testData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1089,6 +1108,7 @@ func TestWatchLabelSelector(t *testing.T) { ...@@ -1089,6 +1108,7 @@ func TestWatchLabelSelector(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
podList := &api.PodList{ podList := &api.PodList{
...@@ -1141,6 +1161,7 @@ func TestWatchFieldSelector(t *testing.T) { ...@@ -1141,6 +1161,7 @@ func TestWatchFieldSelector(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
podList := &api.PodList{ podList := &api.PodList{
...@@ -1193,6 +1214,7 @@ func TestWatchResource(t *testing.T) { ...@@ -1193,6 +1214,7 @@ func TestWatchResource(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1237,6 +1259,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) { ...@@ -1237,6 +1259,7 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1282,6 +1305,7 @@ func TestWatchOnlyResource(t *testing.T) { ...@@ -1282,6 +1305,7 @@ func TestWatchOnlyResource(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{ tf.UnstructuredClient = &fake.RESTClient{
...@@ -1325,6 +1349,7 @@ func TestWatchOnlyList(t *testing.T) { ...@@ -1325,6 +1349,7 @@ func TestWatchOnlyList(t *testing.T) {
pods, events := watchTestData() pods, events := watchTestData()
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
podList := &api.PodList{ podList := &api.PodList{
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
func TestValidateArgs(t *testing.T) { func TestValidateArgs(t *testing.T) {
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
tests := []struct { tests := []struct {
testName string testName string
......
...@@ -168,7 +168,10 @@ func TestRunArgsFollowDashRules(t *testing.T) { ...@@ -168,7 +168,10 @@ func TestRunArgsFollowDashRules(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -197,6 +200,7 @@ func TestRunArgsFollowDashRules(t *testing.T) { ...@@ -197,6 +200,7 @@ func TestRunArgsFollowDashRules(t *testing.T) {
if !test.expectError && err != nil { if !test.expectError && err != nil {
t.Errorf("unexpected error: %v (%s)", err, test.name) t.Errorf("unexpected error: %v (%s)", err, test.name)
} }
})
} }
} }
...@@ -292,8 +296,11 @@ func TestGenerateService(t *testing.T) { ...@@ -292,8 +296,11 @@ func TestGenerateService(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
sawPOST := false sawPOST := false
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -351,7 +358,7 @@ func TestGenerateService(t *testing.T) { ...@@ -351,7 +358,7 @@ func TestGenerateService(t *testing.T) {
if err == nil { if err == nil {
t.Error("unexpected non-error") t.Error("unexpected non-error")
} }
continue return
} }
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
...@@ -359,23 +366,28 @@ func TestGenerateService(t *testing.T) { ...@@ -359,23 +366,28 @@ func TestGenerateService(t *testing.T) {
if test.expectPOST != sawPOST { if test.expectPOST != sawPOST {
t.Errorf("expectPost: %v, sawPost: %v", test.expectPOST, sawPOST) t.Errorf("expectPost: %v, sawPost: %v", test.expectPOST, sawPOST)
} }
})
} }
} }
func TestRunValidations(t *testing.T) { func TestRunValidations(t *testing.T) {
tests := []struct { tests := []struct {
name string
args []string args []string
flags map[string]string flags map[string]string
expectedErr string expectedErr string
}{ }{
{ {
name: "test missing name error",
expectedErr: "NAME is required", expectedErr: "NAME is required",
}, },
{ {
name: "test missing --image error",
args: []string{"test"}, args: []string{"test"},
expectedErr: "--image is required", expectedErr: "--image is required",
}, },
{ {
name: "test invalid image name error",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "#", "image": "#",
...@@ -383,6 +395,7 @@ func TestRunValidations(t *testing.T) { ...@@ -383,6 +395,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "Invalid image name", expectedErr: "Invalid image name",
}, },
{ {
name: "test stdin replicas value",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -392,6 +405,7 @@ func TestRunValidations(t *testing.T) { ...@@ -392,6 +405,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "stdin requires that replicas is 1", expectedErr: "stdin requires that replicas is 1",
}, },
{ {
name: "test rm errors when used on non-attached containers",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -400,6 +414,7 @@ func TestRunValidations(t *testing.T) { ...@@ -400,6 +414,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "rm should only be used for attached containers", expectedErr: "rm should only be used for attached containers",
}, },
{ {
name: "test error on attached containers options",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -409,6 +424,7 @@ func TestRunValidations(t *testing.T) { ...@@ -409,6 +424,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "can't be used with attached containers options", expectedErr: "can't be used with attached containers options",
}, },
{ {
name: "test error on attached containers options, with value from stdin",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -418,6 +434,7 @@ func TestRunValidations(t *testing.T) { ...@@ -418,6 +434,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "can't be used with attached containers options", expectedErr: "can't be used with attached containers options",
}, },
{ {
name: "test error on attached containers options, with value from stdin and tty",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -428,6 +445,7 @@ func TestRunValidations(t *testing.T) { ...@@ -428,6 +445,7 @@ func TestRunValidations(t *testing.T) {
expectedErr: "can't be used with attached containers options", expectedErr: "can't be used with attached containers options",
}, },
{ {
name: "test error when tty=true and no stdin provided",
args: []string{"test"}, args: []string{"test"},
flags: map[string]string{ flags: map[string]string{
"image": "busybox", "image": "busybox",
...@@ -437,7 +455,10 @@ func TestRunValidations(t *testing.T) { ...@@ -437,7 +455,10 @@ func TestRunValidations(t *testing.T) {
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
_, _, codec := cmdtesting.NewExternalScheme() _, _, codec := cmdtesting.NewExternalScheme()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
NegotiatedSerializer: scheme.Codecs, NegotiatedSerializer: scheme.Codecs,
...@@ -459,6 +480,7 @@ func TestRunValidations(t *testing.T) { ...@@ -459,6 +480,7 @@ func TestRunValidations(t *testing.T) {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
} }
})
} }
} }
...@@ -47,6 +47,8 @@ import ( ...@@ -47,6 +47,8 @@ import (
func TestSetEnvLocal(t *testing.T) { func TestSetEnvLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""}, GroupVersion: schema.GroupVersion{Version: ""},
...@@ -83,6 +85,8 @@ func TestSetEnvLocal(t *testing.T) { ...@@ -83,6 +85,8 @@ func TestSetEnvLocal(t *testing.T) {
func TestSetMultiResourcesEnvLocal(t *testing.T) { func TestSetMultiResourcesEnvLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -122,12 +126,14 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) { ...@@ -122,12 +126,14 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
func TestSetEnvRemote(t *testing.T) { func TestSetEnvRemote(t *testing.T) {
inputs := []struct { inputs := []struct {
name string
object runtime.Object object runtime.Object
apiPrefix, apiGroup, apiVersion string apiPrefix, apiGroup, apiVersion string
testAPIGroup string testAPIGroup string
args []string args []string
}{ }{
{ {
name: "test extensions.v1beta1 replicaset",
object: &extensionsv1beta1.ReplicaSet{ object: &extensionsv1beta1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.ReplicaSetSpec{ Spec: extensionsv1beta1.ReplicaSetSpec{
...@@ -148,6 +154,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -148,6 +154,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "env=prod"}, args: []string{"replicaset", "nginx", "env=prod"},
}, },
{ {
name: "test apps.v1beta2 replicaset",
object: &appsv1beta2.ReplicaSet{ object: &appsv1beta2.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.ReplicaSetSpec{ Spec: appsv1beta2.ReplicaSetSpec{
...@@ -168,6 +175,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -168,6 +175,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "env=prod"}, args: []string{"replicaset", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1 replicaset",
object: &appsv1.ReplicaSet{ object: &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.ReplicaSetSpec{ Spec: appsv1.ReplicaSetSpec{
...@@ -188,6 +196,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -188,6 +196,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "env=prod"}, args: []string{"replicaset", "nginx", "env=prod"},
}, },
{ {
name: "test extensions.v1beta1 daemonset",
object: &extensionsv1beta1.DaemonSet{ object: &extensionsv1beta1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.DaemonSetSpec{ Spec: extensionsv1beta1.DaemonSetSpec{
...@@ -208,6 +217,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -208,6 +217,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "env=prod"}, args: []string{"daemonset", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1beta2 daemonset",
object: &appsv1beta2.DaemonSet{ object: &appsv1beta2.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.DaemonSetSpec{ Spec: appsv1beta2.DaemonSetSpec{
...@@ -228,6 +238,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -228,6 +238,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "env=prod"}, args: []string{"daemonset", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1 daemonset",
object: &appsv1.DaemonSet{ object: &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.DaemonSetSpec{ Spec: appsv1.DaemonSetSpec{
...@@ -248,6 +259,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -248,6 +259,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "env=prod"}, args: []string{"daemonset", "nginx", "env=prod"},
}, },
{ {
name: "test extensions.v1beta1 deployment",
object: &extensionsv1beta1.Deployment{ object: &extensionsv1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.DeploymentSpec{ Spec: extensionsv1beta1.DeploymentSpec{
...@@ -268,6 +280,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -268,6 +280,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"deployment", "nginx", "env=prod"}, args: []string{"deployment", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1bta1 deployment",
object: &appsv1beta1.Deployment{ object: &appsv1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta1.DeploymentSpec{ Spec: appsv1beta1.DeploymentSpec{
...@@ -288,6 +301,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -288,6 +301,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"deployment", "nginx", "env=prod"}, args: []string{"deployment", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1beta2n deployment",
object: &appsv1beta2.Deployment{ object: &appsv1beta2.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.DeploymentSpec{ Spec: appsv1beta2.DeploymentSpec{
...@@ -308,6 +322,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -308,6 +322,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"deployment", "nginx", "env=prod"}, args: []string{"deployment", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1 deployment",
object: &appsv1.Deployment{ object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.DeploymentSpec{ Spec: appsv1.DeploymentSpec{
...@@ -328,6 +343,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -328,6 +343,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"deployment", "nginx", "env=prod"}, args: []string{"deployment", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1beta1 statefulset",
object: &appsv1beta1.StatefulSet{ object: &appsv1beta1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta1.StatefulSetSpec{ Spec: appsv1beta1.StatefulSetSpec{
...@@ -348,6 +364,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -348,6 +364,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"statefulset", "nginx", "env=prod"}, args: []string{"statefulset", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1beta2 statefulset",
object: &appsv1beta2.StatefulSet{ object: &appsv1beta2.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.StatefulSetSpec{ Spec: appsv1beta2.StatefulSetSpec{
...@@ -368,6 +385,7 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -368,6 +385,7 @@ func TestSetEnvRemote(t *testing.T) {
args: []string{"statefulset", "nginx", "env=prod"}, args: []string{"statefulset", "nginx", "env=prod"},
}, },
{ {
name: "test appsv1 statefulset",
object: &appsv1.StatefulSet{ object: &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.StatefulSetSpec{ Spec: appsv1.StatefulSetSpec{
...@@ -429,9 +447,12 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -429,9 +447,12 @@ func TestSetEnvRemote(t *testing.T) {
}, },
} }
for _, input := range inputs { for _, input := range inputs {
t.Run(input.name, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Namespace = "test" tf.Namespace = "test"
...@@ -472,5 +493,6 @@ func TestSetEnvRemote(t *testing.T) { ...@@ -472,5 +493,6 @@ func TestSetEnvRemote(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = opts.RunEnv(tf) err = opts.RunEnv(tf)
assert.NoError(t, err) assert.NoError(t, err)
})
} }
} }
...@@ -46,6 +46,8 @@ import ( ...@@ -46,6 +46,8 @@ import (
func TestImageLocal(t *testing.T) { func TestImageLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -149,6 +151,8 @@ func TestSetImageValidation(t *testing.T) { ...@@ -149,6 +151,8 @@ func TestSetImageValidation(t *testing.T) {
func TestSetMultiResourcesImageLocal(t *testing.T) { func TestSetMultiResourcesImageLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -190,12 +194,14 @@ func TestSetMultiResourcesImageLocal(t *testing.T) { ...@@ -190,12 +194,14 @@ func TestSetMultiResourcesImageLocal(t *testing.T) {
func TestSetImageRemote(t *testing.T) { func TestSetImageRemote(t *testing.T) {
inputs := []struct { inputs := []struct {
name string
object runtime.Object object runtime.Object
apiPrefix, apiGroup, apiVersion string apiPrefix, apiGroup, apiVersion string
testAPIGroup string testAPIGroup string
args []string args []string
}{ }{
{ {
name: "set image extensionsv1beta1 ReplicaSet",
object: &extensionsv1beta1.ReplicaSet{ object: &extensionsv1beta1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.ReplicaSetSpec{ Spec: extensionsv1beta1.ReplicaSetSpec{
...@@ -216,6 +222,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -216,6 +222,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "*=thingy"}, args: []string{"replicaset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta2 ReplicaSet",
object: &appsv1beta2.ReplicaSet{ object: &appsv1beta2.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.ReplicaSetSpec{ Spec: appsv1beta2.ReplicaSetSpec{
...@@ -236,6 +243,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -236,6 +243,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "*=thingy"}, args: []string{"replicaset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1 ReplicaSet",
object: &appsv1.ReplicaSet{ object: &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.ReplicaSetSpec{ Spec: appsv1.ReplicaSetSpec{
...@@ -256,6 +264,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -256,6 +264,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"replicaset", "nginx", "*=thingy"}, args: []string{"replicaset", "nginx", "*=thingy"},
}, },
{ {
name: "set image extensionsv1beta1 DaemonSet",
object: &extensionsv1beta1.DaemonSet{ object: &extensionsv1beta1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.DaemonSetSpec{ Spec: extensionsv1beta1.DaemonSetSpec{
...@@ -276,6 +285,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -276,6 +285,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "*=thingy"}, args: []string{"daemonset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta2 DaemonSet",
object: &appsv1beta2.DaemonSet{ object: &appsv1beta2.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.DaemonSetSpec{ Spec: appsv1beta2.DaemonSetSpec{
...@@ -296,6 +306,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -296,6 +306,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "*=thingy"}, args: []string{"daemonset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1 DaemonSet",
object: &appsv1.DaemonSet{ object: &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.DaemonSetSpec{ Spec: appsv1.DaemonSetSpec{
...@@ -316,6 +327,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -316,6 +327,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"daemonset", "nginx", "*=thingy"}, args: []string{"daemonset", "nginx", "*=thingy"},
}, },
{ {
name: "set image extensionsv1beta1 Deployment",
object: &extensionsv1beta1.Deployment{ object: &extensionsv1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: extensionsv1beta1.DeploymentSpec{ Spec: extensionsv1beta1.DeploymentSpec{
...@@ -336,6 +348,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -336,6 +348,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"deployment", "nginx", "*=thingy"}, args: []string{"deployment", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta1 Deployment",
object: &appsv1beta1.Deployment{ object: &appsv1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta1.DeploymentSpec{ Spec: appsv1beta1.DeploymentSpec{
...@@ -356,6 +369,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -356,6 +369,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"deployment", "nginx", "*=thingy"}, args: []string{"deployment", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta2 Deployment",
object: &appsv1beta2.Deployment{ object: &appsv1beta2.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.DeploymentSpec{ Spec: appsv1beta2.DeploymentSpec{
...@@ -376,6 +390,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -376,6 +390,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"deployment", "nginx", "*=thingy"}, args: []string{"deployment", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1 Deployment",
object: &appsv1.Deployment{ object: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.DeploymentSpec{ Spec: appsv1.DeploymentSpec{
...@@ -396,6 +411,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -396,6 +411,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"deployment", "nginx", "*=thingy"}, args: []string{"deployment", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta1 StatefulSet",
object: &appsv1beta1.StatefulSet{ object: &appsv1beta1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta1.StatefulSetSpec{ Spec: appsv1beta1.StatefulSetSpec{
...@@ -416,6 +432,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -416,6 +432,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"statefulset", "nginx", "*=thingy"}, args: []string{"statefulset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1beta2 StatefulSet",
object: &appsv1beta2.StatefulSet{ object: &appsv1beta2.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1beta2.StatefulSetSpec{ Spec: appsv1beta2.StatefulSetSpec{
...@@ -436,6 +453,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -436,6 +453,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"statefulset", "nginx", "*=thingy"}, args: []string{"statefulset", "nginx", "*=thingy"},
}, },
{ {
name: "set image appsv1 StatefulSet",
object: &appsv1.StatefulSet{ object: &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: appsv1.StatefulSetSpec{ Spec: appsv1.StatefulSetSpec{
...@@ -456,6 +474,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -456,6 +474,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"statefulset", "nginx", "*=thingy"}, args: []string{"statefulset", "nginx", "*=thingy"},
}, },
{ {
name: "set image batchv1 Job",
object: &batchv1.Job{ object: &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: batchv1.JobSpec{ Spec: batchv1.JobSpec{
...@@ -476,6 +495,7 @@ func TestSetImageRemote(t *testing.T) { ...@@ -476,6 +495,7 @@ func TestSetImageRemote(t *testing.T) {
args: []string{"job", "nginx", "*=thingy"}, args: []string{"job", "nginx", "*=thingy"},
}, },
{ {
name: "set image v1.ReplicationController",
object: &v1.ReplicationController{ object: &v1.ReplicationController{
ObjectMeta: metav1.ObjectMeta{Name: "nginx"}, ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
Spec: v1.ReplicationControllerSpec{ Spec: v1.ReplicationControllerSpec{
...@@ -497,9 +517,12 @@ func TestSetImageRemote(t *testing.T) { ...@@ -497,9 +517,12 @@ func TestSetImageRemote(t *testing.T) {
}, },
} }
for _, input := range inputs { for _, input := range inputs {
t.Run(input.name, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Namespace = "test" tf.Namespace = "test"
...@@ -540,5 +563,6 @@ func TestSetImageRemote(t *testing.T) { ...@@ -540,5 +563,6 @@ func TestSetImageRemote(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = opts.Run() err = opts.Run()
assert.NoError(t, err) assert.NoError(t, err)
})
} }
} }
...@@ -46,6 +46,7 @@ import ( ...@@ -46,6 +46,7 @@ import (
func TestResourcesLocal(t *testing.T) { func TestResourcesLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -90,6 +91,7 @@ func TestResourcesLocal(t *testing.T) { ...@@ -90,6 +91,7 @@ func TestResourcesLocal(t *testing.T) {
func TestSetMultiResourcesLimitsLocal(t *testing.T) { func TestSetMultiResourcesLimitsLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -446,6 +448,7 @@ func TestSetResourcesRemote(t *testing.T) { ...@@ -446,6 +448,7 @@ func TestSetResourcesRemote(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Namespace = "test" tf.Namespace = "test"
......
...@@ -317,6 +317,8 @@ func TestGetResourcesAndSelector(t *testing.T) { ...@@ -317,6 +317,8 @@ func TestGetResourcesAndSelector(t *testing.T) {
func TestSelectorTest(t *testing.T) { func TestSelectorTest(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""}, GroupVersion: schema.GroupVersion{Version: ""},
......
...@@ -68,6 +68,8 @@ func TestSetServiceAccountLocal(t *testing.T) { ...@@ -68,6 +68,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
for i, input := range inputs { for i, input := range inputs {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: "v1"}, GroupVersion: schema.GroupVersion{Version: "v1"},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -98,6 +100,8 @@ func TestSetServiceAccountLocal(t *testing.T) { ...@@ -98,6 +100,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
func TestSetServiceAccountMultiLocal(t *testing.T) { func TestSetServiceAccountMultiLocal(t *testing.T) {
testapi.Default = testapi.Groups[""] testapi.Default = testapi.Groups[""]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: ""}, GroupVersion: schema.GroupVersion{Version: ""},
...@@ -310,9 +314,12 @@ func TestSetServiceAccountRemote(t *testing.T) { ...@@ -310,9 +314,12 @@ func TestSetServiceAccountRemote(t *testing.T) {
}, },
} }
for _, input := range inputs { for _, input := range inputs {
t.Run(input.apiPrefix, func(t *testing.T) {
groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion} groupVersion := schema.GroupVersion{Group: input.apiGroup, Version: input.apiVersion}
testapi.Default = testapi.Groups[input.testAPIGroup] testapi.Default = testapi.Groups[input.testAPIGroup]
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion) codec := scheme.Codecs.CodecForVersions(scheme.Codecs.LegacyCodec(groupVersion), scheme.Codecs.UniversalDecoder(groupVersion), groupVersion, groupVersion)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Namespace = "test" tf.Namespace = "test"
...@@ -353,19 +360,24 @@ func TestSetServiceAccountRemote(t *testing.T) { ...@@ -353,19 +360,24 @@ func TestSetServiceAccountRemote(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = saConfig.Run() err = saConfig.Run()
assert.NoError(t, err) assert.NoError(t, err)
})
} }
} }
func TestServiceAccountValidation(t *testing.T) { func TestServiceAccountValidation(t *testing.T) {
inputs := []struct { inputs := []struct {
name string
args []string args []string
errorString string errorString string
}{ }{
{args: []string{}, errorString: serviceAccountMissingErrString}, {name: "test service account missing", args: []string{}, errorString: serviceAccountMissingErrString},
{args: []string{serviceAccount}, errorString: resourceMissingErrString}, {name: "test service account resource missing", args: []string{serviceAccount}, errorString: resourceMissingErrString},
} }
for _, input := range inputs { for _, input := range inputs {
t.Run(input.name, func(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Version: "v1"}, GroupVersion: schema.GroupVersion{Version: "v1"},
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
...@@ -381,6 +393,7 @@ func TestServiceAccountValidation(t *testing.T) { ...@@ -381,6 +393,7 @@ func TestServiceAccountValidation(t *testing.T) {
saConfig := &serviceAccountConfig{} saConfig := &serviceAccountConfig{}
err := saConfig.Complete(tf, cmd, input.args) err := saConfig.Complete(tf, cmd, input.args)
assert.EqualError(t, err, input.errorString) assert.EqualError(t, err, input.errorString)
})
} }
} }
......
...@@ -29,6 +29,8 @@ import ( ...@@ -29,6 +29,8 @@ import (
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
tf.Namespace = "test" tf.Namespace = "test"
tests := map[string]struct { tests := map[string]struct {
......
...@@ -236,10 +236,13 @@ func TestTaint(t *testing.T) { ...@@ -236,10 +236,13 @@ func TestTaint(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
oldNode, expectNewNode := generateNodeAndTaintedNode(test.oldTaints, test.newTaints) oldNode, expectNewNode := generateNodeAndTaintedNode(test.oldTaints, test.newTaints)
new_node := &v1.Node{} new_node := &v1.Node{}
tainted := false tainted := false
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -332,6 +335,7 @@ func TestTaint(t *testing.T) { ...@@ -332,6 +335,7 @@ func TestTaint(t *testing.T) {
t.Fatalf("%s: unexpected taint", test.description) t.Fatalf("%s: unexpected taint", test.description)
} }
} }
})
} }
} }
......
...@@ -37,6 +37,8 @@ go_library( ...@@ -37,6 +37,8 @@ go_library(
"//vendor/k8s.io/client-go/kubernetes:go_default_library", "//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/rest/fake:go_default_library", "//vendor/k8s.io/client-go/rest/fake:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
], ],
) )
......
...@@ -17,8 +17,11 @@ limitations under the License. ...@@ -17,8 +17,11 @@ limitations under the License.
package testing package testing
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath" "path/filepath"
"time" "time"
...@@ -34,6 +37,8 @@ import ( ...@@ -34,6 +37,8 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/api/legacyscheme"
api "k8s.io/kubernetes/pkg/apis/core" api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
...@@ -240,14 +245,53 @@ type TestFactory struct { ...@@ -240,14 +245,53 @@ type TestFactory struct {
ClientConfigVal *restclient.Config ClientConfigVal *restclient.Config
CommandVal string CommandVal string
tempConfigFile *os.File
UnstructuredClientForMappingFunc func(mapping *meta.RESTMapping) (resource.RESTClient, error) UnstructuredClientForMappingFunc func(mapping *meta.RESTMapping) (resource.RESTClient, error)
OpenAPISchemaFunc func() (openapi.Resources, error) OpenAPISchemaFunc func() (openapi.Resources, error)
} }
func NewTestFactory() *TestFactory { func NewTestFactory() *TestFactory {
// specify an optionalClientConfig to explicitly use in testing
// to avoid polluting an existing user config.
config, configFile := defaultFakeClientConfig()
return &TestFactory{ return &TestFactory{
Factory: cmdutil.NewFactory(nil), Factory: cmdutil.NewFactory(config),
tempConfigFile: configFile,
}
}
func (f *TestFactory) Cleanup() {
if f.tempConfigFile == nil {
return
}
os.Remove(f.tempConfigFile.Name())
}
func defaultFakeClientConfig() (clientcmd.ClientConfig, *os.File) {
loadingRules, tmpFile, err := newDefaultFakeClientConfigLoadingRules()
if err != nil {
panic(fmt.Sprintf("unable to create a fake client config: %v", err))
}
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmdapi.Cluster{Server: "http://localhost:8080"}}
fallbackReader := bytes.NewBuffer([]byte{})
clientConfig := clientcmd.NewInteractiveDeferredLoadingClientConfig(loadingRules, overrides, fallbackReader)
return clientConfig, tmpFile
}
func newDefaultFakeClientConfigLoadingRules() (*clientcmd.ClientConfigLoadingRules, *os.File, error) {
tmpFile, err := ioutil.TempFile("", "cmdtests_temp")
if err != nil {
return nil, nil, err
} }
return &clientcmd.ClientConfigLoadingRules{
Precedence: []string{tmpFile.Name()},
MigrationRules: map[string]string{},
}, tmpFile, nil
} }
func (f *TestFactory) CategoryExpander() categories.CategoryExpander { func (f *TestFactory) CategoryExpander() categories.CategoryExpander {
......
...@@ -50,6 +50,8 @@ func TestTopNodeAllMetrics(t *testing.T) { ...@@ -50,6 +50,8 @@ func TestTopNodeAllMetrics(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -101,6 +103,8 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) { ...@@ -101,6 +103,8 @@ func TestTopNodeAllMetricsCustomDefaults(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -162,6 +166,8 @@ func TestTopNodeWithNameMetrics(t *testing.T) { ...@@ -162,6 +166,8 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -227,6 +233,8 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) { ...@@ -227,6 +233,8 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -280,6 +288,8 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) { ...@@ -280,6 +288,8 @@ func TestTopNodeAllMetricsFromMetricsServer(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -344,6 +354,8 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) { ...@@ -344,6 +354,8 @@ func TestTopNodeWithNameMetricsFromMetricsServer(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name) expectedNodePath := fmt.Sprintf("/%s/%s/nodes/%s", apiPrefix, apiVersion, expectedMetrics.Name)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
...@@ -418,6 +430,8 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) { ...@@ -418,6 +430,8 @@ func TestTopNodeWithLabelSelectorMetricsFromMetricsServer(t *testing.T) {
expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion) expectedNodePath := fmt.Sprintf("/%s/%s/nodes", apiPrefix, apiVersion)
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
......
...@@ -134,6 +134,7 @@ func TestTopPod(t *testing.T) { ...@@ -134,6 +134,7 @@ func TestTopPod(t *testing.T) {
} }
initTestErrorHandler(t) initTestErrorHandler(t)
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
t.Logf("Running test case: %s", testCase.name) t.Logf("Running test case: %s", testCase.name)
metricsList := testPodMetricsData() metricsList := testPodMetricsData()
var expectedMetrics []metricsv1alpha1api.PodMetrics var expectedMetrics []metricsv1alpha1api.PodMetrics
...@@ -163,6 +164,8 @@ func TestTopPod(t *testing.T) { ...@@ -163,6 +164,8 @@ func TestTopPod(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -218,6 +221,7 @@ func TestTopPod(t *testing.T) { ...@@ -218,6 +221,7 @@ func TestTopPod(t *testing.T) {
t.Errorf("%s: unexpected metrics for %s: \n%s", testCase.name, name, result) t.Errorf("%s: unexpected metrics for %s: \n%s", testCase.name, name, result)
} }
} }
})
} }
} }
...@@ -305,6 +309,8 @@ func TestTopPodWithMetricsServer(t *testing.T) { ...@@ -305,6 +309,8 @@ func TestTopPodWithMetricsServer(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -471,6 +477,7 @@ func TestTopPodCustomDefaults(t *testing.T) { ...@@ -471,6 +477,7 @@ func TestTopPodCustomDefaults(t *testing.T) {
} }
initTestErrorHandler(t) initTestErrorHandler(t)
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
t.Logf("Running test case: %s", testCase.name) t.Logf("Running test case: %s", testCase.name)
metricsList := testPodMetricsData() metricsList := testPodMetricsData()
var expectedMetrics []metricsv1alpha1api.PodMetrics var expectedMetrics []metricsv1alpha1api.PodMetrics
...@@ -500,6 +507,8 @@ func TestTopPodCustomDefaults(t *testing.T) { ...@@ -500,6 +507,8 @@ func TestTopPodCustomDefaults(t *testing.T) {
} }
tf := cmdtesting.NewTestFactory() tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()
ns := legacyscheme.Codecs ns := legacyscheme.Codecs
tf.Client = &fake.RESTClient{ tf.Client = &fake.RESTClient{
...@@ -563,6 +572,7 @@ func TestTopPodCustomDefaults(t *testing.T) { ...@@ -563,6 +572,7 @@ func TestTopPodCustomDefaults(t *testing.T) {
t.Errorf("%s: unexpected metrics for %s: \n%s", testCase.name, name, result) t.Errorf("%s: unexpected metrics for %s: \n%s", testCase.name, name, result)
} }
} }
})
} }
} }
......
...@@ -44,6 +44,8 @@ func TestTopSubcommandsExist(t *testing.T) { ...@@ -44,6 +44,8 @@ func TestTopSubcommandsExist(t *testing.T) {
initTestErrorHandler(t) initTestErrorHandler(t)
f := cmdtesting.NewTestFactory() f := cmdtesting.NewTestFactory()
defer f.Cleanup()
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
cmd := NewCmdTop(f, buf, buf) cmd := NewCmdTop(f, buf, buf)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment