implement hasKeys check
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-01-03 11:55:56 +11:00
parent b2b27b2306
commit e1a1e5a49d
6 changed files with 129 additions and 21 deletions

View File

@@ -18,7 +18,7 @@ func RunTest(testCase *TestCase) error {
var requestUrl string
var requestType string
var req *http.Request
var bodyMap map[string]interface{}
//var bodyMap map[string]interface{}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: testDefinitions.Insecure},
@@ -110,21 +110,14 @@ func RunTest(testCase *TestCase) error {
testCase.ResultBody = string(body)
fmt.Printf("Body response:\n%s\n", testCase.ResultBody)
/*
// Something to store results in
ResultStatusCode int
ResultHeaders map[string]string
ResultBody string
*/
// We have no idea what the response will look like so use an interface and unmarshal manually as needed
if len(body) > 0 {
var b interface{}
json.Unmarshal(body, &b)
if b != nil {
bodyMap = b.(map[string]interface{})
testCase.ResultBodyMap = b.(map[string]interface{})
//bodyMap = b.(map[string]interface{})
}
}
// Iterate through testDefinitions.CaptureCases and see if there are any that match this test
@@ -136,7 +129,7 @@ func RunTest(testCase *TestCase) error {
for k, v := range captureData.Body.Data {
//fmt.Printf("Body capture %s = %s\n", k, v)
if val, ok := bodyMap[k]; ok {
if val, ok := testCase.ResultBodyMap[k]; ok {
// TODO handle values other than string using a switch
//fmt.Printf("Found matching capture in body with value : '%v', storing replacement with key '%s'\n", val, v)
captureValues.Data[v] = val.(string)