2023-09-12 17:08:17 +07:00
|
|
|
package db_test
|
|
|
|
|
|
|
|
import (
|
2024-02-06 11:55:25 +07:00
|
|
|
"context"
|
2023-09-12 17:08:17 +07:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
db "git.nochill.in/nochill/hiling_go/db/sqlc"
|
|
|
|
"git.nochill.in/nochill/hiling_go/util"
|
2024-02-06 11:55:25 +07:00
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
2023-09-12 17:08:17 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
var testQueries *db.Queries
|
2024-02-06 11:55:25 +07:00
|
|
|
var testDB *pgxpool.Pool
|
2023-09-12 17:08:17 +07:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
var err error
|
|
|
|
config, err := util.LoadConfig("../../..")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("cannot load config: ", err)
|
|
|
|
}
|
|
|
|
|
2024-02-06 11:55:25 +07:00
|
|
|
testDB, err = pgxpool.New(context.Background(), config.DBSourceTest)
|
2023-09-12 17:08:17 +07:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("cannot connect db: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testQueries = db.New(testDB)
|
|
|
|
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|