move from test init()s to TestMain
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user