MCPcopy
hub / github.com/valyala/fasthttp / testRequestMultipartFormPipeEmptyFormField

Function testRequestMultipartFormPipeEmptyFormField

http_test.go:3658–3699  ·  view source on GitHub ↗
(t *testing.T, boundary string, formData []byte, partsCount int)

Source from the content-addressed store, hash-verified

3656}
3657
3658func testRequestMultipartFormPipeEmptyFormField(t *testing.T, boundary string, formData []byte, partsCount int) []byte {
3659 s := fmt.Sprintf("POST / HTTP/1.1\r\nHost: aaa\r\nContent-Type: multipart/form-data; boundary=%s\r\nTransfer-Encoding: chunked\r\n\r\n%s",
3660 boundary, formData)
3661
3662 var req Request
3663
3664 r := bytes.NewBufferString(s)
3665 br := bufio.NewReader(r)
3666 if err := req.Read(br); err != nil {
3667 t.Fatalf("unexpected error: %v", err)
3668 }
3669
3670 f, err := req.MultipartForm()
3671 if err != nil {
3672 t.Fatalf("unexpected error: %v", err)
3673 }
3674 defer req.RemoveMultipartFormFiles()
3675
3676 if len(f.File) > 0 {
3677 t.Fatalf("unexpected files found in the multipart form: %d", len(f.File))
3678 }
3679
3680 if len(f.Value) != partsCount {
3681 t.Fatalf("unexpected number of values found: %d. Expecting %d", len(f.Value), partsCount)
3682 }
3683
3684 for k, vv := range f.Value {
3685 if len(vv) != 1 {
3686 t.Fatalf("unexpected number of values found for key=%q: %d. Expecting 1", k, len(vv))
3687 }
3688 if k != "emptyField" {
3689 t.Fatalf("unexpected key=%q. Expecting %q", k, "emptyField")
3690 }
3691
3692 v := vv[0]
3693 if v != "" {
3694 t.Fatalf("unexpected value=%q. expecting %q", v, "")
3695 }
3696 }
3697
3698 return req.Body()
3699}
3700
3701func TestReqCopeToRace(t *testing.T) {
3702 req := AcquireRequest()

Calls 5

ReadMethod · 0.95
MultipartFormMethod · 0.95
BodyMethod · 0.95
NewReaderMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…