Skip to content
Snippets Groups Projects
Commit 03015e48 authored by Alex Ellis (VMware)'s avatar Alex Ellis (VMware)
Browse files

Add test for Http_path for watchdog.

This test takes inspiration from the PR from @telackey with changes
to make it more maintainable. Since the test does not require
changes to the code, I wanted to add it before merging changes.

Ref: https://github.com/openfaas/faas/pull/789



Signed-off-by: default avatarAlex Ellis (VMware) <alexellis2@gmail.com>
parent a4c867fd
No related branches found
No related tags found
No related merge requests found
......@@ -490,6 +490,43 @@ func TestHealthHandler_SatusMethoNotAllowed_ForWriteableVerbs(t *testing.T) {
}
}
func TestHandler_HasFullPathAndQueryInFunction_WithCgi_Mode(t *testing.T) {
rr := httptest.NewRecorder()
body := ""
wantPath := "/my/full/path"
wantQuery := "q=x"
requestURI := wantPath + "?" + wantQuery
req, err := http.NewRequest(http.MethodPost, requestURI, bytes.NewBufferString(body))
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_Path="+wantPath) {
t.Errorf(config.faasProcess+" should print: Http_Path="+wantPath+", got: %s\n", val)
}
if !strings.Contains(val, "Http_Query="+wantQuery) {
t.Errorf(config.faasProcess+" should print: Http_Query="+wantQuery+", got: %s\n", val)
}
}
func removeLockFile() error {
path := filepath.Join(os.TempDir(), ".lock")
log.Printf("Removing lock-file : %s\n", path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment