implement feature to generate random test data
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
36
main.go
36
main.go
@@ -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
|
||||
|
Reference in New Issue
Block a user