Compare commits

..

No commits in common. "450dfa02cc016b525d743a864530581e0372acda" and "e92e4987262372020147aebe0743f687a3a12ee2" have entirely different histories.

15 changed files with 148 additions and 140 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath"
"strconv" "strconv"
"syscall" "syscall"
@ -33,7 +34,6 @@ var (
func init() { func init() {
initializers.LoadEnvVariables() initializers.LoadEnvVariables()
} }
func main() { func main() {
config.LoadConfig() config.LoadConfig()
@ -47,21 +47,20 @@ func main() {
var err error var err error
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", ".state", "connection string") flag.StringVar(&connStr, "c", ".", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output") flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host") flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host")
flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port") flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
logg.Infof("start command", "build", build, "dbdir", connStr, "resourcedir", resourceDir, "outputsize", size) logg.Infof("start command", "build", build, "dbdir", connStr, "resourcedir", resourceDir, "outputsize", size)
@ -81,7 +80,7 @@ func main() {
} }
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData) err = menuStorageService.SetConn(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, err.Error()) fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath"
"syscall" "syscall"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
@ -46,8 +47,8 @@ func (p *asyncRequestParser) GetInput(r any) ([]byte, error) {
func main() { func main() {
config.LoadConfig() config.LoadConfig()
var connStr string
var sessionId string var sessionId string
var connStr string
var resourceDir string var resourceDir string
var size uint var size uint
var database string var database string
@ -58,21 +59,20 @@ func main() {
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", "", "connection string") flag.StringVar(&connStr, "c", ".", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output") flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host") flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host")
flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port") flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
logg.Infof("start command", "connstr", connStr, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId) logg.Infof("start command", "connstr", connStr, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
@ -92,7 +92,7 @@ func main() {
} }
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData) err = menuStorageService.SetConn(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, err.Error()) fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"path/filepath"
"strconv" "strconv"
"syscall" "syscall"
@ -46,21 +47,20 @@ func main() {
var err error var err error
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", "", "connection string") flag.StringVar(&connStr, "c", ".", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output") flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host") flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host")
flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port") flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
logg.Infof("start command", "connstr", connStr, "resourcedir", resourceDir, "outputsize", size) logg.Infof("start command", "connstr", connStr, "resourcedir", resourceDir, "outputsize", size)
@ -80,7 +80,11 @@ func main() {
} }
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData) err = menuStorageService.SetConn(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
rs, err := menuStorageService.GetResource(ctx) rs, err := menuStorageService.GetResource(ctx)
if err != nil { if err != nil {

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
@ -38,19 +39,18 @@ func main() {
var err error var err error
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string") flag.StringVar(&connStr, "c", ".", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output") flag.UintVar(&size, "s", 160, "max size of output")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
logg.Infof("start command", "connstr", connStr, "outputsize", size) logg.Infof("start command", "connstr", connStr, "outputsize", size)
@ -69,7 +69,12 @@ func main() {
resourceDir := scriptDir resourceDir := scriptDir
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData)
err = menuStorageService.SetConn(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
rs, err := menuStorageService.GetResource(ctx) rs, err := menuStorageService.GetResource(ctx)
if err != nil { if err != nil {

View File

@ -23,19 +23,19 @@ type StorageServices interface {
GetPersister(ctx context.Context) (*persist.Persister, error) GetPersister(ctx context.Context) (*persist.Persister, error)
GetUserdataDb(ctx context.Context) (db.Db, error) GetUserdataDb(ctx context.Context) (db.Db, error)
GetResource(ctx context.Context) (resource.Resource, error) GetResource(ctx context.Context) (resource.Resource, error)
SetConn(conn storage.ConnData) SetConn(connStr string) error
} }
type StorageService struct { type StorageService struct {
svc *storage.MenuStorageService svc *storage.MenuStorageService
} }
func NewStorageService(conn storage.ConnData) (*StorageService, error) { func NewStorageService(connStr string) (*StorageService, error) {
svc := &StorageService{ svc := &StorageService{
svc: storage.NewMenuStorageService(""), svc: storage.NewMenuStorageService(""),
} }
svc.SetConn(conn) err := svc.SetConn(connStr)
return svc, nil return svc, err
} }
func(ss *StorageService) GetPersister(ctx context.Context) (*persist.Persister, error) { func(ss *StorageService) GetPersister(ctx context.Context) (*persist.Persister, error) {
@ -50,6 +50,6 @@ func(ss *StorageService) GetResource(ctx context.Context) (resource.Resource, er
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
func(ss *StorageService) SetConn(conn storage.ConnData) { func(ss *StorageService) SetConn(connStr string) error {
ss.svc = ss.svc.WithConn(conn) return ss.svc.SetConn(connStr)
} }

View File

@ -34,7 +34,6 @@ var (
VoucherTransfersURL string VoucherTransfersURL string
VoucherDataURL string VoucherDataURL string
CheckAliasURL string CheckAliasURL string
DbConn string
) )
func setBase() error { func setBase() error {
@ -44,20 +43,14 @@ func setBase() error {
dataURLBase = initializers.GetEnv("DATA_URL_BASE", "http://localhost:5006") dataURLBase = initializers.GetEnv("DATA_URL_BASE", "http://localhost:5006")
BearerToken = initializers.GetEnv("BEARER_TOKEN", "") BearerToken = initializers.GetEnv("BEARER_TOKEN", "")
_, err = url.Parse(custodialURLBase) _, err = url.JoinPath(custodialURLBase, "/foo")
if err != nil { if err != nil {
return err return err
} }
_, err = url.Parse(dataURLBase) _, err = url.JoinPath(dataURLBase, "/bar")
if err != nil { if err != nil {
return err return err
} }
return nil
}
func setConn() error {
DbConn = initializers.GetEnv("DB_CONN", "")
return nil return nil
} }
@ -67,10 +60,6 @@ func LoadConfig() error {
if err != nil { if err != nil {
return err return err
} }
err = setConn()
if err != nil {
return err
}
CreateAccountURL, _ = url.JoinPath(custodialURLBase, createAccountPath) CreateAccountURL, _ = url.JoinPath(custodialURLBase, createAccountPath)
TrackStatusURL, _ = url.JoinPath(custodialURLBase, trackStatusPath) TrackStatusURL, _ = url.JoinPath(custodialURLBase, trackStatusPath)
BalanceURL, _ = url.JoinPath(custodialURLBase, balancePathPrefix) BalanceURL, _ = url.JoinPath(custodialURLBase, balancePathPrefix)

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/config"
@ -35,20 +36,19 @@ func main() {
var err error var err error
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id") flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string") flag.StringVar(&connStr, "c", ".", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
logg.Infof("start command", "conn", connData) logg.Infof("start command", "connstr", connStr)
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
@ -56,7 +56,11 @@ func main() {
resourceDir := scriptDir resourceDir := scriptDir
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData) err = menuStorageService.SetConn(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "connection string error: %v", err)
os.Exit(1)
}
store, err := menuStorageService.GetUserdataDb(ctx) store, err := menuStorageService.GetUserdataDb(ctx)
if err != nil { if err != nil {

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/initializers" "git.grassecon.net/urdt/ussd/initializers"
@ -39,14 +40,13 @@ func main() {
flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.Parse() flag.Parse()
if connStr != "" { if connStr == "." {
connStr = config.DbConn connStr, err = filepath.Abs(".state/state.gdbm")
}
connData, err := storage.ToConnData(config.DbConn)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err) fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err)
os.Exit(1) os.Exit(1)
} }
}
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
@ -54,7 +54,7 @@ func main() {
resourceDir := scriptDir resourceDir := scriptDir
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService = menuStorageService.WithConn(connData) err = menuStorageService.SetConn(connStr)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "connection string error: %v", err) fmt.Fprintf(os.Stderr, "connection string error: %v", err)
os.Exit(1) os.Exit(1)

View File

@ -12,16 +12,16 @@ const (
DBTYPE_POSTGRES DBTYPE_POSTGRES
) )
type ConnData struct { type connData struct {
typ int typ int
str string str string
} }
func (cd *ConnData) DbType() int { func (cd *connData) DbType() int {
return cd.typ return cd.typ
} }
func (cd *ConnData) String() string { func (cd *connData) String() string {
return cd.str return cd.str
} }
@ -40,12 +40,15 @@ func probeGdbm(s string) (string, bool) {
if !path.IsAbs(s) { if !path.IsAbs(s) {
return "", false return "", false
} }
if path.Ext(s) != ".gdbm" {
return "", false
}
s = path.Clean(s) s = path.Clean(s)
return s, true return s, true
} }
func ToConnData(connStr string) (ConnData, error) { func toConnData(connStr string) (connData, error) {
var o ConnData var o connData
if connStr == "" { if connStr == "" {
return o, nil return o, nil

View File

@ -5,23 +5,32 @@ import (
) )
func TestParseConnStr(t *testing.T) { func TestParseConnStr(t *testing.T) {
_, err := ToConnData("postgres://foo:bar@localhost:5432/baz") svc := NewMenuStorageService("")
err := svc.SetConn("postgres://foo:bar@localhost:5432/baz")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = ToConnData("/foo/bar") err = svc.SetConn("/foo/bar/baz.gdbm")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = ToConnData("/foo/bar/") err = svc.SetConn("foo/bar/baz.gdbm")
if err != nil {
t.Fatal(err)
}
_, err = ToConnData("foo/bar")
if err == nil { if err == nil {
t.Fatalf("expected error") t.Fatalf("expected error")
} }
_, err = ToConnData("http://foo/bar") err = svc.SetConn("http://foo/bar")
if err == nil {
t.Fatalf("expected error")
}
err = svc.SetConn("foo/bar/baz.txt")
if err == nil {
t.Fatalf("expected error")
}
err = svc.SetConn("/foo/bar")
if err == nil {
t.Fatalf("expected error")
}
err = svc.SetConn("foo/bar")
if err == nil { if err == nil {
t.Fatalf("expected error") t.Fatalf("expected error")
} }

View File

@ -4,7 +4,6 @@ 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"
@ -12,6 +11,7 @@ import (
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/initializers"
gdbmstorage "git.grassecon.net/urdt/ussd/internal/storage/db/gdbm" gdbmstorage "git.grassecon.net/urdt/ussd/internal/storage/db/gdbm"
) )
@ -27,34 +27,58 @@ type StorageService interface {
} }
type MenuStorageService struct { type MenuStorageService struct {
conn ConnData //dbDir string
conn connData
resourceDir string resourceDir string
resourceStore db.Db resourceStore db.Db
stateStore db.Db stateStore db.Db
userDataStore db.Db userDataStore db.Db
} }
func buildConnStr() string {
host := initializers.GetEnv("DB_HOST", "localhost")
user := initializers.GetEnv("DB_USER", "postgres")
password := initializers.GetEnv("DB_PASSWORD", "")
dbName := initializers.GetEnv("DB_NAME", "")
port := initializers.GetEnv("DB_PORT", "5432")
connString := fmt.Sprintf(
"postgres://%s:%s@%s:%s/%s",
user, password, host, port, dbName,
)
logg.Debugf("pg conn string", "conn", connString)
return connString
}
func NewMenuStorageService(resourceDir string) *MenuStorageService { func NewMenuStorageService(resourceDir string) *MenuStorageService {
return &MenuStorageService{ return &MenuStorageService{
resourceDir: resourceDir, resourceDir: resourceDir,
} }
} }
func (ms *MenuStorageService) WithConn(conn ConnData) *MenuStorageService { func (ms *MenuStorageService) SetConn(connStr string) error {
ms.conn = conn o, err := toConnData(connStr)
return ms if err != nil {
return err
}
ms.conn = o
return nil
} }
func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, section string) (db.Db, error) { func (ms *MenuStorageService) getOrCreateDb(ctx context.Context, existingDb db.Db, fileName string) (db.Db, error) {
var newDb db.Db var newDb db.Db
var err error var err error
// database, ok := ctx.Value("Database").(string)
// if !ok {
// return nil, fmt.Errorf("failed to select the database")
// }
if existingDb != nil { if existingDb != nil {
return existingDb, nil return existingDb, nil
} }
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()
@ -63,13 +87,11 @@ 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())
} }
logg.DebugCtxf(ctx, "connecting to db", "conn", connStr) err = newDb.Connect(ctx, ms.conn.String())
err = newDb.Connect(ctx, connStr)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"path/filepath"
"time" "time"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
@ -28,6 +27,7 @@ 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,46 +39,39 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
FlagCount: uint32(128), FlagCount: uint32(128),
} }
connStr, err := filepath.Abs(".test_state/state.gdbm") dbDir := ".test_state"
if err != nil {
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 resourceDir := scriptDir
//menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir)
menuStorageService := storage.NewMenuStorageService(resourceDir) menuStorageService := storage.NewMenuStorageService(resourceDir)
menuStorageService.WithConn(conn) //err := menuStorageService.EnsureDbDir()
err := menuStorageService.SetConn(dbDir)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "conn error: %v", err) fmt.Fprintf(os.Stderr, err.Error())
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, "resource error: %v", err) fmt.Fprintf(os.Stderr, err.Error())
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, "persister error: %v", err) fmt.Fprintf(os.Stderr, err.Error())
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, "userdb error: %v", err) fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
} }
dbResource, ok := rs.(*resource.DbResource) dbResource, ok := rs.(*resource.DbResource)
if !ok { if !ok {
fmt.Fprintf(os.Stderr, "dbresource cast error") fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
} }

View File

@ -1,15 +0,0 @@
package testutil
import (
"testing"
)
func TestCreateEngine(t *testing.T) {
o, clean, eventC := TestEngine("foo")
defer clean()
defer func() {
<-eventC
close(eventC)
}()
_ = o
}

View File

@ -7,7 +7,6 @@ import (
"log" "log"
"math/rand" "math/rand"
"os" "os"
"path/filepath"
"regexp" "regexp"
"testing" "testing"
@ -18,6 +17,7 @@ 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,11 +25,6 @@ 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()
@ -86,8 +81,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()