loading up the forgejo repo on tangled to test page performance
at forgejo 53 lines 1.8 kB view raw
1// Copyright 2025 The Forgejo Authors. All rights reserved. 2// SPDX-License-Identifier: GPL-3.0-or-later 3 4package integration 5 6import ( 7 "net/http" 8 "testing" 9 10 "forgejo.org/modules/setting" 11 "forgejo.org/modules/test" 12 "forgejo.org/routers" 13 14 "github.com/stretchr/testify/assert" 15) 16 17// `/devtest/error/{errcode}` provides a convenient way of testing various 18// error pages sometimes which can be hard to reach otherwise. 19// This file is a test of various attributes on those pages. 20 21func TestDevtestErrorpages(t *testing.T) { 22 defer test.MockVariableValue(&setting.IsProd, false)() 23 defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())() 24 25 t.Run("Server error", func(t *testing.T) { 26 // `/devtest/error/x` returns 500 for any x by default. 27 // `/500` is simply for good look here 28 req := NewRequest(t, "GET", "/devtest/error/500") 29 resp := MakeRequest(t, req, http.StatusInternalServerError) 30 doc := NewHTMLParser(t, resp.Body) 31 assert.Equal(t, "500", doc.Find(".error-code").Text()) 32 assert.Contains(t, doc.Find("head title").Text(), "Internal server error") 33 }) 34 35 t.Run("Page not found", 36 func(t *testing.T) { 37 req := NewRequest(t, "GET", "/devtest/error/404"). 38 // Without this header `notFoundInternal` returns plaintext error message 39 SetHeader("Accept", "text/html") 40 resp := MakeRequest(t, req, http.StatusNotFound) 41 doc := NewHTMLParser(t, resp.Body) 42 assert.Equal(t, "404", doc.Find(".error-code").Text()) 43 assert.Contains(t, doc.Find("head title").Text(), "Page not found") 44 }) 45 46 t.Run("Quota exhaustion", 47 func(t *testing.T) { 48 req := NewRequest(t, "GET", "/devtest/error/413") 49 resp := MakeRequest(t, req, http.StatusRequestEntityTooLarge) 50 doc := NewHTMLParser(t, resp.Body) 51 assert.Equal(t, "413", doc.Find(".error-code").Text()) 52 }) 53}