2016-04-17 08:41:35 +00:00
|
|
|
package main
|
2016-04-08 21:04:49 +00:00
|
|
|
|
|
|
|
import (
|
2016-04-17 08:41:35 +00:00
|
|
|
sw "./go-petstore"
|
2016-04-10 04:43:46 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-04-17 05:22:23 +00:00
|
|
|
"testing"
|
2016-04-08 21:04:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAddPet(t *testing.T) {
|
2016-04-17 08:41:35 +00:00
|
|
|
s := sw.NewPetApi()
|
|
|
|
newPet := (sw.Pet{Id: 12830, Name: "gopher",
|
2016-04-08 21:04:49 +00:00
|
|
|
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) {
|
2016-04-17 08:41:35 +00:00
|
|
|
assert := assert.New(t)
|
2016-04-08 21:04:49 +00:00
|
|
|
|
2016-04-17 08:41:35 +00:00
|
|
|
s := sw.NewPetApi()
|
2016-04-08 21:04:49 +00:00
|
|
|
resp, err := s.GetPetById(12830)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error while getting pet by id")
|
|
|
|
t.Log(err)
|
|
|
|
} else {
|
2016-04-17 05:22:23 +00:00
|
|
|
assert.Equal(resp.Id, int64(12830), "Pet id should be equal")
|
2016-04-10 04:40:47 +00:00
|
|
|
assert.Equal(resp.Name, "gopher", "Pet name should be gopher")
|
|
|
|
assert.Equal(resp.Status, "pending", "Pet status should be pending")
|
2016-04-10 04:43:46 +00:00
|
|
|
|
2016-04-17 05:22:23 +00:00
|
|
|
//t.Log(resp)
|
2016-04-08 21:04:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdatePetWithForm(t *testing.T) {
|
2016-04-17 08:41:35 +00:00
|
|
|
s := sw.NewPetApi()
|
2016-04-10 22:04:29 +00:00
|
|
|
err := s.UpdatePetWithForm(12830, "golang", "available")
|
2016-04-08 21:04:49 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error while updating pet by id")
|
|
|
|
t.Log(err)
|
2016-04-10 04:43:46 +00:00
|
|
|
}
|
2016-04-08 21:04:49 +00:00
|
|
|
}
|