You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errpage_test.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package common
  4. import (
  5. "context"
  6. "errors"
  7. "net/http"
  8. "net/http/httptest"
  9. "net/url"
  10. "testing"
  11. "code.gitea.io/gitea/models/unittest"
  12. "code.gitea.io/gitea/modules/test"
  13. "code.gitea.io/gitea/modules/web/middleware"
  14. "github.com/stretchr/testify/assert"
  15. )
  16. func TestRenderPanicErrorPage(t *testing.T) {
  17. w := httptest.NewRecorder()
  18. req := &http.Request{URL: &url.URL{}}
  19. req = req.WithContext(middleware.WithContextData(context.Background()))
  20. RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
  21. respContent := w.Body.String()
  22. assert.Contains(t, respContent, `class="page-content status-page-500"`)
  23. assert.Contains(t, respContent, `</html>`)
  24. // the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
  25. // especially when a sub-template causes page error, the HTTP response code is still 200,
  26. // the different "footer" is the only way to know whether a page is fully rendered without error.
  27. assert.False(t, test.IsNormalPageCompleted(respContent))
  28. }
  29. func TestMain(m *testing.M) {
  30. unittest.MainTest(m)
  31. }