38 lines
664 B
Go
38 lines
664 B
Go
package tests
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
type postImagePayload struct {
|
|
Id int64 `json:"id"`
|
|
Extension string `json:"extension"`
|
|
}
|
|
|
|
var rawImage []byte
|
|
var image postImagePayload
|
|
|
|
func Test_02_PostImage(t *testing.T) {
|
|
f, err := os.Open("resources/huh.png")
|
|
if err != nil {
|
|
t.Fatal("failed to open test png")
|
|
}
|
|
rawImage, err = io.ReadAll(f)
|
|
if err != nil {
|
|
t.Fatal("failed to read from file")
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|