Repository: gofiber/fiber
File: mount_test.go (Go)

Code before:

	resp, err := app.Test(httptest.NewRequest(MethodGet, "/one/doe", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	resp, err = app.Test(httptest.NewRequest(MethodGet, "/one/two/nested", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	resp, err = app.Test(httptest.NewRequest(MethodGet, "/one/two/three/test", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	utils.AssertEqual(t, uint32(6), app.handlersCount)
	utils.AssertEqual(t, uint32(6), app.routesCount)
}

// go test -run Test_App_Mount_Express_Behavior
func Test_App_Mount_Express_Behavior(t *testing.T) {
	t.Parallel()
	createTestHandler := func(body string) func(c *Ctx) error {
		return func(c *Ctx) error {
			return c.SendString(body)
		}
	}
	testEndpoint := func(app *App, route, expectedBody string, statusCode int) {
		resp, err := app.Test(httptest.NewRequest(MethodGet, route, http.NoBody))
		utils.AssertEqual(t, nil, err, "app.Test(req)")
		body, err := io.ReadAll(resp.Body)
		utils.AssertEqual(t, nil, err)
		utils.AssertEqual(t, statusCode, resp.StatusCode, "Status code")
		utils.AssertEqual(t, expectedBody, string(body), "Unexpected response body")
	}

	app := New()
	subApp := New()
	// app setup
	{
		subApp.Get("/hello", createTestHandler("subapp hello!"))
		subApp.Get("/world", createTestHandler("subapp world!")) // <- wins

		app.Get("/hello", createTestHandler("app hello!")) // <- wins
		app.Mount("/", subApp)                             // <- subApp registration
		app.Get("/world", createTestHandler("app world!"))

		app.Get("/bar", createTestHandler("app bar!"))
		subApp.Get("/bar", createTestHandler("subapp bar!")) // <- wins

		subApp.Get("/foo", createTestHandler("subapp foo!")) // <- wins
		app.Get("/foo", createTestHandler("app foo!"))


Review comment (suggestion):
```suggestion
	testEndpoint := func(app *App, route, expectedBody string, expectedStatusCode int) {
```

Code after:

	resp, err := app.Test(httptest.NewRequest(MethodGet, "/one/doe", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	resp, err = app.Test(httptest.NewRequest(MethodGet, "/one/two/nested", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	resp, err = app.Test(httptest.NewRequest(MethodGet, "/one/two/three/test", http.NoBody))
	utils.AssertEqual(t, nil, err, "app.Test(req)")
	utils.AssertEqual(t, 200, resp.StatusCode, "Status code")

	utils.AssertEqual(t, uint32(6), app.handlersCount)
	utils.AssertEqual(t, uint32(6), app.routesCount)
}

// go test -run Test_App_Mount_Express_Behavior
func Test_App_Mount_Express_Behavior(t *testing.T) {
	t.Parallel()
	createTestHandler := func(body string) func(c *Ctx) error {
		return func(c *Ctx) error {
			return c.SendString(body)
		}
	}
	testEndpoint := func(app *App, route, expectedBody string, expectedStatusCode int) {
		resp, err := app.Test(httptest.NewRequest(MethodGet, route, http.NoBody))
		utils.AssertEqual(t, nil, err, "app.Test(req)")
		body, err := io.ReadAll(resp.Body)
		utils.AssertEqual(t, nil, err)
		utils.AssertEqual(t, expectedStatusCode, resp.StatusCode, "Status code")
		utils.AssertEqual(t, expectedBody, string(body), "Unexpected response body")
	}

	app := New()
	subApp := New()
	// app setup
	{
		subApp.Get("/hello", createTestHandler("subapp hello!"))
		subApp.Get("/world", createTestHandler("subapp world!")) // <- wins

		app.Get("/hello", createTestHandler("app hello!")) // <- wins
		app.Mount("/", subApp)                             // <- subApp registration
		app.Get("/world", createTestHandler("app world!"))

		app.Get("/bar", createTestHandler("app bar!"))
		subApp.Get("/bar", createTestHandler("subapp bar!")) // <- wins

		subApp.Get("/foo", createTestHandler("subapp foo!")) // <- wins
		app.Get("/foo", createTestHandler("app foo!"))