update more commands for iostreams

This commit is contained in:
David Eads
2018-04-25 08:32:08 -04:00
parent 3fb88a23d9
commit 8c1b687356
24 changed files with 241 additions and 262 deletions

View File

@@ -42,6 +42,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/scheme"
)
@@ -83,9 +84,8 @@ func TestSetServiceAccountLocal(t *testing.T) {
outputFormat := "yaml"
tf.Namespace = "test"
out := new(bytes.Buffer)
cmd := NewCmdServiceAccount(tf, out, out)
cmd.SetOutput(out)
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdServiceAccount(tf, streams)
cmd.Flags().Set("output", outputFormat)
cmd.Flags().Set("local", "true")
testapi.Default = testapi.Groups[input.apiGroup]
@@ -98,13 +98,14 @@ func TestSetServiceAccountLocal(t *testing.T) {
},
fileNameOptions: resource.FilenameOptions{
Filenames: []string{input.yaml}},
out: out,
local: true}
local: true,
IOStreams: streams,
}
err := saConfig.Complete(tf, cmd, []string{serviceAccount})
assert.NoError(t, err)
err = saConfig.Run()
assert.NoError(t, err)
assert.Contains(t, out.String(), "serviceAccountName: "+serviceAccount, fmt.Sprintf("serviceaccount not updated for %s", input.yaml))
assert.Contains(t, buf.String(), "serviceAccountName: "+serviceAccount, fmt.Sprintf("serviceaccount not updated for %s", input.yaml))
})
}
}
@@ -128,9 +129,8 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
outputFormat := "name"
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdServiceAccount(tf, buf, buf)
cmd.SetOutput(buf)
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdServiceAccount(tf, streams)
cmd.Flags().Set("output", outputFormat)
cmd.Flags().Set("local", "true")
opts := SetServiceAccountOptions{
@@ -142,8 +142,9 @@ func TestSetServiceAccountMultiLocal(t *testing.T) {
},
fileNameOptions: resource.FilenameOptions{
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
out: buf,
local: true}
local: true,
IOStreams: streams,
}
err := opts.Complete(tf, cmd, []string{serviceAccount})
if err == nil {
@@ -373,9 +374,8 @@ func TestSetServiceAccountRemote(t *testing.T) {
outputFormat := "yaml"
out := new(bytes.Buffer)
cmd := NewCmdServiceAccount(tf, out, out)
cmd.SetOutput(out)
streams := genericclioptions.NewTestIOStreamsDiscard()
cmd := NewCmdServiceAccount(tf, streams)
cmd.Flags().Set("output", outputFormat)
saConfig := SetServiceAccountOptions{
PrintFlags: &printers.PrintFlags{
@@ -385,8 +385,9 @@ func TestSetServiceAccountRemote(t *testing.T) {
OutputFormat: &outputFormat,
},
out: out,
local: false}
local: false,
IOStreams: streams,
}
err := saConfig.Complete(tf, cmd, input.args)
assert.NoError(t, err)
err = saConfig.Run()
@@ -420,9 +421,8 @@ func TestServiceAccountValidation(t *testing.T) {
outputFormat := ""
tf.Namespace = "test"
out := bytes.NewBuffer([]byte{})
cmd := NewCmdServiceAccount(tf, out, out)
cmd.SetOutput(out)
streams := genericclioptions.NewTestIOStreamsDiscard()
cmd := NewCmdServiceAccount(tf, streams)
saConfig := &SetServiceAccountOptions{
PrintFlags: &printers.PrintFlags{
@@ -431,6 +431,7 @@ func TestServiceAccountValidation(t *testing.T) {
OutputFormat: &outputFormat,
},
IOStreams: streams,
}
err := saConfig.Complete(tf, cmd, input.args)
assert.EqualError(t, err, input.errorString)