47 lines
964 B
Go
47 lines
964 B
Go
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")
|
|
}
|
|
}
|