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

Code before:
		subApp.Get("/bar", createTestHandler("subapp bar!")) // <- wins

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

		// 404 Handler
		app.Use(func(c *Ctx) error {
			return c.SendStatus(StatusNotFound)
		})
	}
	// expectation check
	testEndpoint(app, "/world", "subapp world!")
	testEndpoint(app, "/hello", "app hello!")
	testEndpoint(app, "/bar", "subapp bar!")
	testEndpoint(app, "/foo", "subapp foo!")
	testEndpoint(app, "/unknown", ErrNotFound.Message)

	utils.AssertEqual(t, uint32(17), app.handlersCount)
	utils.AssertEqual(t, uint32(16+9), app.routesCount)
}

// go test -run Test_App_Mount_RoutePositions
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, nil))
		utils.AssertEqual(t, nil, err, "app.Test(req)")
		body, err := io.ReadAll(resp.Body)
		utils.AssertEqual(t, nil, err)
		utils.AssertEqual(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.Mount("/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 in case the positioning is not correct

Review comment (suggestion):
```suggestion
		resp, err := app.Test(httptest.NewRequest(MethodGet, route, http.NoBody))
```

This should have been caught by golangci-lint.

Code after:

		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!"))

		// 404 Handler
		app.Use(func(c *Ctx) error {
			return c.SendStatus(StatusNotFound)
		})
	}
	// expectation check
	testEndpoint(app, "/world", "subapp world!", StatusOK)
	testEndpoint(app, "/hello", "app hello!", StatusOK)
	testEndpoint(app, "/bar", "subapp bar!", StatusOK)
	testEndpoint(app, "/foo", "subapp foo!", StatusOK)
	testEndpoint(app, "/unknown", ErrNotFound.Message, StatusNotFound)

	utils.AssertEqual(t, uint32(17), app.handlersCount)
	utils.AssertEqual(t, uint32(16+9), app.routesCount)
}

// go test -run Test_App_Mount_RoutePositions
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))
		utils.AssertEqual(t, nil, err, "app.Test(req)")
		body, err := io.ReadAll(resp.Body)
		utils.AssertEqual(t, nil, err)
		utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code")
		utils.AssertEqual(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.Mount("/subApp1", subApp1)
		app.Use(func(c *Ctx) error {
			return c.Next()
		})
		app.Get("/bar", func(c *Ctx) error {
			return c.SendString("ok")