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

@@ -20,10 +20,12 @@ import "testing"
func TestPlugin(t *testing.T) {
tests := []struct {
name string
plugin *Plugin
expectedErr error
}{
{
name: "test1",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -33,6 +35,7 @@ func TestPlugin(t *testing.T) {
},
},
{
name: "test2",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -42,10 +45,12 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrIncompletePlugin,
},
{
name: "test3",
plugin: &Plugin{},
expectedErr: ErrIncompletePlugin,
},
{
name: "test4",
plugin: &Plugin{
Description: Description{
Name: "test spaces",
@@ -56,6 +61,7 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrInvalidPluginName,
},
{
name: "test5",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -71,6 +77,7 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrIncompleteFlag,
},
{
name: "test6",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -87,6 +94,7 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrInvalidFlagName,
},
{
name: "test7",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -104,6 +112,7 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrInvalidFlagShorthand,
},
{
name: "test8",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -121,6 +130,7 @@ func TestPlugin(t *testing.T) {
expectedErr: ErrInvalidFlagShorthand,
},
{
name: "test9",
plugin: &Plugin{
Description: Description{
Name: "test",
@@ -160,10 +170,12 @@ func TestPlugin(t *testing.T) {
},
}
for _, test := range tests {
err := test.plugin.Validate()
if err != test.expectedErr {
t.Errorf("%s: expected error %v, got %v", test.plugin.Name, test.expectedErr, err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.plugin.Validate()
if err != tt.expectedErr {
t.Errorf("%s: expected error %v, got %v", tt.plugin.Name, tt.expectedErr, err)
}
})
}
}