| @ -1,76 +0,0 @@ | |||||
| package api | |||||
| import ( | |||||
| "testing" | |||||
| ) | |||||
| func TestDeserializePetJson(t *testing.T) { | |||||
| jsonData := ` | |||||
| { | |||||
| "id": 5, | |||||
| "category": { | |||||
| "id": 6, | |||||
| "name": "test_category" | |||||
| }, | |||||
| "name": "doggie", | |||||
| "photoUrls": [ | |||||
| "photo_url_test" | |||||
| ], | |||||
| "tags": [ | |||||
| { | |||||
| "id": 0, | |||||
| "name": "test_tags" | |||||
| } | |||||
| ], | |||||
| "status": "available" | |||||
| } | |||||
| ` | |||||
| petData, err := deserialsePetJson(jsonData) | |||||
| if err != nil { | |||||
| t.Error(err.Error()) | |||||
| return | |||||
| } | |||||
| if petData.Id != 5 { | |||||
| t.Errorf("Id was incorrect, got: %d, want: %d", petData.Id, 5) | |||||
| } | |||||
| if petData.Name != "doggie" { | |||||
| t.Errorf("Name was incorrect, got: %s, want: %s", petData.Name, "doggie") | |||||
| } | |||||
| if petData.Status != "available" { | |||||
| t.Errorf("Status was incorrect, got: %s, want: %s", petData.Status, "doggie") | |||||
| } | |||||
| if petData.Category.Id != 6 { | |||||
| t.Errorf("Category Id was incorrect, got: %d, want: %d", petData.Category.Id, 6) | |||||
| } | |||||
| if petData.Category.Name != "test_category" { | |||||
| t.Errorf("Category Name was incorrect, got: %s, want: %s", petData.Category.Name, "test_category") | |||||
| } | |||||
| if len(petData.PhotoUrls) != 1 && petData.PhotoUrls[0] != "photo_url_test" { | |||||
| t.Errorf("PhotoUrls was incorrect, length: %d", len(petData.PhotoUrls)) | |||||
| } | |||||
| if len(petData.Tags) != 1 && petData.Tags[0].Id != 0 && petData.Tags[0].Name != "test_tags" { | |||||
| t.Errorf("Tags was incorrect, length: %d", len(petData.Tags)) | |||||
| } | |||||
| } | |||||
| func TestDeserializePetJsonFail(t *testing.T) { | |||||
| jsonData := ` | |||||
| { | |||||
| "invalid": "data" | |||||
| } | |||||
| ` | |||||
| _, err := deserialsePetJson(jsonData) | |||||
| if err == nil { | |||||
| t.Error("Invalid data was provided, expected error was not thrown.") | |||||
| t.Error(err.Error()) | |||||
| } | |||||
| } | |||||