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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. "path/filepath"
  11. "testing"
  12. "code.gitea.io/gitea/models/unittest"
  13. "code.gitea.io/gitea/modules/test"
  14. "code.gitea.io/gitea/modules/web/middleware"
  15. "github.com/stretchr/testify/assert"
  16. )
  17. func TestRenderPanicErrorPage(t *testing.T) {
  18. w := httptest.NewRecorder()
  19. req := &http.Request{URL: &url.URL{}}
  20. req = req.WithContext(middleware.WithContextData(context.Background()))
  21. RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
  22. respContent := w.Body.String()
  23. assert.Contains(t, respContent, `class="page-content status-page-500"`)
  24. assert.Contains(t, respContent, `</html>`)
  25. // the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
  26. // especially when a sub-template causes page error, the HTTP response code is still 200,
  27. // the different "footer" is the only way to know whether a page is fully rendered without error.
  28. assert.False(t, test.IsNormalPageCompleted(respContent))
  29. }
  30. func TestMain(m *testing.M) {
  31. unittest.MainTest(m, &unittest.TestOptions{
  32. GiteaRootPath: filepath.Join("..", ".."),
  33. })
  34. }