forked from ebhomengo/niki
1
0
Fork 0
niki/test/db.go

39 lines
647 B
Go

package testutils
import (
"sync"
"testing"
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
//nolint
_ "github.com/go-sql-driver/mysql"
)
var once = sync.Once{}
const port = 3305
func MySQLTestConfig() mysql.Config {
return mysql.Config{
Username: "testuser",
Password: "test1234",
Port: port,
Host: "localhost",
DBName: "test_db",
}
}
func Setup(t *testing.T) *mysql.DB {
t.Helper()
// connect to mysql database
config := MySQLTestConfig()
once.Do(func() {
mgr := migrator.New(config)
mgr.Up()
})
mysqlRepo := mysql.New(config)
return mysqlRepo
}