Feat: add more tests
This commit is contained in:
37
tests/02_postImage_test.go
Normal file
37
tests/02_postImage_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user