This commit is contained in:
@@ -8,16 +8,40 @@ import (
|
||||
)
|
||||
|
||||
func CheckResults(testCase *TestCase) (bool, error) {
|
||||
var result bool = true
|
||||
|
||||
// Check headers
|
||||
result, err := HeaderContains(testCase)
|
||||
headerContains, err := HeaderContains(testCase)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result = result && headerContains
|
||||
|
||||
headerEquals, err := HeaderEquals(testCase)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result = result && headerEquals
|
||||
|
||||
// Check body
|
||||
bodyContains, err := BodyContains(testCase)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result = result && bodyContains
|
||||
|
||||
bodyHasKeys, err := BodyHasKeys(testCase)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result = result && bodyHasKeys
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func HeaderContains(testCase *TestCase) (bool, error) {
|
||||
for k, v := range testCase.Expect.Header.Contains {
|
||||
fmt.Printf("Header contains check '%s'='%s'\n", k, v)
|
||||
//fmt.Printf("Header contains check '%s'='%s'\n", k, v)
|
||||
|
||||
if k == "http_status" { // http status is a special case
|
||||
statusCode, err := strconv.Atoi(v)
|
||||
@@ -52,3 +76,56 @@ func HeaderContains(testCase *TestCase) (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func HeaderEquals(testCase *TestCase) (bool, error) {
|
||||
|
||||
for k, v := range testCase.Expect.Header.Equals {
|
||||
fmt.Printf("Header equals check '%s'='%s'\n", k, v)
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func BodyContains(testCase *TestCase) (bool, error) {
|
||||
for k, v := range testCase.Expect.Body.Contains {
|
||||
//fmt.Printf("Body contains check '%s'='%s'\n", k, v)
|
||||
|
||||
// If the body response was json then we stored it already when running the test
|
||||
if val, ok := testCase.ResultBodyMap[k]; ok {
|
||||
// TODO handle values other than string using a switch
|
||||
//fmt.Printf("Found key in body with response '%s'\n", val)
|
||||
|
||||
// Check that the value matched
|
||||
if strings.Contains(val.(string), v) {
|
||||
fmt.Printf("Key matches, success\n")
|
||||
} else {
|
||||
fmt.Printf("Body Contains check failed on key '%s'. Expected value '%s' but found '%s'\n", k, v, val)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
} else {
|
||||
// body did not contain the key we were looking for so return false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func BodyHasKeys(testCase *TestCase) (bool, error) {
|
||||
for _, key := range testCase.Expect.Body.HasKeys {
|
||||
// If the body response was json then we stored it already when running the test
|
||||
if _, ok := testCase.ResultBodyMap[key]; ok {
|
||||
fmt.Printf("Confirmed body has key '%s'\n", key)
|
||||
} else {
|
||||
fmt.Printf("Body HasKeys test failed, expected key '%s' not found\n", key)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user