added ApiResponse to all api calls

This commit is contained in:
Guo Huang
2016-04-19 15:18:13 -07:00
parent 611b711a7e
commit 9cf6eb4d8b
8 changed files with 1105 additions and 1042 deletions

View File

@@ -11,11 +11,12 @@ func TestAddPet(t *testing.T) {
newPet := (sw.Pet{Id: 12830, Name: "gopher",
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
err := s.AddPet(newPet)
err, apiResponse := s.AddPet(newPet)
if err != nil {
t.Errorf("Error while adding pet")
t.Log(err)
t.Log(apiResponse)
}
}
@@ -23,10 +24,11 @@ func TestGetPetById(t *testing.T) {
assert := assert.New(t)
s := sw.NewPetApi()
resp, err := s.GetPetById(12830)
resp, err, apiResponse := s.GetPetById(12830)
if err != nil {
t.Errorf("Error while getting pet by id")
t.Log(err)
t.Log(apiResponse)
} else {
assert.Equal(resp.Id, int64(12830), "Pet id should be equal")
assert.Equal(resp.Name, "gopher", "Pet name should be gopher")
@@ -36,22 +38,53 @@ func TestGetPetById(t *testing.T) {
}
}
func TestGetPetByIdWithInvalidID(t *testing.T) {
s := sw.NewPetApi()
resp, err, apiResponse := s.GetPetById(999999999)
if err != nil {
t.Errorf("Error while getting pet by invalid id")
t.Log(err)
t.Log(apiResponse)
} else {
t.Log(resp)
}
}
func TestUpdatePetWithForm(t *testing.T) {
s := sw.NewPetApi()
err := s.UpdatePetWithForm(12830, "golang", "available")
err, apiResponse := s.UpdatePetWithForm(12830, "golang", "available")
if err != nil {
t.Errorf("Error while updating pet by id")
t.Log(err)
t.Log(apiResponse)
}
}
func TestFindPetsByStatus(t *testing.T) {
s := sw.NewPetApi()
resp, err, apiResponse := s.FindPetsByStatus([]string {"pending"})
if err != nil {
t.Errorf("Error while getting pet by id")
t.Log(err)
t.Log(apiResponse)
} else {
t.Log(apiResponse)
if len(resp) == 0 {
t.Errorf("Error no pets returned")
}
t.Log(resp)
}
}
func TestDeletePet(t *testing.T) {
s := sw.NewPetApi()
err := s.DeletePet(12830, "")
err, apiResponse := s.DeletePet(12830, "")
if err != nil {
t.Errorf("Error while deleting pet by id")
t.Log(err)
t.Log(apiResponse)
}
}