use subtest for table units (pkg/kubectl)

This commit is contained in:
Guoliang Wang
2018-05-12 17:24:28 +08:00
parent d057795f3b
commit bae074ef38
34 changed files with 1841 additions and 1301 deletions

View File

@@ -50,33 +50,34 @@ func TestExecRunner(t *testing.T) {
os.Setenv("KUBECTL_PLUGINS_TEST", "ok")
defer os.Unsetenv("KUBECTL_PLUGINS_TEST")
for _, test := range tests {
streams, _, outBuf, _ := genericclioptions.NewTestIOStreams()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
streams, _, outBuf, _ := genericclioptions.NewTestIOStreams()
plugin := &Plugin{
Description: Description{
Name: test.name,
ShortDesc: "Test Runner Plugin",
Command: test.command,
},
}
plugin := &Plugin{
Description: Description{
Name: tt.name,
ShortDesc: "Test Runner Plugin",
Command: tt.command,
},
}
ctx := RunningContext{
IOStreams: streams,
WorkingDir: ".",
EnvProvider: &EmptyEnvProvider{},
}
ctx := RunningContext{
IOStreams: streams,
WorkingDir: ".",
EnvProvider: &EmptyEnvProvider{},
}
runner := &ExecPluginRunner{}
err := runner.Run(plugin, ctx)
runner := &ExecPluginRunner{}
err := runner.Run(plugin, ctx)
if outBuf.String() != test.expectedMsg {
t.Errorf("%s: unexpected output: %q", test.name, outBuf.String())
}
if outBuf.String() != tt.expectedMsg {
t.Errorf("%s: unexpected output: %q", tt.name, outBuf.String())
}
if err != nil && err.Error() != test.expectedErr {
t.Errorf("%s: unexpected err output: %v", test.name, err)
}
if err != nil && err.Error() != tt.expectedErr {
t.Errorf("%s: unexpected err output: %v", tt.name, err)
}
})
}
}