dendrite.daemon/test/test_integration/main_test.go

62 lines
1.2 KiB
Go

package integration_test
import (
"context"
"database/sql"
"encoding/json"
"os"
"path"
"path/filepath"
"testing"
"github.com/KristianJBorgwarth/dendrite.daemon/core/rpc"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
_ "modernc.org/sqlite"
)
type DBFixture struct {
DB *sql.DB
DBPath string
TestContext context.Context
VaultStore *store.VaultStore
}
func NewDBFixture() *DBFixture {
vaultPath := os.TempDir()
err := persistence.InitializeDBContext(vaultPath)
if err != nil {
panic(err)
}
dbPath := filepath.Join(os.TempDir(), ".index", "index.db")
dbContext := persistence.GetDBContext()
return &DBFixture{
DB: dbContext.DB,
DBPath: dbPath,
TestContext: context.Background(),
VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates")),
}
}
var Fixture = NewDBFixture()
func TestMain(m *testing.M) {
code := m.Run()
os.RemoveAll(Fixture.DBPath)
os.Exit(code)
}
func CreateTestRequest(method string, ID int, params json.RawMessage) *rpc.Request {
return &rpc.Request{
Jsonrpc: "2.0",
ID: &ID,
Method: method,
Params: params,
}
}