1
0
mirror of https://github.com/labstack/echo.git synced 2026-05-16 09:48:24 +02:00
Files
echo/echotest/context_external_test.go
T
toimtoimtoim f071367e3c V5 changes
2026-01-18 18:14:41 +02:00

28 lines
621 B
Go

package echotest_test
import (
"net/http"
"testing"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/echotest"
"github.com/stretchr/testify/assert"
)
func TestToContext_JSONBody(t *testing.T) {
c := echotest.ContextConfig{
JSONBody: echotest.LoadBytes(t, "testdata/test.json"),
}.ToContext(t)
payload := struct {
Field string `json:"field"`
}{}
if err := c.Bind(&payload); err != nil {
t.Fatal(err)
}
assert.Equal(t, "value", payload.Field)
assert.Equal(t, http.MethodPost, c.Request().Method)
assert.Equal(t, echo.MIMEApplicationJSON, c.Request().Header.Get(echo.HeaderContentType))
}