use temp kubeconfig for fake factory

This commit is contained in:
juanvallejo
2018-03-08 17:23:55 -05:00
parent 40143fd687
commit 8d35f94d51
49 changed files with 2156 additions and 1723 deletions

View File

@@ -80,34 +80,38 @@ func TestPluginCmd(t *testing.T) {
}
for _, test := range tests {
inBuf := bytes.NewBuffer([]byte{})
outBuf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
t.Run(test.name, func(t *testing.T) {
inBuf := bytes.NewBuffer([]byte{})
outBuf := bytes.NewBuffer([]byte{})
errBuf := bytes.NewBuffer([]byte{})
cmdutil.BehaviorOnFatal(func(str string, code int) {
errBuf.Write([]byte(str))
})
cmdutil.BehaviorOnFatal(func(str string, code int) {
errBuf.Write([]byte(str))
})
runner := &mockPluginRunner{
success: test.expectedSuccess,
}
f := cmdtesting.NewTestFactory()
cmd := NewCmdForPlugin(f, test.plugin, runner, inBuf, outBuf, errBuf)
if cmd == nil {
if !test.expectedNilCmd {
t.Fatalf("%s: command was unexpectedly not registered", test.name)
runner := &mockPluginRunner{
success: test.expectedSuccess,
}
continue
}
cmd.Run(cmd, []string{})
if test.expectedSuccess && outBuf.String() != fmt.Sprintf("ok: %s", test.plugin.Name) {
t.Errorf("%s: unexpected output: %q", test.name, outBuf.String())
}
f := cmdtesting.NewTestFactory()
defer f.Cleanup()
if !test.expectedSuccess && errBuf.String() != fmt.Sprintf("error: oops %s", test.plugin.Name) {
t.Errorf("%s: unexpected err output: %q", test.name, errBuf.String())
}
cmd := NewCmdForPlugin(f, test.plugin, runner, inBuf, outBuf, errBuf)
if cmd == nil {
if !test.expectedNilCmd {
t.Fatalf("%s: command was unexpectedly not registered", test.name)
}
return
}
cmd.Run(cmd, []string{})
if test.expectedSuccess && outBuf.String() != fmt.Sprintf("ok: %s", test.plugin.Name) {
t.Errorf("%s: unexpected output: %q", test.name, outBuf.String())
}
if !test.expectedSuccess && errBuf.String() != fmt.Sprintf("error: oops %s", test.plugin.Name) {
t.Errorf("%s: unexpected err output: %q", test.name, errBuf.String())
}
})
}
}