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

@@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"reflect"
"github.com/iancoleman/orderedmap"
)
@@ -229,13 +230,18 @@ func ReadHeaderTestCases(input orderedmap.OrderedMap, result *HeaderTests) {
func ReadBodyTestCases(input orderedmap.OrderedMap, result *BodyTests) {
result.Contains = make(map[string]string)
result.Equals = make(map[string]string)
result.HasKeys = make(map[string]string)
// TODO : Use tags in struct rather than hard coding all the different check types
// using https://stackoverflow.com/a/23840419 as an idea
// Contains check
if val, ok := input.Get("contains"); ok {
// Confirm this is an ordered map
if _, ok := val.(orderedmap.OrderedMap); !ok {
error := fmt.Sprintf("Unexpected json definition for Body Contains check. Type is '%v' but expected Object.\n", reflect.TypeOf(val))
panic(error)
}
containsMap := val.(orderedmap.OrderedMap)
result.Contains = OrderedToStringMap(containsMap)
}
@@ -247,9 +253,14 @@ func ReadBodyTestCases(input orderedmap.OrderedMap, result *BodyTests) {
}
// Has Keys check
if val, ok := input.Get("haskeys"); ok {
equalsMap := val.(orderedmap.OrderedMap)
result.HasKeys = OrderedToStringMap(equalsMap)
if val, ok := input.Get("hasKeys"); ok {
// This is an array not a map
hasKeysArray := val.([]interface{})
result.HasKeys = OrderedToStringSlice(hasKeysArray)
//equalsMap := val.(orderedmap.OrderedMap)
//result.HasKeys = OrderedToStringMap(equalsMap)
}
// TODO : remaining tests