implement feature to generate random test data
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-11 16:14:00 +11:00
parent aa65b1e784
commit 2afdacaa78
11 changed files with 500 additions and 15 deletions

36
main.go
View File

@@ -4,7 +4,9 @@ import (
"flag"
"fmt"
"os"
"reflect"
"strconv"
"strings"
"github.com/iancoleman/orderedmap"
)
@@ -12,6 +14,36 @@ import (
var testDefinitions *TestDefinitions
var captureValues *CaptureValues
func PrintStructContents(s interface{}, indentLevel int) string {
var result strings.Builder
val := reflect.ValueOf(s)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
typ := val.Type()
for i := 0; i < val.NumField(); i++ {
field := val.Field(i)
fieldType := typ.Field(i)
indent := strings.Repeat("\t", indentLevel)
result.WriteString(fmt.Sprintf("%s%s: ", indent, fieldType.Name))
switch field.Kind() {
case reflect.Struct:
result.WriteString("\n")
result.WriteString(PrintStructContents(field.Interface(), indentLevel+1))
default:
result.WriteString(fmt.Sprintf("%v\n", field.Interface()))
}
}
return result.String()
}
func main() {
var s []byte
var err error
@@ -43,6 +75,8 @@ func main() {
// Process the input json
ReadInput(s, testDefinitions)
//fmt.Println(PrintStructContents(testDefinitions.TestCases[1], 0))
// Perform specified test cases
for i := range testDefinitions.TestCases {
@@ -52,6 +86,7 @@ func main() {
}
RunTest(&testDefinitions.TestCases[i])
fmt.Printf("\nRunning checks on output\n")
success, err := CheckResults(&testDefinitions.TestCases[i])
if err != nil {
@@ -71,6 +106,7 @@ func main() {
// For debugging, just dump the output
//fmt.Printf("%+v\n", testDefinitions)
//fmt.Println(PrintStructContents(testDefinitions, 0))
}
// fileExists returns true if the specified file exists and is not a directory