implemented header contains test
This commit is contained in:
@@ -1,6 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CheckResults(testCase *TestCase) (bool, error) {
|
||||
|
||||
// Check headers
|
||||
for k, v := range testCase.Expect.Header.Contains {
|
||||
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)
|
||||
if err != nil {
|
||||
error := fmt.Sprintf("unable to convert http_status expected value '%s' to int : %s", v, err)
|
||||
return false, errors.New(error)
|
||||
}
|
||||
if statusCode != testCase.ResultStatusCode {
|
||||
return false, nil
|
||||
}
|
||||
} else { // any other contains check
|
||||
checkFound := false
|
||||
for hKey, hVal := range testCase.ResultHeaders {
|
||||
if k == hKey {
|
||||
fmt.Printf("Found header key '%s', checking value '%s' matches test definition '%s'\n", hKey, hVal, v)
|
||||
|
||||
for i := range hVal {
|
||||
if strings.Contains(hVal[i], v) {
|
||||
fmt.Printf("Found match '%s' = '%s'\n", hVal[i], v)
|
||||
checkFound = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !checkFound {
|
||||
fmt.Printf("Expected to find header key-value of '%s:%s' but no matching value was found\n", k, v)
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user