diff --git a/driver/groupdriver.go b/driver/groupdriver.go deleted file mode 100644 index f20d755..0000000 --- a/driver/groupdriver.go +++ /dev/null @@ -1,60 +0,0 @@ -package driver - -import ( - "encoding/json" - "os" -) - -type StepTest struct { - Input string `json:"input"` - ExpectedContent string `json:"expectedContent"` -} - -// Group represents a group of steps. -type GroupTest struct { - Name string `json:"name"` - Steps []Step `json:"steps"` -} - -// DataGroup represents the overall structure of the JSON. -type DataGroup struct { - Groups []Group `json:"groups"` -} - -func LoadTestGroups(filePath string) (DataGroup, error) { - var sessionsData DataGroup - data, err := os.ReadFile(filePath) - if err != nil { - return sessionsData, err - } - err = json.Unmarshal(data, &sessionsData) - return sessionsData, err -} - -func CreateTestCases(group DataGroup) []struct { - Name string - Input string - ExpectedContent string -} { - var tests []struct { - Name string - Input string - ExpectedContent string - } - for _, group := range group.Groups { - for _, step := range group.Steps { - // Create a test case for each group - tests = append(tests, struct { - Name string - Input string - ExpectedContent string - }{ - Name: group.Name, - Input: step.Input, - ExpectedContent: step.ExpectedContent, - }) - } - } - - return tests -} diff --git a/driver/testdata.go b/driver/testdata.go deleted file mode 100644 index 673d417..0000000 --- a/driver/testdata.go +++ /dev/null @@ -1,55 +0,0 @@ -package driver - -import ( - "encoding/json" - "log" - "os" -) - -type Step struct { - Input string `json:"input"` - ExpectedContent string `json:"expectedContent"` -} - -type Group struct { - Name string `json:"name"` - Steps []Step `json:"steps"` -} - -type Session struct { - Name string `json:"name"` - Groups []Group `json:"groups"` -} - -func ReadData() []Session { - data, err := os.ReadFile("test_setup.json") - if err != nil { - log.Fatalf("Failed to read file: %v", err) - } - // Unmarshal JSON data - var sessions []Session - err = json.Unmarshal(data, &sessions) - if err != nil { - log.Fatalf("Failed to unmarshal JSON: %v", err) - } - - return sessions -} - -func FilterGroupsByName(groups []Group, name string) []Group { - var filteredGroups []Group - for _, group := range groups { - if group.Name == name { - filteredGroups = append(filteredGroups, group) - } - } - return filteredGroups -} - -func Map[T any, U any](input []T, fn func(T) U) []U { - result := make([]U, len(input)) - for i, v := range input { - result[i] = fn(v) - } - return result -} diff --git a/engine/engine.go b/engine/engine.go deleted file mode 100644 index f597173..0000000 --- a/engine/engine.go +++ /dev/null @@ -1,109 +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