menu-traversal-refactor #109

Closed
carlos wants to merge 24 commits from menu-traversal-refactor into master
2 changed files with 115 additions and 0 deletions
Showing only changes of commit d7bfdc62e9 - Show all commits

60
driver/groupdriver.go Normal file
View File

@ -0,0 +1,60 @@
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 []GroupTest `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 {
carlos marked this conversation as resolved Outdated
Outdated
Review

I prefer typedef instead of inline structs, the latter is hard to read.

should this be an extension of StepTest?

I prefer typedef instead of inline structs, the latter is hard to read. should this be an extension of StepTest?

Created a TestCase struct for generating the test cases: Commit : 810dd74e43.

Created a TestCase struct for generating the test cases: Commit : 810dd74e43936d999d2e6361c6b8a167c67a6317.
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
}

55
driver/setup_driver .go Normal file
View File

@ -0,0 +1,55 @@
package driver
carlos marked this conversation as resolved Outdated
Outdated
Review

please remove space in filename

please remove space in filename

Updated by commit: 3afe35b44f ,the setup driver functionality is now in the group driver.

Updated by commit: 3afe35b44f28cffbefe1a0f41b70a2c3ba1b4ccb ,the setup driver functionality is now in the group driver.
import (
"encoding/json"
"log"
"os"
)
type Step struct {
carlos marked this conversation as resolved Outdated
Outdated
Review

aren't these structs more or less the same as in the groupdriver.go

can't we just reuse the definitions?

aren't these structs more or less the same as in the groupdriver.go can't we just reuse the definitions?

Updated by commit: 3afe35b44f ,the setup driver functionality is now in the group driver.

Updated by commit: 3afe35b44f28cffbefe1a0f41b70a2c3ba1b4ccb ,the setup driver functionality is now in the group driver.
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 {
carlos marked this conversation as resolved Outdated
Outdated
Review

Can we please use regex here, match start of string

Can we please use regex here, match start of string
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
}