@@ -28,9 +28,10 @@ type TestupdateUserDetails struct {
2828}
2929
3030type 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"`
3435}
3536
3637type updateUserRequest struct {
@@ -69,13 +70,15 @@ func TestHttpMarshallerInvalidStruct(t *testing.T) {
6970}
7071
7172func 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" } }
7374 request := MakeDefaultHTTPRequest (http .MethodPost , "/" )
74- HTTPRequestMarshaller (s , & request )
75+ e := HTTPRequestMarshaller (s , & request )
7576 query := request .URL .Query ()
77+ assert .NoError (t , e )
7678 assert .True (t , query .Get ("compartmentId" ) == "ocid1" )
7779 assert .True (t , query .Get ("page" ) == "p" )
7880 assert .True (t , query .Get ("limit" ) == "23" )
81+ assert .True (t , query .Get ("fields" ) == "one,two,three" )
7982}
8083
8184func TestMakeDefault (t * testing.T ) {
@@ -169,15 +172,19 @@ func TestHttpMarshallerEmptyPath(t *testing.T) {
169172
170173func TestHttpMarshalerAll (t * testing.T ) {
171174 desc := "theDescription"
175+ type inc string
176+ includes := []inc {inc ("One" ), inc ("Two" )}
177+
172178 s := struct {
173179 ID string `contributesTo:"path"`
174180 Name string `contributesTo:"query" name:"name"`
175181 When * SDKTime `contributesTo:"query" name:"when"`
176182 Income float32 `contributesTo:"query" name:"income"`
183+ Include []inc `contributesTo:"query" name:"includes" collectionFormat:"csv"`
177184 Male bool `contributesTo:"header" name:"male"`
178185 Details TestupdateUserDetails `contributesTo:"body"`
179186 }{
180- "101" , "tapir" , now (), 3.23 , true , TestupdateUserDetails {Description : desc },
187+ "101" , "tapir" , now (), 3.23 , includes , true , TestupdateUserDetails {Description : desc },
181188 }
182189 request := MakeDefaultHTTPRequest (http .MethodPost , "/" )
183190 e := HTTPRequestMarshaller (s , & request )
@@ -190,6 +197,7 @@ func TestHttpMarshalerAll(t *testing.T) {
190197 assert .True (t , request .URL .Query ().Get ("name" ) == s .Name )
191198 assert .True (t , request .URL .Query ().Get ("income" ) == strconv .FormatFloat (float64 (s .Income ), 'f' , 6 , 32 ))
192199 assert .True (t , request .URL .Query ().Get ("when" ) == when )
200+ assert .True (t , request .URL .Query ().Get ("includes" ) == "One,Two" )
193201 assert .Contains (t , content , "description" )
194202 assert .Equal (t , request .Header .Get ("Content-Type" ), "application/json" )
195203 if val , ok := content ["description" ]; ! ok || val != desc {
@@ -678,6 +686,34 @@ func TestEmptyQueryParam(t *testing.T) {
678686 assert .NotContains (t , r .URL .RawQuery , "meta" )
679687}
680688
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+
681717func TestOmitFieldsInJson_SimpleStruct (t * testing.T ) {
682718 type Nested struct {
683719 N * string `mandatory:"false" json:"n"`
0 commit comments