Merge pull request #2532 from guohuang/issue1948

issue #1948, added testing code to test go api
This commit is contained in:
wing328 2016-04-11 01:05:20 +08:00
commit 4942ebdc73

View File

@ -0,0 +1,52 @@
package main
import (
"testing"
sw "./swagger"
"github.com/stretchr/testify/assert"
)
func TestAddPet(t *testing.T) {
t.Log("Testing TestAddPet...")
s := sw.NewPetApi()
newPet := (sw.Pet{Id: 12830, Name: "gopher",
PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: "pending"})
err := s.AddPet(newPet)
if err != nil {
t.Errorf("Error while adding pet")
t.Log(err)
}
}
func TestGetPetById(t *testing.T) {
assert := assert.New(t)
t.Log("Testing TestGetPetById...")
s := sw.NewPetApi()
resp, err := s.GetPetById(12830)
if err != nil {
t.Errorf("Error while getting pet by id")
t.Log(err)
} else {
assert.Equal(resp.Id, 12830, "Pet id should be equal")
assert.Equal(resp.Name, "gopher", "Pet name should be gopher")
assert.Equal(resp.Status, "pending", "Pet status should be pending")
t.Log(resp)
}
}
func TestUpdatePetWithForm(t *testing.T) {
t.Log("Testing UpdatePetWithForm...")
s := sw.NewPetApi()
err := s.UpdatePetWithForm("12830", "golang", "available")
if err != nil {
t.Errorf("Error while updating pet by id")
t.Log(err)
}
}