Home / Function/ Test_Ctx_SaveFileToStorage_ContextPropagation() — fiber Function Reference

Test_Ctx_SaveFileToStorage_ContextPropagation() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

ctx_test.go lines 4853–4904

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

	type ctxKeyType string

	const ctxKey ctxKeyType = "storage-context-key"

	storage := &mockContextAwareStorage{t: t, key: ctxKey, expectedValue: "expected-context-value"}
	app := New()

	app.Post("/test", func(c Ctx) error {
		fh, err := c.FormFile("file")
		require.NoError(t, err)

		ctxWithValue := context.WithValue(context.Background(), ctxKey, storage.expectedValue)
		ctx, cancel := context.WithCancel(ctxWithValue)
		storage.validateCtx = func(received context.Context) {
			if received != ctx {
				storage.helperFailure("storage received unexpected context instance")
			}
		}
		storage.cancel = cancel

		c.SetContext(ctx)

		err = c.SaveFileToStorage(fh, "test", storage)
		require.NoError(t, err)

		require.True(t, storage.ctxMatched.Load(), "storage should receive the context installed on Ctx")
		require.True(t, storage.cancelObserved.Load(), "storage should observe context cancellation")

		return nil
	})

	body := &bytes.Buffer{}
	writer := multipart.NewWriter(body)

	ioWriter, err := writer.CreateFormFile("file", "test")
	require.NoError(t, err)

	_, err = ioWriter.Write([]byte("hello world"))
	require.NoError(t, err)
	require.NoError(t, writer.Close())

	req := httptest.NewRequest(MethodPost, "/test", body)
	req.Header.Set("Content-Type", writer.FormDataContentType())
	req.Header.Set("Content-Length", strconv.Itoa(len(body.Bytes())))

	resp, err := app.Test(req)
	require.NoError(t, err, "app.Test(req)")
	require.Equal(t, StatusOK, resp.StatusCode, "Status code")
}

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free