@@ -28,9 +28,10 @@ type TestupdateUserDetails struct {
28
28
}
29
29
30
30
type listCompartmentsRequest struct {
31
- CompartmentID string `mandatory:"true" contributesTo:"query" name:"compartmentId"`
32
- Page string `mandatory:"false" contributesTo:"query" name:"page"`
33
- Limit int32 `mandatory:"false" contributesTo:"query" name:"limit"`
31
+ CompartmentID string `mandatory:"true" contributesTo:"query" name:"compartmentId"`
32
+ Page string `mandatory:"false" contributesTo:"query" name:"page"`
33
+ Limit int32 `mandatory:"false" contributesTo:"query" name:"limit"`
34
+ Fields []string `mandatory:"true" contributesTo:"query" name:"fields" collectionFormat:"csv"`
34
35
}
35
36
36
37
type updateUserRequest struct {
@@ -69,13 +70,15 @@ func TestHttpMarshallerInvalidStruct(t *testing.T) {
69
70
}
70
71
71
72
func TestHttpRequestMarshallerQuery (t * testing.T ) {
72
- s := listCompartmentsRequest {CompartmentID : "ocid1" , Page : "p" , Limit : 23 }
73
+ s := listCompartmentsRequest {CompartmentID : "ocid1" , Page : "p" , Limit : 23 , Fields : [] string { "one" , "two" , "three" } }
73
74
request := MakeDefaultHTTPRequest (http .MethodPost , "/" )
74
- HTTPRequestMarshaller (s , & request )
75
+ e := HTTPRequestMarshaller (s , & request )
75
76
query := request .URL .Query ()
77
+ assert .NoError (t , e )
76
78
assert .True (t , query .Get ("compartmentId" ) == "ocid1" )
77
79
assert .True (t , query .Get ("page" ) == "p" )
78
80
assert .True (t , query .Get ("limit" ) == "23" )
81
+ assert .True (t , query .Get ("fields" ) == "one,two,three" )
79
82
}
80
83
81
84
func TestMakeDefault (t * testing.T ) {
@@ -169,15 +172,19 @@ func TestHttpMarshallerEmptyPath(t *testing.T) {
169
172
170
173
func TestHttpMarshalerAll (t * testing.T ) {
171
174
desc := "theDescription"
175
+ type inc string
176
+ includes := []inc {inc ("One" ), inc ("Two" )}
177
+
172
178
s := struct {
173
179
ID string `contributesTo:"path"`
174
180
Name string `contributesTo:"query" name:"name"`
175
181
When * SDKTime `contributesTo:"query" name:"when"`
176
182
Income float32 `contributesTo:"query" name:"income"`
183
+ Include []inc `contributesTo:"query" name:"includes" collectionFormat:"csv"`
177
184
Male bool `contributesTo:"header" name:"male"`
178
185
Details TestupdateUserDetails `contributesTo:"body"`
179
186
}{
180
- "101" , "tapir" , now (), 3.23 , true , TestupdateUserDetails {Description : desc },
187
+ "101" , "tapir" , now (), 3.23 , includes , true , TestupdateUserDetails {Description : desc },
181
188
}
182
189
request := MakeDefaultHTTPRequest (http .MethodPost , "/" )
183
190
e := HTTPRequestMarshaller (s , & request )
@@ -190,6 +197,7 @@ func TestHttpMarshalerAll(t *testing.T) {
190
197
assert .True (t , request .URL .Query ().Get ("name" ) == s .Name )
191
198
assert .True (t , request .URL .Query ().Get ("income" ) == strconv .FormatFloat (float64 (s .Income ), 'f' , 6 , 32 ))
192
199
assert .True (t , request .URL .Query ().Get ("when" ) == when )
200
+ assert .True (t , request .URL .Query ().Get ("includes" ) == "One,Two" )
193
201
assert .Contains (t , content , "description" )
194
202
assert .Equal (t , request .Header .Get ("Content-Type" ), "application/json" )
195
203
if val , ok := content ["description" ]; ! ok || val != desc {
@@ -678,6 +686,34 @@ func TestEmptyQueryParam(t *testing.T) {
678
686
assert .NotContains (t , r .URL .RawQuery , "meta" )
679
687
}
680
688
689
+ type responseWithWrongCsvType struct {
690
+ Meta string `contributesTo:"query" omitEmpty:"true" name:"meta"`
691
+ QParam string `contributesTo:"query" omitEmpty:"false" name:"qp"`
692
+ QParam2 string `contributesTo:"query" name:"qp2"`
693
+ QParam3 map [string ]string `contributesTo:"query" name:"qp2" collectionFormat:"csv"`
694
+ }
695
+
696
+ func TestWrongTypeQueryParamEncodingWrongType (t * testing.T ) {
697
+ m := make (map [string ]string )
698
+ m ["one" ] = "one"
699
+ s := responseWithWrongCsvType {QParam3 : m }
700
+ _ , err := MakeDefaultHTTPRequestWithTaggedStruct ("GET" , "/" , s )
701
+ assert .Error (t , err )
702
+ }
703
+
704
+ type responseUnsupportedQueryEncoding struct {
705
+ Meta string `contributesTo:"query" omitEmpty:"true" name:"meta"`
706
+ QParam string `contributesTo:"query" omitEmpty:"false" name:"qp"`
707
+ QParam2 string `contributesTo:"query" name:"qp2"`
708
+ QParam3 []string `contributesTo:"query" name:"qp2" collectionFormat:"xml"`
709
+ }
710
+
711
+ func TestWrongTypeQueryParamWrongEncoding (t * testing.T ) {
712
+ s := responseUnsupportedQueryEncoding {QParam3 : []string {"one " , "two" }}
713
+ _ , err := MakeDefaultHTTPRequestWithTaggedStruct ("GET" , "/" , s )
714
+ assert .Error (t , err )
715
+ }
716
+
681
717
func TestOmitFieldsInJson_SimpleStruct (t * testing.T ) {
682
718
type Nested struct {
683
719
N * string `mandatory:"false" json:"n"`
0 commit comments