From 0acfbd393b19aaaf30439c25fcacf8dae2a875b5 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 17 Jul 2022 07:35:39 +0200 Subject: [PATCH] Fix and reenable automatic tests --- .github/workflows/master.yml | 12 ++++++------ activityPub_test.go | 3 +++ app_test.go | 7 +++++++ authentication_test.go | 2 ++ blogroll_test.go | 2 ++ blogstats_test.go | 2 ++ captcha_test.go | 2 ++ comments_test.go | 2 ++ contact_test.go | 2 ++ editor_test.go | 3 +++ errors_test.go | 2 ++ feeds_test.go | 3 +++ geoTrack_test.go | 2 ++ geo_test.go | 2 ++ indexnow_test.go | 2 ++ indieAuthServer_test.go | 2 ++ indieAuth_test.go | 2 ++ micropub_test.go | 3 +++ ntfy_test.go | 2 ++ postsDb_test.go | 6 ++++++ postsDeleter_test.go | 2 ++ postsScheduler_test.go | 2 ++ posts_test.go | 6 ++++++ privateMode_test.go | 2 ++ reactions_test.go | 6 ++++++ sitemap_test.go | 2 ++ ui_test.go | 10 ++++++++++ webmentionVerification_test.go | 6 ++++++ webmention_test.go | 2 ++ 29 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 app_test.go diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a025113..6cb148d 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -23,12 +23,12 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # - name: Test - # uses: docker/build-push-action@v2 - # with: - # push: false - # target: test - # tags: test + - name: Test + uses: docker/build-push-action@v2 + with: + push: false + target: test + tags: test - name: Build base image uses: docker/build-push-action@v2 with: diff --git a/activityPub_test.go b/activityPub_test.go index 6824708..ce286b5 100644 --- a/activityPub_test.go +++ b/activityPub_test.go @@ -49,6 +49,9 @@ func Test_webfinger(t *testing.T) { cfg: createDefaultTestConfig(t), } app.cfg.Server.PublicAddress = "https://example.com" + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/app_test.go b/app_test.go new file mode 100644 index 0000000..8e6b34b --- /dev/null +++ b/app_test.go @@ -0,0 +1,7 @@ +package main + +func (a *goBlog) cleanup() { + if a.db != nil { + _ = a.db.close() + } +} diff --git a/authentication_test.go b/authentication_test.go index af56503..457d0ac 100644 --- a/authentication_test.go +++ b/authentication_test.go @@ -29,6 +29,8 @@ func Test_authMiddleware(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/blogroll_test.go b/blogroll_test.go index f4e6889..0ea64d7 100644 --- a/blogroll_test.go +++ b/blogroll_test.go @@ -35,6 +35,8 @@ func Test_blogroll(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/blogstats_test.go b/blogstats_test.go index 7ded1ed..d09e361 100644 --- a/blogstats_test.go +++ b/blogstats_test.go @@ -32,6 +32,8 @@ func Test_blogStats(t *testing.T) { } app.cfg.DefaultBlog = "en" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/captcha_test.go b/captcha_test.go index fe4c419..0252827 100644 --- a/captcha_test.go +++ b/captcha_test.go @@ -23,6 +23,8 @@ func Test_captchaMiddleware(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/comments_test.go b/comments_test.go index 74ed627..ed49cb9 100644 --- a/comments_test.go +++ b/comments_test.go @@ -29,6 +29,8 @@ func Test_comments(t *testing.T) { } app.cfg.DefaultBlog = "en" + t.Cleanup(app.cleanup) + err := app.initConfig(false) require.NoError(t, err) app.initComponents(false) diff --git a/contact_test.go b/contact_test.go index ef60e60..9656d18 100644 --- a/contact_test.go +++ b/contact_test.go @@ -43,6 +43,8 @@ func Test_contact(t *testing.T) { } app.cfg.DefaultBlog = "en" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/editor_test.go b/editor_test.go index d200a01..8de3912 100644 --- a/editor_test.go +++ b/editor_test.go @@ -15,6 +15,9 @@ func Test_editorPreview(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/errors_test.go b/errors_test.go index aba0088..3c6c4c8 100644 --- a/errors_test.go +++ b/errors_test.go @@ -15,6 +15,8 @@ func Test_errors(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/feeds_test.go b/feeds_test.go index 29da48c..b980d28 100644 --- a/feeds_test.go +++ b/feeds_test.go @@ -15,6 +15,9 @@ func Test_feeds(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/geoTrack_test.go b/geoTrack_test.go index 285968d..34bb162 100644 --- a/geoTrack_test.go +++ b/geoTrack_test.go @@ -21,6 +21,8 @@ func Test_geoTrack(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/geo_test.go b/geo_test.go index 92822e6..9329c68 100644 --- a/geo_test.go +++ b/geo_test.go @@ -17,6 +17,8 @@ func Test_geo(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/indexnow_test.go b/indexnow_test.go index e5ea677..e255a70 100644 --- a/indexnow_test.go +++ b/indexnow_test.go @@ -20,6 +20,8 @@ func Test_indexNow(t *testing.T) { } app.cfg.IndexNow = &configIndexNow{Enabled: true} + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/indieAuthServer_test.go b/indieAuthServer_test.go index 96a4fde..d91880d 100644 --- a/indieAuthServer_test.go +++ b/indieAuthServer_test.go @@ -35,6 +35,8 @@ func Test_indieAuthServer(t *testing.T) { } app.cfg.Cache.Enable = false + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/indieAuth_test.go b/indieAuth_test.go index 0c5bc38..9bd8510 100644 --- a/indieAuth_test.go +++ b/indieAuth_test.go @@ -17,6 +17,8 @@ func Test_checkIndieAuth(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/micropub_test.go b/micropub_test.go index 3a774d3..5e799fb 100644 --- a/micropub_test.go +++ b/micropub_test.go @@ -14,6 +14,9 @@ func Test_micropubQuery(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/ntfy_test.go b/ntfy_test.go index e0f3f53..efc2c2c 100644 --- a/ntfy_test.go +++ b/ntfy_test.go @@ -18,6 +18,8 @@ func Test_ntfySending(t *testing.T) { httpClient: fakeClient.Client, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/postsDb_test.go b/postsDb_test.go index 5763de9..1ee2dc6 100644 --- a/postsDb_test.go +++ b/postsDb_test.go @@ -24,6 +24,9 @@ func Test_postsDb(t *testing.T) { }, }, } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -380,6 +383,9 @@ func Test_postDeletesParams(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/postsDeleter_test.go b/postsDeleter_test.go index ff8b80e..29bfc0c 100644 --- a/postsDeleter_test.go +++ b/postsDeleter_test.go @@ -12,6 +12,8 @@ func Test_checkDeletedPosts(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/postsScheduler_test.go b/postsScheduler_test.go index 3e274bc..b3a461e 100644 --- a/postsScheduler_test.go +++ b/postsScheduler_test.go @@ -22,6 +22,8 @@ func Test_postsScheduler(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/posts_test.go b/posts_test.go index 61421cc..35d4833 100644 --- a/posts_test.go +++ b/posts_test.go @@ -16,6 +16,9 @@ func Test_serveDate(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -104,6 +107,9 @@ func Test_servePost(t *testing.T) { Username: "test", Password: "test", }) + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/privateMode_test.go b/privateMode_test.go index 558e553..a1edfd1 100644 --- a/privateMode_test.go +++ b/privateMode_test.go @@ -36,6 +36,8 @@ func Test_privateMode(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/reactions_test.go b/reactions_test.go index 93559c1..75048f6 100644 --- a/reactions_test.go +++ b/reactions_test.go @@ -15,6 +15,9 @@ func Test_reactionsLowLevel(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -95,6 +98,9 @@ func Test_reactionsHighLevel(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/sitemap_test.go b/sitemap_test.go index 4814d73..323ca9e 100644 --- a/sitemap_test.go +++ b/sitemap_test.go @@ -17,6 +17,8 @@ func Test_sitemap(t *testing.T) { cfg: createDefaultTestConfig(t), } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/ui_test.go b/ui_test.go index a001900..a7634e5 100644 --- a/ui_test.go +++ b/ui_test.go @@ -20,6 +20,9 @@ func Test_renderPostTax(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -46,6 +49,9 @@ func Test_renderOldContentWarning(t *testing.T) { app := &goBlog{ cfg: createDefaultTestConfig(t), } + + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -73,6 +79,8 @@ func Test_renderInteractions(t *testing.T) { } app.cfg.Server.PublicAddress = "https://example.com" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -142,6 +150,8 @@ func Test_renderAuthor(t *testing.T) { app.cfg.User.Picture = "https://example.com/picture.jpg" app.cfg.User.Name = "John Doe" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/webmentionVerification_test.go b/webmentionVerification_test.go index 86b373c..1e5b0d9 100644 --- a/webmentionVerification_test.go +++ b/webmentionVerification_test.go @@ -29,6 +29,8 @@ func Test_verifyMention(t *testing.T) { } app.cfg.Server.PublicAddress = "https://example.org" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -70,6 +72,8 @@ func Test_verifyMentionBidgy(t *testing.T) { } app.cfg.Server.PublicAddress = "https://example.org" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) @@ -107,6 +111,8 @@ func Test_verifyMentionColin(t *testing.T) { } app.cfg.Server.PublicAddress = "https://jlelse.blog" + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false) diff --git a/webmention_test.go b/webmention_test.go index fc6a925..46e954f 100644 --- a/webmention_test.go +++ b/webmention_test.go @@ -19,6 +19,8 @@ func Test_webmentions(t *testing.T) { }, } + t.Cleanup(app.cleanup) + _ = app.initConfig(false) app.initComponents(false)