Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 23, 2022
1 parent a342ac6 commit 4555649
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions binder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fiber

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
)

func Test_Binder(t *testing.T) {
t.Parallel()
app := New()

ctx := app.NewCtx(&fasthttp.RequestCtx{}).(*DefaultCtx)
ctx.values = [maxParams]string{"id string"}
ctx.route = &Route{Params: []string{"id"}}
ctx.Request().SetBody([]byte(`{"name": "john doe"}`))
ctx.Request().Header.Set("content-type", "application/json")

var req struct {
ID string `param:"id"`
}

var body struct {
Name string `json:"name"`
}

err := ctx.Bind().Req(&req).JSON(&body).Err()
require.NoError(t, err)
require.Equal(t, "id string", req.ID)
require.Equal(t, "john doe", body.Name)
}

0 comments on commit 4555649

Please sign in to comment.