You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
660 B
Go
28 lines
660 B
Go
package httpx
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// MustTest executes a Fiber test request and fails on transport errors.
|
|
func MustTest(t testing.TB, app *fiber.App, req *http.Request) *http.Response {
|
|
t.Helper()
|
|
resp, err := app.Test(req)
|
|
if err != nil {
|
|
t.Fatalf("app.Test failed: %v", err)
|
|
}
|
|
return resp
|
|
}
|
|
|
|
// AssertStatusAndClose validates status code and closes response body.
|
|
func AssertStatusAndClose(t testing.TB, resp *http.Response, want int, msg string) {
|
|
t.Helper()
|
|
defer func() { _ = resp.Body.Close() }()
|
|
if resp.StatusCode != want {
|
|
t.Fatalf("%s: status=%d want=%d", msg, resp.StatusCode, want)
|
|
}
|
|
}
|