mirror of https://github.com/jlelse/GoBlog
Close database after all tests
This commit is contained in:
parent
66cdf89863
commit
9eb9b50c0a
|
@ -20,6 +20,7 @@ func Test_loadActivityPubPrivateKey(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
|
|
||||||
// Generate
|
// Generate
|
||||||
err := app.loadActivityPubPrivateKey()
|
err := app.loadActivityPubPrivateKey()
|
||||||
|
|
|
@ -31,6 +31,7 @@ func Test_authMiddleware(t *testing.T) {
|
||||||
|
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.d = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
app.d = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ func Test_blogroll(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
fc.setFakeResponse(200, `
|
fc.setFakeResponse(200, `
|
||||||
|
|
|
@ -43,6 +43,7 @@ func Test_blogStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
// Insert post
|
// Insert post
|
||||||
|
|
|
@ -25,6 +25,7 @@ func Test_captchaMiddleware(t *testing.T) {
|
||||||
|
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.d = alice.New(app.checkIsCaptcha, app.captchaMiddleware).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
app.d = alice.New(app.checkIsCaptcha, app.captchaMiddleware).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ func Test_comments(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
t.Run("Successful comment", func(t *testing.T) {
|
t.Run("Successful comment", func(t *testing.T) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ func Test_contact(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
// Make contact form request
|
// Make contact form request
|
||||||
|
|
|
@ -17,6 +17,7 @@ func Test_editorPreview(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
h := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
h := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ func Test_errors(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
t.Run("Test 404, no HTML", func(t *testing.T) {
|
t.Run("Test 404, no HTML", func(t *testing.T) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ func Test_export(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initMarkdown()
|
app.initMarkdown()
|
||||||
|
|
||||||
err := app.db.savePost(&post{
|
err := app.db.savePost(&post{
|
||||||
|
|
|
@ -17,6 +17,7 @@ func Test_feeds(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
app.d, _ = app.buildRouter()
|
app.d, _ = app.buildRouter()
|
||||||
handlerClient := newHandlerClient(app.d)
|
handlerClient := newHandlerClient(app.d)
|
||||||
|
|
|
@ -28,6 +28,7 @@ func Test_geoTrack(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
// First test (just with track)
|
// First test (just with track)
|
||||||
|
|
|
@ -20,6 +20,7 @@ func Test_indexNow(t *testing.T) {
|
||||||
app.cfg.IndexNow = &configIndexNow{Enabled: true}
|
app.cfg.IndexNow = &configIndexNow{Enabled: true}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
// Create http router
|
// Create http router
|
||||||
|
|
|
@ -49,6 +49,7 @@ func Test_indieAuthServer(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.ias.Client = newHandlerClient(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
app.ias.Client = newHandlerClient(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ func Test_checkIndieAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
|
|
@ -26,6 +26,7 @@ func Test_ntfySending(t *testing.T) {
|
||||||
|
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.sendNotification("Test notification")
|
app.sendNotification("Test notification")
|
||||||
|
|
|
@ -26,6 +26,7 @@ func Test_postsDb(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
now := toLocalSafe(time.Now().String())
|
now := toLocalSafe(time.Now().String())
|
||||||
|
@ -234,6 +235,7 @@ func Test_ftsWithoutTitle(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initMarkdown()
|
app.initMarkdown()
|
||||||
|
|
||||||
err := app.db.savePost(&post{
|
err := app.db.savePost(&post{
|
||||||
|
@ -265,6 +267,7 @@ func Test_postsPriority(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initMarkdown()
|
app.initMarkdown()
|
||||||
|
|
||||||
err := app.db.savePost(&post{
|
err := app.db.savePost(&post{
|
||||||
|
@ -315,6 +318,7 @@ func Test_usesOfMediaFile(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
|
|
||||||
err := app.db.savePost(&post{
|
err := app.db.savePost(&post{
|
||||||
Path: "/test/abc",
|
Path: "/test/abc",
|
||||||
|
|
|
@ -13,6 +13,7 @@ func Test_checkDeletedPosts(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
// Create a post
|
// Create a post
|
||||||
|
|
|
@ -33,6 +33,7 @@ func Test_postsScheduler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
err := app.db.savePost(&post{
|
err := app.db.savePost(&post{
|
||||||
|
|
|
@ -18,6 +18,7 @@ func Test_serveDate(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.d, err = app.buildRouter()
|
app.d, err = app.buildRouter()
|
||||||
|
@ -108,6 +109,7 @@ func Test_servePost(t *testing.T) {
|
||||||
})
|
})
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.d, err = app.buildRouter()
|
app.d, err = app.buildRouter()
|
||||||
|
|
|
@ -46,6 +46,7 @@ func Test_privateMode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
handler := alice.New(middleware.WithValue(blogKey, "en"), app.privateModeHandler).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
handler := alice.New(middleware.WithValue(blogKey, "en"), app.privateModeHandler).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ func Test_queue(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
db := app.db
|
db := app.db
|
||||||
|
|
||||||
err := db.enqueue("test", []byte(""), time.Now())
|
err := db.enqueue("test", []byte(""), time.Now())
|
||||||
|
|
|
@ -17,6 +17,7 @@ func Test_shortenPath(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
db := app.db
|
db := app.db
|
||||||
|
|
||||||
res1, err := db.shortenPath("/a")
|
res1, err := db.shortenPath("/a")
|
||||||
|
|
|
@ -18,6 +18,7 @@ func Test_sitemap(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
app.d, err = app.buildRouter()
|
app.d, err = app.buildRouter()
|
||||||
|
|
|
@ -124,6 +124,7 @@ func Test_telegram(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
|
|
||||||
app.initMarkdown()
|
app.initMarkdown()
|
||||||
app.initTelegram()
|
app.initTelegram()
|
||||||
|
@ -157,6 +158,7 @@ func Test_telegram(t *testing.T) {
|
||||||
|
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
|
|
||||||
app.initTelegram()
|
app.initTelegram()
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ func Test_renderPostTax(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
p := &post{
|
p := &post{
|
||||||
|
@ -47,6 +48,7 @@ func Test_renderOldContentWarning(t *testing.T) {
|
||||||
}
|
}
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
p := &post{
|
p := &post{
|
||||||
|
@ -74,6 +76,7 @@ func Test_renderInteractions(t *testing.T) {
|
||||||
app.cfg.Server.PublicAddress = "https://example.com"
|
app.cfg.Server.PublicAddress = "https://example.com"
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
app.d, err = app.buildRouter()
|
app.d, err = app.buildRouter()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -140,6 +143,7 @@ func Test_renderAuthor(t *testing.T) {
|
||||||
app.cfg.User.Name = "John Doe"
|
app.cfg.User.Name = "John Doe"
|
||||||
_ = app.initConfig()
|
_ = app.initConfig()
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
|
@ -37,6 +37,7 @@ func Test_verifyMention(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
m := &mention{
|
m := &mention{
|
||||||
|
@ -84,6 +85,7 @@ func Test_verifyMentionBidgy(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
m := &mention{
|
m := &mention{
|
||||||
|
@ -127,6 +129,7 @@ func Test_verifyMentionColin(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
m := &mention{
|
m := &mention{
|
||||||
|
|
|
@ -29,6 +29,7 @@ func Test_webmentions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = app.initDatabase(false)
|
_ = app.initDatabase(false)
|
||||||
|
defer app.db.close()
|
||||||
app.initComponents(false)
|
app.initComponents(false)
|
||||||
|
|
||||||
_ = app.db.insertWebmention(&mention{
|
_ = app.db.insertWebmention(&mention{
|
||||||
|
|
Loading…
Reference in New Issue