improve body contains check
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-03 15:42:25 +11:00
parent af7ee7f3c1
commit b2519287ef
8 changed files with 148 additions and 62 deletions

View File

@@ -25,7 +25,7 @@ func RunTest(testCase *TestCase) error {
}
client := &http.Client{Transport: tr}
fmt.Printf("Running test '%s'\n", testCase.Name)
fmt.Printf("\nRunning %s : %s\n", testCase.Name, testCase.Description)
// Determine URL
if len(testDefinitions.BaseUrl) > 0 {
@@ -50,8 +50,11 @@ func RunTest(testCase *TestCase) error {
requestType = testCase.Method
}
fmt.Printf("Preparing %s for endpoint %s\n", requestType, requestUrl)
// Create request
if len(testCase.Body) > 0 {
fmt.Printf("Adding body to request : %s\n", testCase.Body)
req, err = http.NewRequest(requestType, requestUrl, bytes.NewBuffer(testCase.Body))
} else {
req, err = http.NewRequest(requestType, requestUrl, nil)
@@ -87,6 +90,7 @@ func RunTest(testCase *TestCase) error {
}
// Perform request
fmt.Printf("Sending request\n")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
@@ -98,7 +102,7 @@ func RunTest(testCase *TestCase) error {
testCase.ResultStatusCode = resp.StatusCode
testCase.ResultHeaders = resp.Header
fmt.Printf("http_status:\n'%+v'\n", testCase.ResultStatusCode)
fmt.Printf("Status Code: %s\n", resp.Status)
fmt.Printf("Header response:\n%+v\n", testCase.ResultHeaders)
body, err := io.ReadAll(resp.Body)