Skip to content

Commit 87a495b

Browse files
danicc097mromaszewicz
authored andcommitted
test update
1 parent 5bb2934 commit 87a495b

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

deepobject_test.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,38 @@ import (
1010
"github.com/stretchr/testify/require"
1111
)
1212

13+
type InnerArrayObject struct {
14+
Names []string `json:"names"`
15+
}
16+
1317
type InnerObject struct {
1418
Name string
1519
ID int
1620
}
21+
type InnerObject2 struct {
22+
Foo string
23+
Is bool
24+
}
1725

1826
// These are all possible field types, mandatory and optional.
1927
type AllFields struct {
20-
I int `json:"i"`
21-
Oi *int `json:"oi,omitempty"`
22-
F float32 `json:"f"`
23-
Of *float32 `json:"of,omitempty"`
24-
B bool `json:"b"`
25-
Ob *bool `json:"ob,omitempty"`
26-
As []string `json:"as"`
27-
Oas *[]string `json:"oas,omitempty"`
28-
O InnerObject `json:"o"`
29-
Oo *InnerObject `json:"oo,omitempty"`
30-
D MockBinder `json:"d"`
31-
Od *MockBinder `json:"od,omitempty"`
32-
M map[string]int `json:"m"`
33-
Om *map[string]int `json:"om,omitempty"`
28+
I int `json:"i"`
29+
Oi *int `json:"oi,omitempty"`
30+
Ab *[]bool `json:"ab,omitempty"`
31+
F float32 `json:"f"`
32+
Of *float32 `json:"of,omitempty"`
33+
B bool `json:"b"`
34+
Ob *bool `json:"ob,omitempty"`
35+
As []string `json:"as"`
36+
Oas *[]string `json:"oas,omitempty"`
37+
O InnerObject `json:"o"`
38+
Ao []InnerObject2 `json:"ao"`
39+
Onas InnerArrayObject `json:"onas"`
40+
Oo *InnerObject `json:"oo,omitempty"`
41+
D MockBinder `json:"d"`
42+
Od *MockBinder `json:"od,omitempty"`
43+
M map[string]int `json:"m"`
44+
Om *map[string]int `json:"om,omitempty"`
3445
}
3546

3647
func TestDeepObject(t *testing.T) {
@@ -54,12 +65,20 @@ func TestDeepObject(t *testing.T) {
5465
Of: &of,
5566
B: true,
5667
Ob: &ob,
68+
Ab: &[]bool{true},
5769
As: []string{"hello", "world"},
5870
Oas: &oas,
5971
O: InnerObject{
6072
Name: "Joe Schmoe",
6173
ID: 456,
6274
},
75+
Ao: []InnerObject2{
76+
{Foo: "bar", Is: true},
77+
{Foo: "baz", Is: false},
78+
},
79+
Onas: InnerArrayObject{
80+
Names: []string{"Bill", "Frank"},
81+
},
6382
Oo: &oo,
6483
D: d,
6584
Od: &d,
@@ -69,7 +88,7 @@ func TestDeepObject(t *testing.T) {
6988

7089
marshaled, err := MarshalDeepObject(srcObj, "p")
7190
require.NoError(t, err)
72-
t.Log(marshaled)
91+
require.EqualValues(t, "p[ab][0]=true&p[ao][0][Foo]=bar&p[ao][0][Is]=true&p[ao][1][Foo]=baz&p[ao][1][Is]=false&p[as][0]=hello&p[as][1]=world&p[b]=true&p[d]=2020-02-01&p[f]=4.2&p[i]=12&p[m][additional]=1&p[o][ID]=456&p[o][Name]=Joe Schmoe&p[oas][0]=foo&p[oas][1]=bar&p[ob]=true&p[od]=2020-02-01&p[of]=3.7&p[oi]=5&p[om][additional]=1&p[onas][names][0]=Bill&p[onas][names][1]=Frank&p[oo][ID]=123&p[oo][Name]=Marcin Romaszewicz", marshaled)
7392

7493
params := make(url.Values)
7594
marshaledParts := strings.Split(marshaled, "&")

0 commit comments

Comments
 (0)