forked from gorilla/schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export the Form and Query decoders in order to be customized by Iris …
…users and ignore unknown url query parameters instead of giving an ErrPath relative to: kataras/iris#1566
- Loading branch information
Showing
4 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/iris-contrib/schema | ||
|
||
go 1.12 | ||
go 1.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// package schema_test black box testing | ||
package schema_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kataras/iris/v12" | ||
"github.com/kataras/iris/v12/httptest" | ||
) | ||
|
||
type testRequest struct { | ||
Username string `form:"test_username" json:"test_username"` | ||
Data []testData `form:"test_data" json:"test_data"` | ||
Other int `form:"test_other" json:"test_other"` | ||
} | ||
|
||
type testData struct { | ||
Name string `form:"test_data_name" json:"test_data_name"` | ||
} | ||
|
||
func TestSchemaSliceFieldTag(t *testing.T) { | ||
app := iris.New() | ||
app.Post("/", func(ctx iris.Context) { | ||
var p testRequest | ||
if err := ctx.ReadForm(&p); err != nil && iris.IsErrPath(err) { | ||
t.Fatal(err) | ||
} | ||
|
||
ctx.JSON(p) | ||
}) | ||
|
||
payload := testRequest{ | ||
Username: "test username", | ||
Data: []testData{ | ||
{Name: "test data name 1"}, | ||
{Name: "test data name 2"}, | ||
{Name: "test data name 3"}, | ||
}, | ||
Other: 42, | ||
} | ||
|
||
e := httptest.New(t, app) | ||
e.POST("/").WithForm(payload).Expect().Status(iris.StatusOK).JSON().Equal(payload) | ||
} |