From 913f762eb0b4bce42e74b921dd2788ca8c0da7e9 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.codeberg.org> Date: Mon, 13 Jun 2022 14:43:49 +0200 Subject: [PATCH] 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 --- Justfile | 6 ++++++ integration/get_test.go | 18 +++++++++++++++--- integration/main_test.go | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Justfile b/Justfile index c5c5a08..720c0f1 100644 --- a/Justfile +++ b/Justfile @@ -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/... diff --git a/integration/get_test.go b/integration/get_test.go index ef00531..973b049 100644 --- a/integration/get_test.go +++ b/integration/get_test.go @@ -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) diff --git a/integration/main_test.go b/integration/main_test.go index 43f6792..8104413 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -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)