MCPcopy Index your code
hub / github.com/php/frankenphp / testFileUpload

Function testFileUpload

frankenphp_test.go:787–804  ·  view source on GitHub ↗
(t *testing.T, opts *testOptions)

Source from the content-addressed store, hash-verified

785 testFileUpload(t, &testOptions{workerScript: "file-upload.php"})
786}
787func 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
806func ExampleServeHTTP() {
807 if err := frankenphp.Init(); err != nil {

Callers 2

TestFileUpload_moduleFunction · 0.85
TestFileUpload_workerFunction · 0.85

Calls 4

runTestFunction · 0.85
testRequestFunction · 0.85
CloseMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected