config: clean up and remove some tests

Small modification to make these align with our test-table-style tests.
Also removed TestCloudConfigInvalidKeys since it hasn't been a useful
test since d3294bcb86.
This commit is contained in:
Alex Crawford 2014-12-20 17:47:17 -08:00
parent edced59fa6
commit 182241c8d3

View File

@ -23,8 +23,9 @@ import (
) )
func TestIsZero(t *testing.T) { func TestIsZero(t *testing.T) {
for _, tt := range []struct { tests := []struct {
c interface{} c interface{}
empty bool empty bool
}{ }{
{struct{}{}, true}, {struct{}{}, true},
@ -34,7 +35,9 @@ func TestIsZero(t *testing.T) {
{struct{ A string }{A: "hello"}, false}, {struct{ A string }{A: "hello"}, false},
{struct{ A int }{}, true}, {struct{ A int }{}, true},
{struct{ A int }{A: 1}, false}, {struct{ A int }{A: 1}, false},
} { }
for _, tt := range tests {
if empty := IsZero(tt.c); tt.empty != empty { if empty := IsZero(tt.c); tt.empty != empty {
t.Errorf("bad result (%q): want %t, got %t", 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) { func TestAssertStructValid(t *testing.T) {
for _, tt := range []struct { tests := []struct {
c interface{} c interface{}
err error err error
}{ }{
{struct{}{}, nil}, {struct{}{}, nil},
@ -71,41 +75,15 @@ func TestAssertStructValid(t *testing.T) {
{struct { {struct {
A, b int `valid:"1,2"` A, b int `valid:"1,2"`
}{A: 9, b: 2}, &ErrorValid{Value: "9", Field: "A", Valid: []string{"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) { if err := AssertStructValid(tt.c); !reflect.DeepEqual(tt.err, err) {
t.Errorf("bad result (%q): want %q, got %q", tt.c, 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) { func TestCloudConfigUnknownKeys(t *testing.T) {
contents := ` contents := `
coreos: coreos: