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