Home / Function/ Test_App_DisablePreParseMultipartForm() — fiber Function Reference

Test_App_DisablePreParseMultipartForm() — fiber Function Reference

Architecture documentation for the Test_App_DisablePreParseMultipartForm() function in app_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  891790ec_d4b1_ca1a_c468_8f6848afdd0a["Test_App_DisablePreParseMultipartForm()"]
  e728fdd2_242f_706b_c1d2_041b3d6badb5["app_test.go"]
  891790ec_d4b1_ca1a_c468_8f6848afdd0a -->|defined in| e728fdd2_242f_706b_c1d2_041b3d6badb5
  style 891790ec_d4b1_ca1a_c468_8f6848afdd0a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

app_test.go lines 2361–2407

func Test_App_DisablePreParseMultipartForm(t *testing.T) {
	t.Parallel()
	// Must be used with both otherwise there is no point.
	testString := "this is a test"

	app := New(Config{DisablePreParseMultipartForm: true, StreamRequestBody: true})
	app.Post("/", func(c Ctx) error {
		req := c.Request()
		mpf, err := req.MultipartForm()
		if err != nil {
			return err
		}
		if !req.IsBodyStream() {
			return errors.New("not a body stream")
		}
		file, err := mpf.File["test"][0].Open()
		if err != nil {
			return fmt.Errorf("failed to open: %w", err)
		}
		buffer := make([]byte, len(testString))
		n, err := file.Read(buffer)
		if err != nil {
			return fmt.Errorf("failed to read: %w", err)
		}
		if n != len(testString) {
			return errors.New("bad read length")
		}
		return c.Send(buffer)
	})
	b := &bytes.Buffer{}
	w := multipart.NewWriter(b)
	writer, err := w.CreateFormFile("test", "test")
	require.NoError(t, err, "w.CreateFormFile")
	n, err := writer.Write([]byte(testString))
	require.NoError(t, err, "writer.Write")
	require.Len(t, testString, n, "writer n")
	require.NoError(t, w.Close(), "w.Close()")

	req := httptest.NewRequest(MethodPost, "/", b)
	req.Header.Set("Content-Type", w.FormDataContentType())
	resp, err := app.Test(req)
	require.NoError(t, err, "app.Test(req)")
	body, err := io.ReadAll(resp.Body)
	require.NoError(t, err, "io.ReadAll(resp.Body)")

	require.Equal(t, testString, string(body))
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_App_DisablePreParseMultipartForm() do?
Test_App_DisablePreParseMultipartForm() is a function in the fiber codebase, defined in app_test.go.
Where is Test_App_DisablePreParseMultipartForm() defined?
Test_App_DisablePreParseMultipartForm() is defined in app_test.go at line 2361.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free