Add unit test for the message body and headers
Adds unit tests for passing of the message body and the message headers.
This commit is contained in:
parent
a3266382fd
commit
42176fac4e
|
@ -281,8 +281,12 @@ func TestHeaderAndBody(t *testing.T) {
|
|||
|
||||
var cf Config
|
||||
|
||||
bodyIncluded := "this is the request body\nit is awesome"
|
||||
bodyIgnored := "this part of the body should be ignored\nIt is hopefully not present"
|
||||
bodyText := fmt.Sprintf("%s\n%s", bodyIncluded, bodyIgnored)
|
||||
|
||||
cf.Settings.BindAddress = "127.0.0.1:2088"
|
||||
cf.Settings.MaxBodySize = 4096
|
||||
cf.Settings.MaxBodySize = int64(len(bodyIncluded))
|
||||
cf.Hooks = make([]Hook, 0)
|
||||
cf.Hooks = append(cf.Hooks, Hook{Name: "hook", Command: fmt.Sprintf("tee %s", tempFile.Name()), Route: "/header_and_body"})
|
||||
|
||||
|
@ -320,7 +324,7 @@ func TestHeaderAndBody(t *testing.T) {
|
|||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
req.Body = io.NopCloser(bytes.NewReader([]byte("this is the request body\nit is awesome")))
|
||||
req.Body = io.NopCloser(bytes.NewReader([]byte(bodyText)))
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("http request error: %s", err)
|
||||
|
@ -348,8 +352,14 @@ func TestHeaderAndBody(t *testing.T) {
|
|||
}
|
||||
|
||||
// Assert the message body got passed as well
|
||||
if !strings.Contains(contents, bodyIncluded) {
|
||||
t.Fatal("Message body was not passed")
|
||||
}
|
||||
|
||||
// Assert the messaeg body got cropped
|
||||
if strings.Contains(contents, bodyIgnored) {
|
||||
t.Fatal("Cut-off after max-body size didn't happen")
|
||||
}
|
||||
}
|
||||
|
||||
func generateKeypair(keyfile string, certfile string, hostnames []string) error {
|
||||
|
|
Loading…
Reference in a new issue