@@ -18,23 +18,24 @@ import (
18
18
"bytes"
19
19
"encoding/json"
20
20
"fmt"
21
- "io"
22
21
"net/http"
23
22
"strings"
24
23
"time"
25
24
)
26
25
27
26
// WaitForSuccessfulHTTPRequest waits for an HTTP request to be successful
28
- func WaitForSuccessfulHTTPRequest (namespace , httpMethod , uri , path , bodyFormat string , body io. Reader , timeoutInMin int ) error {
27
+ func WaitForSuccessfulHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , bodyContent string , timeoutInMin int ) error {
29
28
return WaitFor (namespace , fmt .Sprintf ("HTTP %s request on path '%s' to be successful" , httpMethod , path ), time .Duration (timeoutInMin )* time .Minute , func () (bool , error ) {
30
- return IsHTTPRequestSuccessful (namespace , httpMethod , uri , path , bodyFormat , body )
29
+ return IsHTTPRequestSuccessful (namespace , httpMethod , uri , path , bodyFormat , bodyContent )
31
30
})
32
31
}
33
32
34
33
// ExecuteHTTPRequest executes an HTTP request
35
- func ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat string , body io.Reader ) (* http.Response , error ) {
36
- request , err := http .NewRequest (httpMethod , uri + "/" + path , body )
37
- if body != nil && len (bodyFormat ) > 0 {
34
+ func ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , bodyContent string ) (* http.Response , error ) {
35
+ GetLogger (namespace ).Debugf ("ExecuteHTTPRequest %s on uri %s, with path %s, %s bodyContent %s" , httpMethod , uri , path , bodyFormat , bodyContent )
36
+
37
+ request , err := http .NewRequest (httpMethod , uri + "/" + path , strings .NewReader (bodyContent ))
38
+ if len (bodyContent ) > 0 && len (bodyFormat ) > 0 {
38
39
switch bodyFormat {
39
40
case "json" :
40
41
request .Header .Add ("Content-Type" , "application/json" )
@@ -54,8 +55,8 @@ func ExecuteHTTPRequest(namespace, httpMethod, uri, path, bodyFormat string, bod
54
55
}
55
56
56
57
// IsHTTPRequestSuccessful makes and checks whether an http request is successful
57
- func IsHTTPRequestSuccessful (namespace , httpMethod , uri , path , bodyFormat string , body io. Reader ) (bool , error ) {
58
- response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , body )
58
+ func IsHTTPRequestSuccessful (namespace , httpMethod , uri , path , bodyFormat , bodyContent string ) (bool , error ) {
59
+ response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , bodyContent )
59
60
if err != nil {
60
61
return false , err
61
62
}
@@ -73,8 +74,8 @@ func CheckHTTPResponseSuccessful(namespace string, response *http.Response) bool
73
74
}
74
75
75
76
// IsHTTPResponseArraySize makes and checks whether an http request returns an array of a specific size
76
- func IsHTTPResponseArraySize (namespace , httpMethod , uri , path string , bodyFormat string , body io. Reader , arraySize int ) (bool , error ) {
77
- response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , body )
77
+ func IsHTTPResponseArraySize (namespace , httpMethod , uri , path string , bodyFormat , bodyContent string , arraySize int ) (bool , error ) {
78
+ response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , bodyContent )
78
79
if err != nil {
79
80
return false , err
80
81
}
@@ -96,8 +97,8 @@ func IsHTTPResponseArraySize(namespace, httpMethod, uri, path string, bodyFormat
96
97
}
97
98
98
99
// DoesHTTPResponseContain checks whether the response of an http request contains a certain string
99
- func DoesHTTPResponseContain (namespace , httpMethod , uri , path string , bodyFormat string , body io. Reader , responseContent string ) (bool , error ) {
100
- response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , body )
100
+ func DoesHTTPResponseContain (namespace , httpMethod , uri , path string , bodyFormat , bodyContent string , responseContent string ) (bool , error ) {
101
+ response , err := ExecuteHTTPRequest (namespace , httpMethod , uri , path , bodyFormat , bodyContent )
101
102
if err != nil {
102
103
return false , err
103
104
}
0 commit comments