github.com/abemedia/go-don@v0.2.2-0.20240329015135-be88e32bb73b/encoding/form/form_test.go (about)

     1  package form_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/abemedia/go-don/internal/test"
     7  )
     8  
     9  func TestForm(t *testing.T) {
    10  	type item struct {
    11  		Foo string `form:"foo"`
    12  	}
    13  
    14  	t.Run("URLEncoded", func(t *testing.T) {
    15  		test.Decode(t, test.EncodingOptions[item]{
    16  			Mime:   "application/x-www-form-urlencoded",
    17  			Raw:    "foo=bar",
    18  			Parsed: item{Foo: "bar"},
    19  		})
    20  	})
    21  
    22  	t.Run("Multipart", func(t *testing.T) {
    23  		test.Decode(t, test.EncodingOptions[item]{
    24  			Mime:   `multipart/form-data;boundary="boundary"`,
    25  			Raw:    "--boundary\nContent-Disposition: form-data; name=\"foo\"\n\nbar\n--boundary\n",
    26  			Parsed: item{Foo: "bar"},
    27  		})
    28  	})
    29  }