extend for form type requests
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2025-07-11 13:46:15 +10:00
parent d658a46a3f
commit 7905823731
4 changed files with 114 additions and 2 deletions

View File

@@ -184,6 +184,35 @@ func ReadInput(data []byte, testDefinitions *TestDefinitions) {
// Create a normal string map for all the body key-value pairs
thisTestCase.Header = OrderedToStringMap(val.(orderedmap.OrderedMap))
}
// Form
if val, ok := thisTestCaseMap.Get("form"); ok {
// Turn the original string into json
bytes, err := json.Marshal(val)
if err != nil {
error := fmt.Sprintf("Error mnarshalling request form for test case : '%s'\n", err)
panic(error)
}
// Now that we have json, convert it to an interface that we can play with
var jsonData interface{}
err = json.Unmarshal(bytes, &jsonData)
if err != nil {
error := fmt.Sprintf("Error processing request form for test case : '%s'\n", err)
panic(error)
}
// Search for any keys in the body that we need to replace with a dynamic random value
results := findRandom(nil, jsonData)
// store the results back into the body
newBytes, err := json.Marshal(results)
if err != nil {
error := fmt.Sprintf("Error turning form interface back into json for test case : '%s'\n", err)
panic(error)
}
thisTestCase.Form = newBytes
//fmt.Printf("Form marshalled:\n%v\n", string(newBytes))
}
// Expect - this is more tricky since it is yet another json fragment
if val, ok := thisTestCaseMap.Get("expect"); ok {
@@ -205,6 +234,7 @@ func ReadInput(data []byte, testDefinitions *TestDefinitions) {
thisTestCase.Expect = *expectOptions
}
}
testDefinitions.TestCases = append(testDefinitions.TestCases, *thisTestCase)
}
}