Improve test speeds by removing useless method calls

pull/25/head
Jan-Lukas Else 4 months ago
parent 72ee1c833c
commit f0d3f1c84f
  1. 3
      activityPub_test.go
  2. 7
      app_test.go
  3. 6
      authentication_test.go
  4. 3
      blogroll_test.go
  5. 7
      blogstats_test.go
  6. 6
      captcha_test.go
  7. 5
      comments_test.go
  8. 5
      contact_test.go
  9. 5
      editor_test.go
  10. 5
      errors_test.go
  11. 6
      feeds_test.go
  12. 3
      geoTrack_test.go
  13. 3
      geo_test.go
  14. 5
      indexnow_test.go
  15. 7
      indieAuthServer_test.go
  16. 5
      indieAuth_test.go
  17. 17
      main.go
  18. 6
      micropub_test.go
  19. 3
      ntfy_test.go
  20. 10
      postsDb_test.go
  21. 4
      postsDeleter_test.go
  22. 4
      postsScheduler_test.go
  23. 14
      posts_test.go
  24. 5
      privateMode_test.go
  25. 10
      reactions_test.go
  26. 5
      sitemap_test.go
  27. 17
      ui_test.go
  28. 3
      webmention_test.go

@ -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()

@ -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()

@ -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…
Cancel
Save