2024-09-30 12:21:17 +02:00
|
|
|
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 {
|
2024-10-07 18:05:36 +02:00
|
|
|
data, err := os.ReadFile("test_setup.json")
|
2024-09-30 12:21:17 +02:00
|
|
|
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
|
|
|
|
}
|