Skip to content

Commit

Permalink
Add test to show TransferEncoding being passed to function
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 6, 2020
1 parent 6a30ce1 commit 4873e08
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions watchdog/requesthandler_test.go
Expand Up @@ -26,6 +26,45 @@ func TestHandler_make(t *testing.T) {
}
}

func TestHandler_TransferEncodingPassedToFunction(t *testing.T) {
rr := httptest.NewRecorder()

body := "Message"
req, err := http.NewRequest(http.MethodPost, "/", bytes.NewBufferString(body))
req.TransferEncoding = []string{
"chunked",
}
req.ContentLength = -1

if err != nil {
t.Fatal(err)
}

config := WatchdogConfig{
faasProcess: "env",
cgiHeaders: true,
}
handler := makeRequestHandler(&config)
handler(rr, req)

required := http.StatusOK
if status := rr.Code; status != required {
t.Errorf("handler returned wrong status code - got: %v, want: %v",
status, required)
}

read, _ := ioutil.ReadAll(rr.Body)
val := string(read)
if !strings.Contains(val, `Http_ContentLength=-1`) {
t.Errorf(config.faasProcess+" should print: Http_ContentLength=-1, got: %s\n", val)
}

if !strings.Contains(val, "Http_Transfer_Encoding") {
t.Errorf(config.faasProcess+" should print: Http_Transfer_Encoding=chunked, got: %s\n", val)
}

}

func TestHandler_HasCustomHeaderInFunction_WithCgi_Mode(t *testing.T) {
rr := httptest.NewRecorder()

Expand Down

0 comments on commit 4873e08

Please sign in to comment.