Skip to content

Commit b0020c1

Browse files
danicc097mromaszewicz
authored andcommitted
update tests
1 parent 13c65e1 commit b0020c1

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

bindparam_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,20 @@ func TestSplitParameter(t *testing.T) {
294294

295295
func TestBindQueryParameter(t *testing.T) {
296296
t.Run("deepObject", func(t *testing.T) {
297+
type Object struct {
298+
Count int `json:"count"`
299+
}
300+
type Nested struct {
301+
Object Object `json:"object"`
302+
Objects []Object `json:"objects"`
303+
}
297304
type ID struct {
298305
FirstName *string `json:"firstName"`
299306
LastName *string `json:"lastName"`
300307
Role string `json:"role"`
301308
Birthday *types.Date `json:"birthday"`
302309
Married *MockBinder `json:"married"`
310+
Nested Nested `json:"nested"`
303311
}
304312

305313
expectedName := "Alex"
@@ -308,16 +316,23 @@ func TestBindQueryParameter(t *testing.T) {
308316
Role: "admin",
309317
Birthday: &types.Date{Time: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)},
310318
Married: &MockBinder{time.Date(2020, 2, 2, 0, 0, 0, 0, time.UTC)},
319+
Nested: Nested{
320+
Object: Object{Count: 123},
321+
Objects: []Object{{Count: 1}, {Count: 2}},
322+
},
311323
}
312324

313325
actual := new(ID)
314326
paramName := "id"
315327
queryParams := url.Values{
316-
"id[firstName]": {"Alex"},
317-
"id[role]": {"admin"},
318-
"foo": {"bar"},
319-
"id[birthday]": {"2020-01-01"},
320-
"id[married]": {"2020-02-02"},
328+
"id[firstName]": {"Alex"},
329+
"id[role]": {"admin"},
330+
"foo": {"bar"},
331+
"id[birthday]": {"2020-01-01"},
332+
"id[married]": {"2020-02-02"},
333+
"id[nested][object][count]": {"123"},
334+
"id[nested][objects][0][count]": {"1"},
335+
"id[nested][objects][1][count]": {"2"},
321336
}
322337

323338
err := BindQueryParameter("deepObject", true, false, paramName, queryParams, &actual)

0 commit comments

Comments
 (0)