(t *testing.T, opts *testOptions)
| 785 | testFileUpload(t, &testOptions{workerScript: "file-upload.php"}) |
| 786 | } |
| 787 | func testFileUpload(t *testing.T, opts *testOptions) { |
| 788 | runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) { |
| 789 | requestBody := &bytes.Buffer{} |
| 790 | writer := multipart.NewWriter(requestBody) |
| 791 | part, _ := writer.CreateFormFile("file", "foo.txt") |
| 792 | _, err := part.Write([]byte("bar")) |
| 793 | require.NoError(t, err) |
| 794 | |
| 795 | require.NoError(t, writer.Close()) |
| 796 | |
| 797 | req := httptest.NewRequest("POST", "http://example.com/file-upload.php", requestBody) |
| 798 | req.Header.Add("Content-Type", writer.FormDataContentType()) |
| 799 | |
| 800 | body, _ := testRequest(req, handler, t) |
| 801 | |
| 802 | assert.Contains(t, string(body), "Upload OK") |
| 803 | }, opts) |
| 804 | } |
| 805 | |
| 806 | func ExampleServeHTTP() { |
| 807 | if err := frankenphp.Init(); err != nil { |
no test coverage detected