diff options
author | Wolfy-J <[email protected]> | 2018-06-13 20:54:38 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-13 20:54:38 +0300 |
commit | c1649e34f4ea19f462cc68dd63bfe47de24b95e5 (patch) | |
tree | 896ca2fc20cf54394c2422b3404a98d1171b0d23 /service | |
parent | fba45ff53a51bf173471e6d046fc46f0cbaf89e3 (diff) |
nested uploads test
Diffstat (limited to 'service')
-rw-r--r-- | service/http/uploads_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/service/http/uploads_test.go b/service/http/uploads_test.go index c3dad6be..af351067 100644 --- a/service/http/uploads_test.go +++ b/service/http/uploads_test.go @@ -78,6 +78,68 @@ func TestServer_Upload_File(t *testing.T) { assert.Equal(t, `{"upload":`+fs+`}`, string(b)) } +func TestServer_Upload_NestedFile(t *testing.T) { + st := &Handler{ + cfg: &Config{ + MaxRequest: 1024, + Uploads: &UploadsConfig{ + Dir: os.TempDir(), + Forbid: []string{}, + }, + }, + rr: roadrunner.NewServer(&roadrunner.ServerConfig{ + Command: "php ../../php-src/tests/http/client.php upload pipes", + Relay: "pipes", + Pool: &roadrunner.Config{ + NumWorkers: 1, + AllocateTimeout: 10000000, + DestroyTimeout: 10000000, + }, + }), + } + + assert.NoError(t, st.rr.Start()) + defer st.rr.Stop() + + hs := &http.Server{Addr: ":8021", Handler: st,} + defer hs.Shutdown(context.Background()) + + go func() { hs.ListenAndServe() }() + time.Sleep(time.Millisecond * 10) + + var mb bytes.Buffer + w := multipart.NewWriter(&mb) + + f := mustOpen("uploads_test.go") + defer f.Close() + fw, err := w.CreateFormFile("upload[x][y][z][]", f.Name()) + assert.NotNil(t, fw) + assert.NoError(t, err) + io.Copy(fw, f) + + w.Close() + + req, err := http.NewRequest("POST", "http://localhost"+hs.Addr, &mb) + assert.NoError(t, err) + + req.Header.Set("Content-Type", w.FormDataContentType()) + + r, err := http.DefaultClient.Do(req) + assert.NoError(t, err) + defer r.Body.Close() + + b, err := ioutil.ReadAll(r.Body) + assert.NoError(t, err) + + assert.NoError(t, err) + assert.Equal(t, 200, r.StatusCode) + + fs := fileString("uploads_test.go", 0, "application/octet-stream") + + assert.Equal(t, `{"upload":{"x":{"y":{"z":[`+fs+`]}}}}`, string(b)) +} + + func TestServer_Upload_File_NoTmpDir(t *testing.T) { st := &Handler{ cfg: &Config{ |