Home / Function/ Test_Static_Next() — fiber Function Reference

Test_Static_Next() — fiber Function Reference

Architecture documentation for the Test_Static_Next() function in static_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  4a7af2ab_ca1a_28a0_120d_98810d40fc25["Test_Static_Next()"]
  f26a2d79_1e01_f027_82eb_45c4308747e8["static_test.go"]
  4a7af2ab_ca1a_28a0_120d_98810d40fc25 -->|defined in| f26a2d79_1e01_f027_82eb_45c4308747e8
  style 4a7af2ab_ca1a_28a0_120d_98810d40fc25 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/static/static_test.go lines 399–442

func Test_Static_Next(t *testing.T) {
	t.Parallel()
	app := fiber.New()

	app.Get("/*", New("../../.github", Config{
		Next: func(c fiber.Ctx) bool {
			return c.Get("X-Custom-Header") == "skip"
		},
	}))

	app.Get("/*", func(c fiber.Ctx) error {
		return c.SendString("You've skipped app.Static")
	})

	t.Run("app.Static is skipped: invoking Get handler", func(t *testing.T) {
		t.Parallel()
		req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
		req.Header.Set("X-Custom-Header", "skip")
		resp, err := app.Test(req)
		require.NoError(t, err)
		require.Equal(t, 200, resp.StatusCode)
		require.NotEmpty(t, resp.Header.Get(fiber.HeaderContentLength))
		require.Equal(t, fiber.MIMETextPlainCharsetUTF8, resp.Header.Get(fiber.HeaderContentType))

		body, err := io.ReadAll(resp.Body)
		require.NoError(t, err)
		require.Contains(t, string(body), "You've skipped app.Static")
	})

	t.Run("app.Static is not skipped: serving index.html", func(t *testing.T) {
		t.Parallel()
		req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
		req.Header.Set("X-Custom-Header", "don't skip")
		resp, err := app.Test(req)
		require.NoError(t, err)
		require.Equal(t, 200, resp.StatusCode)
		require.NotEmpty(t, resp.Header.Get(fiber.HeaderContentLength))
		require.Equal(t, fiber.MIMETextHTMLCharsetUTF8, resp.Header.Get(fiber.HeaderContentType))

		body, err := io.ReadAll(resp.Body)
		require.NoError(t, err)
		require.Contains(t, string(body), "Hello, World!")
	})
}

Domain

Subdomains

Frequently Asked Questions

What does Test_Static_Next() do?
Test_Static_Next() is a function in the fiber codebase, defined in middleware/static/static_test.go.
Where is Test_Static_Next() defined?
Test_Static_Next() is defined in middleware/static/static_test.go at line 399.

Analyze Your Own Codebase

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

Try Supermodel Free