@@ -429,6 +429,62 @@ func TestBindUnsupportedMediaType(t *testing.T) {
429429 testBindError (t , strings .NewReader (invalidContent ), MIMEApplicationJSON , & json.SyntaxError {})
430430}
431431
432+ func TestDefaultBinder_bindDataToMap (t * testing.T ) {
433+ exampleData := map [string ][]string {
434+ "multiple" : {"1" , "2" },
435+ "single" : {"3" },
436+ }
437+
438+ t .Run ("ok, bind to map[string]string" , func (t * testing.T ) {
439+ dest := map [string ]string {}
440+ assert .NoError (t , new (DefaultBinder ).bindData (& dest , exampleData , "param" ))
441+ assert .Equal (t ,
442+ map [string ]string {
443+ "multiple" : "1" ,
444+ "single" : "3" ,
445+ },
446+ dest ,
447+ )
448+ })
449+
450+ t .Run ("ok, bind to map[string][]string" , func (t * testing.T ) {
451+ dest := map [string ][]string {}
452+ assert .NoError (t , new (DefaultBinder ).bindData (& dest , exampleData , "param" ))
453+ assert .Equal (t ,
454+ map [string ][]string {
455+ "multiple" : {"1" , "2" },
456+ "single" : {"3" },
457+ },
458+ dest ,
459+ )
460+ })
461+
462+ t .Run ("ok, bind to map[string]interface" , func (t * testing.T ) {
463+ dest := map [string ]interface {}{}
464+ assert .NoError (t , new (DefaultBinder ).bindData (& dest , exampleData , "param" ))
465+ assert .Equal (t ,
466+ map [string ]interface {}{
467+ "multiple" : []string {"1" , "2" },
468+ "single" : []string {"3" },
469+ },
470+ dest ,
471+ )
472+ })
473+
474+ t .Run ("ok, bind to map[string]int skips" , func (t * testing.T ) {
475+ dest := map [string ]int {}
476+ assert .NoError (t , new (DefaultBinder ).bindData (& dest , exampleData , "param" ))
477+ assert .Equal (t , map [string ]int {}, dest )
478+ })
479+
480+ t .Run ("ok, bind to map[string][]int skips" , func (t * testing.T ) {
481+ dest := map [string ][]int {}
482+ assert .NoError (t , new (DefaultBinder ).bindData (& dest , exampleData , "param" ))
483+ assert .Equal (t , map [string ][]int {}, dest )
484+ })
485+
486+ }
487+
432488func TestBindbindData (t * testing.T ) {
433489 ts := new (bindTestStruct )
434490 b := new (DefaultBinder )
0 commit comments