diff --git a/config/config_test.go b/config/config_test.go index 29171ad..68a42cc 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -23,8 +23,9 @@ import ( ) func TestIsZero(t *testing.T) { - for _, tt := range []struct { - c interface{} + tests := []struct { + c interface{} + empty bool }{ {struct{}{}, true}, @@ -34,7 +35,9 @@ func TestIsZero(t *testing.T) { {struct{ A string }{A: "hello"}, false}, {struct{ A int }{}, true}, {struct{ A int }{A: 1}, false}, - } { + } + + for _, tt := range tests { if empty := IsZero(tt.c); tt.empty != empty { t.Errorf("bad result (%q): want %t, got %t", tt.c, tt.empty, empty) } @@ -42,8 +45,9 @@ func TestIsZero(t *testing.T) { } func TestAssertStructValid(t *testing.T) { - for _, tt := range []struct { - c interface{} + tests := []struct { + c interface{} + err error }{ {struct{}{}, nil}, @@ -71,41 +75,15 @@ func TestAssertStructValid(t *testing.T) { {struct { A, b int `valid:"1,2"` }{A: 9, b: 2}, &ErrorValid{Value: "9", Field: "A", Valid: []string{"1", "2"}}}, - } { + } + + for _, tt := range tests { if err := AssertStructValid(tt.c); !reflect.DeepEqual(tt.err, err) { t.Errorf("bad result (%q): want %q, got %q", tt.c, tt.err, err) } } } -func TestCloudConfigInvalidKeys(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Fatalf("panic while instantiating CloudConfig with nil keys: %v", r) - } - }() - - for _, tt := range []struct { - contents string - }{ - {"coreos:"}, - {"ssh_authorized_keys:"}, - {"ssh_authorized_keys:\n -"}, - {"ssh_authorized_keys:\n - 0:"}, - {"write_files:"}, - {"write_files:\n -"}, - {"write_files:\n - 0:"}, - {"users:"}, - {"users:\n -"}, - {"users:\n - 0:"}, - } { - _, err := NewCloudConfig(tt.contents) - if err != nil { - t.Fatalf("error instantiating CloudConfig with invalid keys: %v", err) - } - } -} - func TestCloudConfigUnknownKeys(t *testing.T) { contents := ` coreos: