Repository: traefik/traefik
File: integration/error_pages_test.go (Go)

Code before:
	require.NoError(s.T(), err)
	frontendReq.Host = "test.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("nginx"))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestErrorPage() {
	// error.toml contains a mis-configuration of the backend host
	file := s.adaptFile("fixtures/error_pages/error.toml", struct {
		Server1 string
		Server2 string
	}{s.BackendIP, s.ErrorPageIP})

	s.traefikCmd(withConfigFile(file))

	frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestRewriteStatus() {
	// rewriteStatus.toml contains a mis-configuration of the backend host and some rewrites for the status code
	file := s.adaptFile("fixtures/error_pages/rewriteStatus.toml", struct {
		Server1 string
		Server2 string
	}{s.BackendIP, s.ErrorPageIP})

	s.traefikCmd(withConfigFile(file))

	frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test502.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(404))
	require.NoError(s.T(), err)

	frontendReq, err = http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test418.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(400))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestErrorPageFlush() {
	srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		rw.Header().Add("Transfer-Encoding", "chunked")

Review comment (suggestion):
```suggestion
	// The `rewriteStatus.toml` file contains a misconfigured backend host and some status code rewrites.
```

Code after:
	require.NoError(s.T(), err)
	frontendReq.Host = "test.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("nginx"))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestErrorPage() {
	// error.toml contains a mis-configuration of the backend host
	file := s.adaptFile("fixtures/error_pages/error.toml", struct {
		Server1 string
		Server2 string
	}{s.BackendIP, s.ErrorPageIP})

	s.traefikCmd(withConfigFile(file))

	frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestStatusRewrites() {
	// The `statusRewrites.toml` file contains a misconfigured backend host and some status code rewrites.
	file := s.adaptFile("fixtures/error_pages/statusRewrites.toml", struct {
		Server1 string
		Server2 string
	}{s.BackendIP, s.ErrorPageIP})

	s.traefikCmd(withConfigFile(file))

	frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test502.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(404))
	require.NoError(s.T(), err)

	frontendReq, err = http.NewRequest(http.MethodGet, "http://127.0.0.1:8080", nil)
	require.NoError(s.T(), err)
	frontendReq.Host = "test418.local"

	err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."), try.StatusCodeIs(400))
	require.NoError(s.T(), err)
}

func (s *ErrorPagesSuite) TestErrorPageFlush() {
	srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		rw.Header().Add("Transfer-Encoding", "chunked")