Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use temp kubeconfig for fake factory #60950

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 33 additions & 21 deletions pkg/kubectl/cmd/annotate_test.go
Expand Up @@ -417,36 +417,42 @@ func TestAnnotateErrors(t *testing.T) {
}

for k, testCase := range testCases {
tf := cmdtesting.NewTestFactory()
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig()
t.Run(k, func(t *testing.T) {
tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()

buf := bytes.NewBuffer([]byte{})
cmd := NewCmdAnnotate(tf, buf)
cmd.SetOutput(buf)
tf.Namespace = "test"
tf.ClientConfigVal = defaultClientConfig()

for k, v := range testCase.flags {
cmd.Flags().Set(k, v)
}
options := &AnnotateOptions{}
err := options.Complete(buf, cmd, testCase.args)
if err == nil {
err = options.Validate()
}
if !testCase.errFn(err) {
t.Errorf("%s: unexpected error: %v", k, err)
continue
}
if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes()))
}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdAnnotate(tf, buf)
cmd.SetOutput(buf)

for k, v := range testCase.flags {
cmd.Flags().Set(k, v)
}
options := &AnnotateOptions{}
err := options.Complete(buf, cmd, testCase.args)
if err == nil {
err = options.Validate()
}
if !testCase.errFn(err) {
t.Errorf("%s: unexpected error: %v", k, err)
return
}
if buf.Len() > 0 {
t.Errorf("buffer should be empty: %s", string(buf.Bytes()))
}
})
}
}

func TestAnnotateObject(t *testing.T) {
pods, _, _ := testData()

tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()

codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)

tf.UnstructuredClient = &fake.RESTClient{
Expand Down Expand Up @@ -499,6 +505,8 @@ func TestAnnotateObjectFromFile(t *testing.T) {
pods, _, _ := testData()

tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()

codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)

tf.UnstructuredClient = &fake.RESTClient{
Expand Down Expand Up @@ -550,6 +558,8 @@ func TestAnnotateObjectFromFile(t *testing.T) {

func TestAnnotateLocal(t *testing.T) {
tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()

tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"},
NegotiatedSerializer: unstructuredSerializer,
Expand Down Expand Up @@ -581,6 +591,8 @@ func TestAnnotateMultipleObjects(t *testing.T) {
pods, _, _ := testData()

tf := cmdtesting.NewTestFactory()
defer tf.Cleanup()

codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...)
tf.UnstructuredClient = &fake.RESTClient{
GroupVersion: schema.GroupVersion{Group: "testgroup", Version: "v1"},
Expand Down