-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for parseManagedObjectReferenceResponse
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
inventory/inventoryReferenceApi_parseManagedObjectResponse_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package inventory | ||
|
||
import ( | ||
"fmt" | ||
"github.com/tarent/gomulocity/generic" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestInventoryReferenceApi_ParseManagedObjectResponse(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
givenResponseBody string | ||
expectedManagedObjectReference *ManagedObjectReference | ||
expectedErr *generic.Error | ||
}{ | ||
{ | ||
name: "parsable body", | ||
givenResponseBody: givenReferenceResponseBody, | ||
expectedManagedObjectReference: expectedManagedObjectReference, | ||
expectedErr: nil, | ||
}, { | ||
name: "unparsable body", | ||
givenResponseBody: `{`, | ||
expectedManagedObjectReference: nil, | ||
expectedErr: &generic.Error{ | ||
ErrorType: "ClientError", | ||
Message: "Error while parsing response JSON: unexpected end of JSON input", | ||
Info: "ResponseParser", | ||
}, | ||
}, { | ||
name: "without body", | ||
givenResponseBody: ``, | ||
expectedManagedObjectReference: nil, | ||
expectedErr: &generic.Error{ | ||
ErrorType: "ClientError", | ||
Message: "Response body was empty", | ||
Info: "ResponseParser", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
managedObject, err := parseManagedObjectReferenceResponse([]byte(tt.givenResponseBody)) | ||
|
||
if fmt.Sprint(err) != fmt.Sprint(tt.expectedErr) { | ||
t.Fatalf("Unexpected error was returned: %s\nExpected: %s", err, tt.expectedErr) | ||
} | ||
|
||
if !reflect.DeepEqual(managedObject, tt.expectedManagedObjectReference) { | ||
t.Errorf("Unexpected managedObject was returned: %#v\nExpected: %#v", managedObject, tt.expectedManagedObjectReference) | ||
} | ||
}) | ||
} | ||
} |