mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-23 20:51:59 +00:00
use temp kubeconfig for fake factory
This commit is contained in:
@@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user