Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

errpage_test.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. assert.Contains(t, respContent, `lang="en-US"`) // make sure the locale work
  26. // the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
  27. // especially when a sub-template causes page error, the HTTP response code is still 200,
  28. // the different "footer" is the only way to know whether a page is fully rendered without error.
  29. assert.False(t, test.IsNormalPageCompleted(respContent))
  30. }
  31. func TestMain(m *testing.M) {
  32. unittest.MainTest(m, &unittest.TestOptions{
  33. GiteaRootPath: filepath.Join("..", ".."),
  34. })
  35. }