89 lines
1.8 KiB
Go
89 lines
1.8 KiB
Go
package enginetest
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"git.defalsify.org/vise.git/engine"
|
|
"git.defalsify.org/vise.git/logging"
|
|
"git.defalsify.org/vise.git/persist"
|
|
"git.defalsify.org/vise.git/resource"
|
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
|
)
|
|
var (
|
|
logg = logging.NewVanilla()
|
|
scriptDir = path.Join("services", "registration")
|
|
)
|
|
|
|
func TestEngine(sessionId string) (engine.Engine,*persist.Persister){
|
|
ctx := context.Background()
|
|
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
pfp := path.Join(scriptDir, "pp.csv")
|
|
|
|
cfg := engine.Config{
|
|
Root: "root",
|
|
SessionId: sessionId,
|
|
OutputSize: uint32(160),
|
|
//FlagCount: uint32(16),
|
|
}
|
|
|
|
dbDir := ".test_state"
|
|
resourceDir := scriptDir
|
|
menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir)
|
|
|
|
err := menuStorageService.EnsureDbDir()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
rs, err := menuStorageService.GetResource(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
pe, err := menuStorageService.GetPersister(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
userdatastore, err := menuStorageService.GetUserdataDb(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
dbResource, ok := rs.(*resource.DbResource)
|
|
if !ok {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs)
|
|
lhs.SetDataStore(&userdatastore)
|
|
lhs.SetPersister(pe)
|
|
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
hl, err := lhs.GetHandler()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
en := lhs.GetEngine()
|
|
en = en.WithFirst(hl.Init)
|
|
|
|
//en = en.WithDebug(nil)
|
|
return en,pe
|
|
|
|
}
|