github.com/nais/knorten@v0.0.0-20240104110906-55926958e361/pkg/database/repo_test.go (about) 1 package database 2 3 import ( 4 "log" 5 "os" 6 "path" 7 "runtime" 8 "testing" 9 10 "github.com/nais/knorten/local/dbsetup" 11 "github.com/sirupsen/logrus" 12 ) 13 14 var repo *Repo 15 16 func init() { 17 _, filename, _, _ := runtime.Caller(0) 18 dir := path.Join(path.Dir(filename), "../..") 19 err := os.Chdir(dir) 20 if err != nil { 21 panic(err) 22 } 23 } 24 25 func TestMain(m *testing.M) { 26 dbConn, err := dbsetup.SetupDBForTests() 27 if err != nil { 28 log.Fatal(err) 29 } 30 repo, err = New(dbConn, "", logrus.NewEntry(logrus.StandardLogger())) 31 if err != nil { 32 log.Fatal(err) 33 } 34 35 code := m.Run() 36 os.Exit(code) 37 }