move from test init()s to TestMain

This commit is contained in:
sentriz
2020-05-03 04:42:29 +01:00
parent 9e4d924fd5
commit 9bf80f4b18
3 changed files with 35 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ package scanner
import (
"io/ioutil"
"log"
"os"
"testing"
_ "github.com/jinzhu/gorm/dialects/sqlite"
@@ -12,17 +13,6 @@ import (
var testScanner *Scanner
func init() {
db, err := db.NewMock()
if err != nil {
log.Fatalf("error opening database: %v\n", err)
}
// benchmarks aren't real code are they? >:)
// here is an absolute path to my music directory
testScanner = New("/home/senan/music", db)
log.SetOutput(ioutil.Discard)
}
func resetTables(db *db.DB) {
tx := db.Begin()
defer tx.Commit()
@@ -54,6 +44,18 @@ func BenchmarkScanIncremental(b *testing.B) {
}
}
func TestMain(m *testing.M) {
db, err := db.NewMock()
if err != nil {
log.Fatalf("error opening database: %v\n", err)
}
// benchmarks aren't real code are they? >:)
// here is an absolute path to my music directory
testScanner = New("/home/senan/music", db)
log.SetOutput(ioutil.Discard)
os.Exit(m.Run())
}
// RESULTS fresh
// 20 times / 1.436
// 20 times / 1.39