mirror of https://github.com/jlelse/GoBlog
Improve test speeds by removing useless method calls
parent
72ee1c833c
commit
f0d3f1c84f
|
@ -50,10 +50,7 @@ func Test_webfinger(t *testing.T) {
|
|||
}
|
||||
app.cfg.Server.PublicAddress = "https://example.com"
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
app.prepareWebfinger()
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package main
|
||||
|
||||
func (a *goBlog) cleanup() {
|
||||
if a.db != nil {
|
||||
_ = a.db.close()
|
||||
}
|
||||
}
|
|
@ -29,10 +29,10 @@ func Test_authMiddleware(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
_, _ = rw.Write([]byte("ABC Test"))
|
||||
|
|
|
@ -35,10 +35,7 @@ func Test_blogroll(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
fc.setFakeResponse(http.StatusOK, `
|
||||
<opml version="2.0">
|
||||
|
|
|
@ -32,10 +32,11 @@ func Test_blogStats(t *testing.T) {
|
|||
}
|
||||
app.cfg.DefaultBlog = "en"
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
app.initMarkdown()
|
||||
_ = app.initTemplateStrings()
|
||||
app.initSessions()
|
||||
|
||||
// Insert post
|
||||
|
||||
|
|
|
@ -23,10 +23,10 @@ func Test_captchaMiddleware(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = alice.New(app.checkIsCaptcha, app.captchaMiddleware).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
_, _ = rw.Write([]byte("ABC Test"))
|
||||
|
|
|
@ -29,11 +29,10 @@ 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)
|
||||
_ = app.initTemplateStrings()
|
||||
app.initSessions()
|
||||
|
||||
t.Run("Successful comment", func(t *testing.T) {
|
||||
|
||||
|
|
|
@ -43,10 +43,9 @@ func Test_contact(t *testing.T) {
|
|||
}
|
||||
app.cfg.DefaultBlog = "en"
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
// Make contact form request
|
||||
rec := httptest.NewRecorder()
|
||||
|
|
|
@ -16,10 +16,9 @@ func Test_editorPreview(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
h := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
app.serveEditorPreview(rw, r.WithContext(context.WithValue(r.Context(), blogKey, "default")))
|
||||
|
|
|
@ -15,10 +15,9 @@ func Test_errors(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
|
||||
t.Run("Test 404, no HTML", func(t *testing.T) {
|
||||
h := http.HandlerFunc(app.serve404)
|
||||
|
|
|
@ -16,10 +16,10 @@ func Test_feeds(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
app.initSessions()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
handlerClient := newHandlerClient(app.d)
|
||||
|
|
|
@ -21,10 +21,7 @@ func Test_geoTrack(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
// First test (just with track)
|
||||
|
||||
|
|
|
@ -17,10 +17,7 @@ func Test_geo(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
p := &post{
|
||||
Blog: "en",
|
||||
|
|
|
@ -20,10 +20,9 @@ func Test_indexNow(t *testing.T) {
|
|||
}
|
||||
app.cfg.IndexNow = &configIndexNow{Enabled: true}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
app.initIndexNow()
|
||||
|
||||
// Create http router
|
||||
app.d = app.buildRouter()
|
||||
|
|
|
@ -35,10 +35,11 @@ func Test_indieAuthServer(t *testing.T) {
|
|||
}
|
||||
app.cfg.Cache.Enable = false
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initIndieAuth()
|
||||
_ = app.initCache()
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
|
||||
|
|
|
@ -17,10 +17,9 @@ func Test_checkIndieAuth(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
|
17
main.go
17
main.go
|
@ -153,7 +153,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Initialize components
|
||||
app.initComponents(true)
|
||||
app.initComponents()
|
||||
|
||||
// Start cron hooks
|
||||
app.startHourlyHooks()
|
||||
|
@ -169,12 +169,11 @@ func main() {
|
|||
app.shutdown.Wait()
|
||||
}
|
||||
|
||||
func (app *goBlog) initComponents(logging bool) {
|
||||
func (app *goBlog) initComponents() {
|
||||
var err error
|
||||
// Log start
|
||||
if logging {
|
||||
log.Println("Initialize components...")
|
||||
}
|
||||
|
||||
log.Println("Initialize components...")
|
||||
|
||||
app.initMarkdown()
|
||||
if err = app.initTemplateAssets(); err != nil { // Needs minify
|
||||
app.logErrAndQuit("Failed to init template assets:", err.Error())
|
||||
|
@ -209,10 +208,8 @@ func (app *goBlog) initComponents(logging bool) {
|
|||
app.startPostsScheduler()
|
||||
app.initPostsDeleter()
|
||||
app.initIndexNow()
|
||||
// Log finish
|
||||
if logging {
|
||||
log.Println("Initialized components")
|
||||
}
|
||||
|
||||
log.Println("Initialized components")
|
||||
}
|
||||
|
||||
func (a *goBlog) logErrAndQuit(v ...any) {
|
||||
|
|
|
@ -15,10 +15,10 @@ func Test_micropubQuery(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
|
||||
// Create a test post with tags
|
||||
err := app.createPost(&post{
|
||||
|
|
|
@ -18,10 +18,7 @@ func Test_ntfySending(t *testing.T) {
|
|||
httpClient: fakeClient.Client,
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
t.Run("Default", func(t *testing.T) {
|
||||
app.cfg.Notifications = &configNotifications{
|
||||
|
|
|
@ -25,10 +25,9 @@ func Test_postsDb(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
|
||||
now := toLocalSafe(time.Now().String())
|
||||
nowPlus1Hour := toLocalSafe(time.Now().Add(1 * time.Hour).String())
|
||||
|
@ -384,10 +383,9 @@ func Test_postDeletesParams(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
|
||||
err := app.createPost(&post{
|
||||
Path: "/test/abc",
|
||||
|
|
|
@ -12,10 +12,8 @@ func Test_checkDeletedPosts(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
|
||||
// Create a post
|
||||
err := app.createPost(&post{
|
||||
|
|
|
@ -22,10 +22,8 @@ func Test_postsScheduler(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
|
||||
err := app.db.savePost(&post{
|
||||
Path: "/test/abc",
|
||||
|
|
|
@ -17,10 +17,11 @@ func Test_serveDate(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
|
||||
|
@ -108,10 +109,11 @@ func Test_servePost(t *testing.T) {
|
|||
Password: "test",
|
||||
})
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
|
||||
|
|
|
@ -36,10 +36,9 @@ func Test_privateMode(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initSessions()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
handler := alice.New(middleware.WithValue(blogKey, "en"), app.privateModeHandler).ThenFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
_, _ = rw.Write([]byte("Awesome"))
|
||||
|
|
|
@ -16,10 +16,8 @@ func Test_reactionsLowLevel(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
|
||||
err := app.saveReaction("🖕", "/testpost")
|
||||
assert.ErrorContains(t, err, "not allowed")
|
||||
|
@ -99,10 +97,10 @@ func Test_reactionsHighLevel(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
app.initSessions()
|
||||
_ = app.initCache()
|
||||
|
||||
// Send unsuccessful reaction
|
||||
form := url.Values{
|
||||
|
|
|
@ -17,10 +17,9 @@ func Test_sitemap(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
_ = app.initCache()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
|
||||
|
|
17
ui_test.go
17
ui_test.go
|
@ -21,10 +21,8 @@ func Test_renderPostTax(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
app.initMarkdown()
|
||||
|
||||
p := &post{
|
||||
Parameters: map[string][]string{
|
||||
|
@ -50,10 +48,8 @@ func Test_renderOldContentWarning(t *testing.T) {
|
|||
cfg: createDefaultTestConfig(t),
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
p := &post{
|
||||
Published: "2018-01-01",
|
||||
|
@ -79,10 +75,10 @@ func Test_renderInteractions(t *testing.T) {
|
|||
}
|
||||
app.cfg.Server.PublicAddress = "https://example.com"
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
_ = app.initCache()
|
||||
app.initMarkdown()
|
||||
_ = app.initTemplateStrings()
|
||||
|
||||
app.d = app.buildRouter()
|
||||
|
||||
|
@ -150,10 +146,7 @@ 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)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
hb := newHtmlBuilder(buf)
|
||||
|
|
|
@ -19,10 +19,7 @@ func Test_webmentions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
t.Cleanup(app.cleanup)
|
||||
|
||||
_ = app.initConfig(false)
|
||||
app.initComponents(false)
|
||||
|
||||
_ = app.db.insertWebmention(&mention{
|
||||
Source: "https://example.net/test",
|
||||
|
|
Loading…
Reference in New Issue