Feat: add more tests
This commit is contained in:
46
tests/08_deleteImage_test.go
Normal file
46
tests/08_deleteImage_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type getImagesPayload struct {
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
|
||||
func Test_08_DeleteImage(t *testing.T) {
|
||||
resp, err := client.R().
|
||||
SetBody(rawImage).
|
||||
SetResult(&image).
|
||||
Post("http://localhost:8080/api/image")
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to post image")
|
||||
}
|
||||
|
||||
resp, err = client.R().
|
||||
Delete(fmt.Sprintf("http://localhost:8080/api/image/%d",
|
||||
image.Id))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to delete image")
|
||||
}
|
||||
|
||||
var imgs []getImagesPayload
|
||||
|
||||
resp, err = client.R().
|
||||
SetResult(&imgs).
|
||||
SetQueryParam("images", strconv.FormatInt(image.Id, 10)).
|
||||
Get("http://localhost:8080/api/images")
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to get image by image id")
|
||||
}
|
||||
|
||||
if len(imgs) > 0 {
|
||||
t.Fatal("image not deleted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user