mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
query binding test
This commit is contained in:
parent
c17e9f1a15
commit
29dfe40442
@ -12,7 +12,6 @@ func (queryBinding) Name() string {
|
|||||||
return "query"
|
return "query"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add tests
|
|
||||||
func (q queryBinding) Bind(req *http.Request, obj any) error {
|
func (q queryBinding) Bind(req *http.Request, obj any) error {
|
||||||
values := req.URL.Query()
|
values := req.URL.Query()
|
||||||
if err := mapFormByTag(obj, values, q.Name()); err != nil {
|
if err := mapFormByTag(obj, values, q.Name()); err != nil {
|
||||||
|
23
binding/query_test.go
Normal file
23
binding/query_test.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package binding
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestQueryBinding(t *testing.T) {
|
||||||
|
var s struct {
|
||||||
|
Foo string `query:"foo"`
|
||||||
|
}
|
||||||
|
|
||||||
|
request := &http.Request{URL: &url.URL{RawQuery: "foo=BAR"}}
|
||||||
|
|
||||||
|
err := queryBinding{}.Bind(request, &s)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, "BAR", s.Foo)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user