Merge branch 'guohuang-tests'

This commit is contained in:
wing328 2016-05-04 10:21:47 +08:00
commit 33291f5780

View File

@ -3,8 +3,8 @@ package main
import (
sw "./go-petstore"
"github.com/stretchr/testify/assert"
"testing"
"os"
"testing"
)
func TestAddPet(t *testing.T) {
@ -20,7 +20,7 @@ func TestAddPet(t *testing.T) {
}
if *apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response)
}
}
}
func TestFindPetsByStatusWithMissingParam(t *testing.T) {
@ -34,7 +34,7 @@ func TestFindPetsByStatusWithMissingParam(t *testing.T) {
}
if *apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse)
}
}
}
func TestGetPetById(t *testing.T) {
@ -54,7 +54,7 @@ func TestGetPetById(t *testing.T) {
}
if *apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response)
}
}
}
func TestGetPetByIdWithInvalidID(t *testing.T) {
@ -69,7 +69,7 @@ func TestGetPetByIdWithInvalidID(t *testing.T) {
}
if *apiResponse.Response.StatusCode != 200 {
t.Log(*apiResponse.Response)
}
}
}
func TestUpdatePetWithForm(t *testing.T) {
@ -88,7 +88,7 @@ func TestUpdatePetWithForm(t *testing.T) {
func TestFindPetsByStatus(t *testing.T) {
s := sw.NewPetApi()
resp, apiResponse, err := s.FindPetsByStatus([]string {"available"})
resp, apiResponse, err := s.FindPetsByStatus([]string{"available"})
if err != nil {
t.Errorf("Error while getting pet by id")
t.Log(err)
@ -97,6 +97,11 @@ func TestFindPetsByStatus(t *testing.T) {
t.Log(*apiResponse)
if len(*resp) == 0 {
t.Errorf("Error no pets returned")
} else {
assert := assert.New(t)
for i := 0; i < len(resp); i++ {
assert.Equal(resp[i].Status, "available", "Pet status should be `available`")
}
}
if *apiResponse.Response.StatusCode != 200 {
@ -107,7 +112,7 @@ func TestFindPetsByStatus(t *testing.T) {
func TestUploadFile(t *testing.T) {
s := sw.NewPetApi()
file, _ := os.Open("../python/testfiles/foo.png")
file, _ := os.Open("../python/testfiles/foo.png")
_, apiResponse, err := s.UploadFile(12830, "golang", file)