jldb/mdb/db_test.go
2023-10-13 11:43:27 +02:00

55 lines
907 B
Go

package mdb
import (
"testing"
"time"
)
type TestDB struct {
*Database
Users Users
UserData UserData
}
func NewTestDBPrimary(t *testing.T, rootDir string) TestDB {
db := New(Config{
RootDir: rootDir,
Primary: true,
NetTimeout: 8 * time.Second,
ReplicationPSK: "123",
})
testDB := TestDB{
Database: db,
Users: NewUserCollection(db),
UserData: NewUserDataCollection(db),
}
if err := testDB.Open(); err != nil {
t.Fatal(err)
}
return testDB
}
func NewTestSecondaryDB(t *testing.T, rootDir, primaryURL string) TestDB {
db := New(Config{
RootDir: rootDir,
PrimaryEndpoint: primaryURL,
NetTimeout: 8 * time.Second,
ReplicationPSK: "123",
})
testDB := TestDB{
Database: db,
Users: NewUserCollection(db),
UserData: NewUserDataCollection(db),
}
if err := testDB.Open(); err != nil {
t.Fatal(err)
}
return testDB
}