WIP revert connstr gdbm to dir only, add file as table spec
This commit is contained in:
parent
e92e498726
commit
dc61d05584
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
fsdb "git.defalsify.org/vise.git/db/fs"
|
fsdb "git.defalsify.org/vise.git/db/fs"
|
||||||
@ -66,7 +67,7 @@ func (ms *MenuStorageService) SetConn(connStr string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, fileName string) (db.Db, error) {
|
func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, section string) (db.Db, error) {
|
||||||
var newDb db.Db
|
var newDb db.Db
|
||||||
var err error
|
var err error
|
||||||
// database, ok := ctx.Value("Database").(string)
|
// database, ok := ctx.Value("Database").(string)
|
||||||
@ -79,6 +80,7 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
connStr := ms.conn.String()
|
||||||
dbTyp := ms.conn.DbType()
|
dbTyp := ms.conn.DbType()
|
||||||
if dbTyp == DBTYPE_POSTGRES {
|
if dbTyp == DBTYPE_POSTGRES {
|
||||||
newDb = postgres.NewPgDb()
|
newDb = postgres.NewPgDb()
|
||||||
@ -87,11 +89,13 @@ func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.D
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
connStr = path.Join(connStr, section)
|
||||||
newDb = gdbmstorage.NewThreadGdbmDb()
|
newDb = gdbmstorage.NewThreadGdbmDb()
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("unsupported connection string: %s", ms.conn.String())
|
return nil, fmt.Errorf("unsupported connection string: %s", ms.conn.String())
|
||||||
}
|
}
|
||||||
err = newDb.Connect(ctx, ms.conn.String())
|
logg.DebugCtxf(ctx, "connecting to db", "conn", connStr)
|
||||||
|
err = newDb.Connect(ctx, connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
@ -27,7 +28,6 @@ var (
|
|||||||
func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||||
ctx = context.WithValue(ctx, "Database", "gdbm")
|
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
|
|
||||||
var eventChannel = make(chan bool)
|
var eventChannel = make(chan bool)
|
||||||
@ -39,39 +39,43 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
|||||||
FlagCount: uint32(128),
|
FlagCount: uint32(128),
|
||||||
}
|
}
|
||||||
|
|
||||||
dbDir := ".test_state"
|
connStr, err := filepath.Abs(".test_state/state.gdbm")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
resourceDir := scriptDir
|
resourceDir := scriptDir
|
||||||
//menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir)
|
//menuStorageService := storage.NewMenuStorageService(connStr, resourceDir)
|
||||||
menuStorageService := storage.NewMenuStorageService(resourceDir)
|
menuStorageService := storage.NewMenuStorageService(resourceDir)
|
||||||
|
|
||||||
//err := menuStorageService.EnsureDbDir()
|
//err := menuStorageService.EnsureDbDir()
|
||||||
err := menuStorageService.SetConn(dbDir)
|
err = menuStorageService.SetConn(connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "conn error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, err := menuStorageService.GetResource(ctx)
|
rs, err := menuStorageService.GetResource(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "resource error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pe, err := menuStorageService.GetPersister(ctx)
|
pe, err := menuStorageService.GetPersister(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "persister error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
userDataStore, err := menuStorageService.GetUserdataDb(ctx)
|
userDataStore, err := menuStorageService.GetUserdataDb(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "userdb error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbResource, ok := rs.(*resource.DbResource)
|
dbResource, ok := rs.(*resource.DbResource)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "dbresource cast error")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
15
internal/testutil/engine_test.go
Normal file
15
internal/testutil/engine_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package testutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateEngine(t *testing.T) {
|
||||||
|
o, clean, eventC := TestEngine("foo")
|
||||||
|
defer clean()
|
||||||
|
defer func() {
|
||||||
|
<-eventC
|
||||||
|
close(eventC)
|
||||||
|
}()
|
||||||
|
_ = o
|
||||||
|
}
|
@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -17,7 +18,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
testData = driver.ReadData()
|
testData = driver.ReadData()
|
||||||
testStore = ".test_state"
|
|
||||||
sessionID string
|
sessionID string
|
||||||
src = rand.NewSource(42)
|
src = rand.NewSource(42)
|
||||||
g = rand.New(src)
|
g = rand.New(src)
|
||||||
@ -25,6 +25,11 @@ var (
|
|||||||
|
|
||||||
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
|
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
|
||||||
|
|
||||||
|
func testStore() string {
|
||||||
|
v, _ := filepath.Abs(".test_state/state.gdbm")
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
func GenerateSessionId() string {
|
func GenerateSessionId() string {
|
||||||
uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g))
|
uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g))
|
||||||
v, err := uu.NewV4()
|
v, err := uu.NewV4()
|
||||||
@ -81,8 +86,8 @@ func extractSendAmount(response []byte) string {
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
sessionID = GenerateSessionId()
|
sessionID = GenerateSessionId()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := os.RemoveAll(testStore); err != nil {
|
if err := os.RemoveAll(testStore()); err != nil {
|
||||||
log.Fatalf("Failed to delete state store %s: %v", testStore, err)
|
log.Fatalf("Failed to delete state store %s: %v", testStore(), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
m.Run()
|
m.Run()
|
||||||
|
Loading…
Reference in New Issue
Block a user