forked from grassrootseconomics/visedriver
Merge branch 'lash/purify-more' into postgres-switch-for-tests
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
@@ -16,11 +17,9 @@ import (
|
||||
"git.grassecon.net/urdt/ussd/internal/testutil/testservice"
|
||||
"git.grassecon.net/urdt/ussd/internal/testutil/testtag"
|
||||
"git.grassecon.net/urdt/ussd/remote"
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
)
|
||||
|
||||
var (
|
||||
baseDir = testdataloader.GetBasePath()
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join(baseDir, "services", "registration")
|
||||
selectedDatabase = ""
|
||||
@@ -28,7 +27,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
initializers.LoadEnvVariables(baseDir)
|
||||
initializers.LoadEnvVariables()
|
||||
}
|
||||
|
||||
// SetDatabase updates the database used by TestEngine
|
||||
@@ -40,9 +39,6 @@ func SetDatabase(dbType string, dbSchema string) {
|
||||
func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Database", selectedDatabase)
|
||||
ctx = context.WithValue(ctx, "Schema", selectedDbSchema)
|
||||
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
var eventChannel = make(chan bool)
|
||||
@@ -54,37 +50,40 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
FlagCount: uint32(128),
|
||||
}
|
||||
|
||||
dbDir := ".test_state"
|
||||
resourceDir := scriptDir
|
||||
menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir)
|
||||
|
||||
err := menuStorageService.EnsureDbDir()
|
||||
connStr, err := filepath.Abs(".test_state/state.gdbm")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
conn, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr parse err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
resourceDir := scriptDir
|
||||
menuStorageService := storage.NewMenuStorageService(conn, resourceDir)
|
||||
|
||||
rs, err := menuStorageService.GetResource(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "resource error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
pe, err := menuStorageService.GetPersister(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "persister error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
userDataStore, err := menuStorageService.GetUserdataDb(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "userdb error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "dbresource cast error")
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user