mirror of
https://github.com/openfaas/faas.git
synced 2025-06-20 04:56:38 +00:00
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: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user