Home / Function/ Test_Ctx_SendFile_Multiple() — fiber Function Reference

Test_Ctx_SendFile_Multiple() — fiber Function Reference

Architecture documentation for the Test_Ctx_SendFile_Multiple() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  a87bf245_294f_7b1b_64f7_ff95a10ab862["Test_Ctx_SendFile_Multiple()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  a87bf245_294f_7b1b_64f7_ff95a10ab862 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style a87bf245_294f_7b1b_64f7_ff95a10ab862 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 5472–5528

func Test_Ctx_SendFile_Multiple(t *testing.T) {
	t.Parallel()

	app := New()
	app.Get("/test", func(c Ctx) error {
		switch c.Query("file") {
		case "1":
			return c.SendFile("ctx.go")
		case "2":
			return c.SendFile("app.go")
		case "3":
			return c.SendFile("ctx.go", SendFile{
				Download: true,
			})
		case "4":
			return c.SendFile("app_test.go", SendFile{
				FS: os.DirFS("."),
			})
		default:
			return c.SendStatus(StatusNotFound)
		}
	})

	app.Get("/test2", func(c Ctx) error {
		return c.SendFile("ctx.go", SendFile{
			Download: true,
		})
	})

	testCases := []struct {
		url                string
		body               string
		contentDisposition string
	}{
		{url: "/test?file=1", body: "type DefaultCtx struct", contentDisposition: ""},
		{url: "/test?file=2", body: "type App struct", contentDisposition: ""},
		{url: "/test?file=3", body: "type DefaultCtx struct", contentDisposition: "attachment"},
		{url: "/test?file=4", body: "Test_App_MethodNotAllowed", contentDisposition: ""},
		{url: "/test2", body: "type DefaultCtx struct", contentDisposition: "attachment"},
		{url: "/test2", body: "type DefaultCtx struct", contentDisposition: "attachment"},
	}

	for _, tc := range testCases {
		resp, err := app.Test(httptest.NewRequest(MethodGet, tc.url, http.NoBody))
		require.NoError(t, err)
		require.Equal(t, StatusOK, resp.StatusCode)
		require.Equal(t, tc.contentDisposition, resp.Header.Get(HeaderContentDisposition))

		body, err := io.ReadAll(resp.Body)
		require.NoError(t, err)
		require.Contains(t, string(body), tc.body)
	}

	app.sendfilesMutex.RLock()
	defer app.sendfilesMutex.RUnlock()
	require.Len(t, app.sendfiles, 3)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Ctx_SendFile_Multiple() do?
Test_Ctx_SendFile_Multiple() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_SendFile_Multiple() defined?
Test_Ctx_SendFile_Multiple() is defined in ctx_test.go at line 5472.

Analyze Your Own Codebase

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

Try Supermodel Free