From 0837933b6c83cf7d5c73d72364a407a6bed682e1 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 10 Oct 2024 16:53:59 +0300 Subject: [PATCH] move engine to testutil --- engine/engine.go | 111 ------------------------------------------ engine/tag_offline.go | 5 -- engine/tag_online.go | 5 -- 3 files changed, 121 deletions(-) delete mode 100644 engine/engine.go delete mode 100644 engine/tag_offline.go delete mode 100644 engine/tag_online.go diff --git a/engine/engine.go b/engine/engine.go deleted file mode 100644 index ea06193..0000000 --- a/engine/engine.go +++ /dev/null @@ -1,111 +0,0 @@ -package engine - - -import ( - "context" - "fmt" - "os" - "path" - - "git.defalsify.org/vise.git/engine" - "git.defalsify.org/vise.git/logging" - "git.defalsify.org/vise.git/resource" - "git.grassecon.net/urdt/ussd/internal/handlers" - "git.grassecon.net/urdt/ussd/internal/handlers/server" - "git.grassecon.net/urdt/ussd/internal/storage" - testdataloader "github.com/peteole/testdata-loader" -) - -var ( - baseDir = testdataloader.GetBasePath() - logg = logging.NewVanilla() - scriptDir = path.Join(baseDir, "services", "registration") -) - -func TestEngine(sessionId string) (engine.Engine, func()) { - var accountService server.AccountServiceInterface - 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) - } - - if OnlineTestEnabled { - accountService = &server.AccountService{} - } else { - accountService = &server.MockAccountService{} - } - hl, err := lhs.GetHandler(accountService) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - os.Exit(1) - } - - en := lhs.GetEngine() - en = en.WithFirst(hl.Init) - - cleanFn := func() { - err := en.Finish() - if err != nil { - logg.Errorf(err.Error()) - } - - err = menuStorageService.Close() - if err != nil { - logg.Errorf(err.Error()) - } - logg.Infof("testengine storage closed") - } - - //en = en.WithDebug(nil) - return en, cleanFn -} - diff --git a/engine/tag_offline.go b/engine/tag_offline.go deleted file mode 100644 index d81433e..0000000 --- a/engine/tag_offline.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !online - -package engine - -const OnlineTestEnabled = false \ No newline at end of file diff --git a/engine/tag_online.go b/engine/tag_online.go deleted file mode 100644 index a2ba80b..0000000 --- a/engine/tag_online.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build online - -package engine - -const OnlineTestEnabled = true \ No newline at end of file