release-note-none

Added negative test case for namespace
pull/6/head
Rajdeep Dua 2016-05-05 02:11:28 -07:00
parent 303742ce12
commit 51b5b895a8
1 changed files with 37 additions and 6 deletions

View File

@ -28,6 +28,7 @@ func TestNamespaceGenerate(t *testing.T) {
params map[string]interface{} params map[string]interface{}
expected *api.Namespace expected *api.Namespace
expectErr bool expectErr bool
index int
}{ }{
{ {
params: map[string]interface{}{ params: map[string]interface{}{
@ -44,15 +45,45 @@ func TestNamespaceGenerate(t *testing.T) {
params: map[string]interface{}{}, params: map[string]interface{}{},
expectErr: true, expectErr: true,
}, },
{
params: map[string]interface{}{
"name": 1,
},
expectErr: true,
},
{
params: map[string]interface{}{
"name": nil,
},
expectErr: true,
},
{
params: map[string]interface{}{
"name_wrong_key": "some_value",
},
expectErr: true,
},
{
params: map[string]interface{}{
"NAME": "some_value",
},
expectErr: true,
},
} }
generator := NamespaceGeneratorV1{} generator := NamespaceGeneratorV1{}
for _, test := range tests { for index, test := range tests {
obj, err := generator.Generate(test.params) obj, err := generator.Generate(test.params)
if !test.expectErr && err != nil { switch {
t.Errorf("unexpected error: %v", err) case test.expectErr && err != nil:
} continue // loop, since there's no output to check
if test.expectErr && err != nil { case test.expectErr && err == nil:
continue t.Errorf("%v: expected error and didn't get one", index)
continue // loop, no expected output object
case !test.expectErr && err != nil:
t.Errorf("%v: expected error and didn't get one", index)
continue // loop, no output object
case !test.expectErr && err == nil:
// do nothing and drop through
} }
if !reflect.DeepEqual(obj.(*api.Namespace), test.expected) { if !reflect.DeepEqual(obj.(*api.Namespace), test.expected) {
t.Errorf("\nexpected:\n%#v\nsaw:\n%#v", test.expected, obj.(*api.Namespace)) t.Errorf("\nexpected:\n%#v\nsaw:\n%#v", test.expected, obj.(*api.Namespace))