add driver to group tests

This commit is contained in:
Carlosokumu 2024-10-07 16:42:48 +03:00
parent 0a92444ae8
commit 2ffe749c9d
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

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 []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
}