menu-traversal-refactor #109
60
driver/groupdriver.go
Normal file
60
driver/groupdriver.go
Normal 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
|
|||||||
|
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
55
driver/setup_driver .go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package driver
|
||||||
carlos marked this conversation as resolved
Outdated
lash
commented
please remove space in filename please remove space in filename
carlos
commented
Updated by commit: 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
lash
commented
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?
carlos
commented
Updated by commit: 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
lash
commented
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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user
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
.