@@ -28,6 +28,7 @@ func TestNamespaceGenerate(t *testing.T) {
28
28
params map [string ]interface {}
29
29
expected * api.Namespace
30
30
expectErr bool
31
+ index int
31
32
}{
32
33
{
33
34
params : map [string ]interface {}{
@@ -44,15 +45,45 @@ func TestNamespaceGenerate(t *testing.T) {
44
45
params : map [string ]interface {}{},
45
46
expectErr : true ,
46
47
},
48
+ {
49
+ params : map [string ]interface {}{
50
+ "name" : 1 ,
51
+ },
52
+ expectErr : true ,
53
+ },
54
+ {
55
+ params : map [string ]interface {}{
56
+ "name" : nil ,
57
+ },
58
+ expectErr : true ,
59
+ },
60
+ {
61
+ params : map [string ]interface {}{
62
+ "name_wrong_key" : "some_value" ,
63
+ },
64
+ expectErr : true ,
65
+ },
66
+ {
67
+ params : map [string ]interface {}{
68
+ "NAME" : "some_value" ,
69
+ },
70
+ expectErr : true ,
71
+ },
47
72
}
48
73
generator := NamespaceGeneratorV1 {}
49
- for _ , test := range tests {
74
+ for index , test := range tests {
50
75
obj , err := generator .Generate (test .params )
51
- if ! test .expectErr && err != nil {
52
- t .Errorf ("unexpected error: %v" , err )
53
- }
54
- if test .expectErr && err != nil {
55
- continue
76
+ switch {
77
+ case test .expectErr && err != nil :
78
+ continue // loop, since there's no output to check
79
+ case test .expectErr && err == nil :
80
+ t .Errorf ("%v: expected error and didn't get one" , index )
81
+ continue // loop, no expected output object
82
+ case ! test .expectErr && err != nil :
83
+ t .Errorf ("%v: expected error and didn't get one" , index )
84
+ continue // loop, no output object
85
+ case ! test .expectErr && err == nil :
86
+ // do nothing and drop through
56
87
}
57
88
if ! reflect .DeepEqual (obj .(* api.Namespace ), test .expected ) {
58
89
t .Errorf ("\n expected:\n %#v\n saw:\n %#v" , test .expected , obj .(* api.Namespace ))
0 commit comments