mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-12 19:20:06 +00:00
51 lines
839 B
Go
51 lines
839 B
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/bitcomplete/sqltestutil"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
testDB *DBHandler
|
||
|
)
|
||
|
|
||
|
func TestMain(m *testing.M) {
|
||
|
ctx := context.Background()
|
||
|
psql, err := sqltestutil.StartPostgresContainer(ctx, "latest")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer psql.Shutdown(ctx)
|
||
|
|
||
|
testDB, err = OpenFromConnectionString("postgres", psql.ConnectionString()+"?sslmode=disable")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer testDB.Close()
|
||
|
|
||
|
if err := testDB.Setup(); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
os.Exit(m.Run())
|
||
|
}
|
||
|
|
||
|
func TestDBAccount(t *testing.T) {
|
||
|
if _, err := testDB.NewAccount("test", "test"); err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
|
||
|
// now try to retrieve account data
|
||
|
acc, err := testDB.TryLogin("test", "test")
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
|
||
|
if acc.Login != "test" {
|
||
|
t.Error("account username is not test")
|
||
|
}
|
||
|
}
|