Add integration test for custom domain (#90)

and some nits

---
close #89

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/90
This commit is contained in:
6543 2022-06-13 14:43:49 +02:00
parent 38fb28f84f
commit 913f762eb0
3 changed files with 23 additions and 5 deletions

View file

@ -27,3 +27,9 @@ tool-gofumpt:
@hash gofumpt> /dev/null 2>&1; if [ $? -ne 0 ]; then \
go install mvdan.cc/gofumpt@latest; \
fi
test:
go test -race codeberg.org/codeberg/pages/server/...
integration:
go test -race -tags integration codeberg.org/codeberg/pages/integration/...

View file

@ -16,7 +16,7 @@ import (
)
func TestGetRedirect(t *testing.T) {
log.Printf("== TestGetRedirect ==\n")
log.Printf("=== TestGetRedirect ===\n")
// test custom domain redirect
resp, err := getTestHTTPSClient().Get("https://calciumdibromid.localhost.mock.directory:4430")
assert.NoError(t, err)
@ -28,7 +28,7 @@ func TestGetRedirect(t *testing.T) {
}
func TestGetContent(t *testing.T) {
log.Printf("== TestGetContent ==\n")
log.Printf("=== TestGetContent ===\n")
// test get image
resp, err := getTestHTTPSClient().Get("https://magiclike.localhost.mock.directory:4430/images/827679288a.jpg")
assert.NoError(t, err)
@ -49,8 +49,20 @@ func TestGetContent(t *testing.T) {
assert.True(t, getSize(resp.Body) > 1000)
}
func TestCustomDomain(t *testing.T) {
log.Printf("=== TestCustomDomain ===\n")
resp, err := getTestHTTPSClient().Get("https://mock-pages.codeberg-test.org:4430/README.md")
assert.NoError(t, err)
if !assert.EqualValues(t, http.StatusOK, resp.StatusCode) {
t.FailNow()
}
assert.EqualValues(t, "text/markdown; charset=utf-8", resp.Header["Content-Type"][0])
assert.EqualValues(t, "106", resp.Header["Content-Length"][0])
assert.EqualValues(t, 106, getSize(resp.Body))
}
func TestGetNotFound(t *testing.T) {
log.Printf("== TestGetNotFound ==\n")
log.Printf("=== TestGetNotFound ===\n")
// test custom not found pages
resp, err := getTestHTTPSClient().Get("https://crystal.localhost.mock.directory:4430/pages-404-demo/blah")
assert.NoError(t, err)

View file

@ -16,14 +16,14 @@ import (
)
func TestMain(m *testing.M) {
log.Printf("=== TestMain: START Server ==\n")
log.Printf("=== TestMain: START Server ===\n")
serverCtx, serverCancel := context.WithCancel(context.Background())
if err := startServer(serverCtx); err != nil {
log.Fatal().Msgf("could not start server: %v", err)
}
defer func() {
serverCancel()
log.Printf("=== TestMain: Server STOPED ==\n")
log.Printf("=== TestMain: Server STOPED ===\n")
}()
time.Sleep(20 * time.Second)