Home / Function/ Test_App_Mount_RoutePositions() — fiber Function Reference

Test_App_Mount_RoutePositions() — fiber Function Reference

Architecture documentation for the Test_App_Mount_RoutePositions() function in mount_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  57dfa679_efd4_27ed_9b7b_5be84b389bf2["Test_App_Mount_RoutePositions()"]
  dbd7cc10_1955_3f67_b103_5ae841223af0["mount_test.go"]
  57dfa679_efd4_27ed_9b7b_5be84b389bf2 -->|defined in| dbd7cc10_1955_3f67_b103_5ae841223af0
  style 57dfa679_efd4_27ed_9b7b_5be84b389bf2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

mount_test.go lines 141–204

func Test_App_Mount_RoutePositions(t *testing.T) {
	t.Parallel()
	testEndpoint := func(app *App, route, expectedBody string) {
		resp, err := app.Test(httptest.NewRequest(MethodGet, route, http.NoBody))
		require.NoError(t, err, "app.Test(req)")
		body, err := io.ReadAll(resp.Body)
		require.NoError(t, err)
		require.Equal(t, StatusOK, resp.StatusCode, "Status code")
		require.Equal(t, expectedBody, string(body), "Unexpected response body")
	}

	app := New()
	subApp1 := New()
	subApp2 := New()
	// app setup
	{
		app.Use(func(c Ctx) error {
			// set initial value
			c.Locals("world", "world")
			return c.Next()
		})
		app.Use("/subApp1", subApp1)
		app.Use(func(c Ctx) error {
			return c.Next()
		})
		app.Get("/bar", func(c Ctx) error {
			return c.SendString("ok")
		})
		app.Use(func(c Ctx) error {
			// is overwritten when the positioning is not correct
			c.Locals("world", "hello")
			return c.Next()
		})
		methods := subApp2.Group("/subApp2")
		methods.Get("/world", func(c Ctx) error {
			v, ok := c.Locals("world").(string)
			if !ok {
				panic("unexpected data type")
			}
			return c.SendString(v)
		})
		app.Use("", subApp2)
	}

	testEndpoint(app, "/subApp2/world", "hello")

	routeStackGET := app.Stack()[0]
	require.True(t, routeStackGET[0].use)
	require.Equal(t, "/", routeStackGET[0].path)

	require.True(t, routeStackGET[1].use)
	require.Equal(t, "/", routeStackGET[1].path)

	require.False(t, routeStackGET[2].use)
	require.Equal(t, "/bar", routeStackGET[2].path)

	require.True(t, routeStackGET[3].use)
	require.Equal(t, "/", routeStackGET[3].path)

	require.False(t, routeStackGET[4].use)
	require.Equal(t, "/subapp2/world", routeStackGET[4].path)

	require.Len(t, routeStackGET, 5)
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_App_Mount_RoutePositions() do?
Test_App_Mount_RoutePositions() is a function in the fiber codebase, defined in mount_test.go.
Where is Test_App_Mount_RoutePositions() defined?
Test_App_Mount_RoutePositions() is defined in mount_test.go at line 141.

Analyze Your Own Codebase

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

Try Supermodel Free