mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-18 10:29:43 +00:00
42d5802b9b
This try to address #115 Co-authored-by: Simon Vieille <simon@deblan.fr> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/125 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: deblan <deblan@noreply.codeberg.org> Co-committed-by: deblan <deblan@noreply.codeberg.org>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"codeberg.org/codeberg/pages/server/cache"
|
|
"codeberg.org/codeberg/pages/server/gitea"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func TestHandlerPerformance(t *testing.T) {
|
|
giteaClient, _ := gitea.NewClient("https://codeberg.org", "", cache.NewKeyValueCache(), false, false)
|
|
testHandler := Handler(
|
|
"codeberg.page", "raw.codeberg.org",
|
|
giteaClient,
|
|
"https://docs.codeberg.org/pages/raw-content/",
|
|
[]string{"/.well-known/acme-challenge/"},
|
|
[]string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"},
|
|
[]string{"pages"},
|
|
cache.NewKeyValueCache(),
|
|
cache.NewKeyValueCache(),
|
|
)
|
|
|
|
testCase := func(uri string, status int) {
|
|
t.Run(uri, func(t *testing.T) {
|
|
req := httptest.NewRequest("GET", uri, nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
log.Printf("Start: %v\n", time.Now())
|
|
start := time.Now()
|
|
testHandler(w, req)
|
|
end := time.Now()
|
|
log.Printf("Done: %v\n", time.Now())
|
|
|
|
resp := w.Result()
|
|
|
|
if resp.StatusCode != status {
|
|
t.Errorf("request failed with status code %d", resp.StatusCode)
|
|
} else {
|
|
t.Logf("request took %d milliseconds", end.Sub(start).Milliseconds())
|
|
}
|
|
})
|
|
}
|
|
|
|
testCase("https://mondstern.codeberg.page/", 404) // TODO: expect 200
|
|
testCase("https://codeberg.page/", 404) // TODO: expect 200
|
|
testCase("https://example.momar.xyz/", 424)
|
|
}
|