diff --git a/test/hooks.json.tmpl b/test/hooks.json.tmpl index 0a8aead..d65d1d3 100644 --- a/test/hooks.json.tmpl +++ b/test/hooks.json.tmpl @@ -136,5 +136,49 @@ } } } + }, + { + "id": "capture-command-output-on-success-not-by-default", + "pass-arguments-to-command": [ + { + "source": "string", + "name": "exit=0" + } + ], + "execute-command": "{{ .Hookecho }}" + }, + { + "id": "capture-command-output-on-success-yes-with-flag", + "pass-arguments-to-command": [ + { + "source": "string", + "name": "exit=0" + } + ], + "execute-command": "{{ .Hookecho }}", + "include-command-output-in-response": true + }, + { + "id": "capture-command-output-on-error-not-by-default", + "pass-arguments-to-command": [ + { + "source": "string", + "name": "exit=1" + } + ], + "execute-command": "{{ .Hookecho }}", + "include-command-output-in-response": true + }, + { + "id": "capture-command-output-on-error-yes-with-extra-flag", + "pass-arguments-to-command": [ + { + "source": "string", + "name": "exit=1" + } + ], + "execute-command": "{{ .Hookecho }}", + "include-command-output-in-response": true, + "include-command-output-in-response-on-error": true } ] diff --git a/test/hooks.yaml.tmpl b/test/hooks.yaml.tmpl index 176a76d..c0377e5 100644 --- a/test/hooks.yaml.tmpl +++ b/test/hooks.yaml.tmpl @@ -73,3 +73,27 @@ include-command-output-in-response: true id: gitlab command-working-directory: / +- id: capture-command-output-on-success-not-by-default + pass-arguments-to-command: + - source: string + name: exit=0 + execute-command: '{{ .Hookecho }}' +- id: capture-command-output-on-success-yes-with-flag + pass-arguments-to-command: + - source: string + name: exit=0 + execute-command: '{{ .Hookecho }}' + include-command-output-in-response: true +- id: capture-command-output-on-error-not-by-default + pass-arguments-to-command: + - source: string + name: exit=1 + execute-command: '{{ .Hookecho }}' + include-command-output-in-response: true +- id: capture-command-output-on-error-yes-with-extra-flag + pass-arguments-to-command: + - source: string + name: exit=1 + execute-command: '{{ .Hookecho }}' + include-command-output-in-response: true + include-command-output-in-response-on-error: true diff --git a/webhook_test.go b/webhook_test.go index 93230d4..4373b16 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -51,7 +51,7 @@ func TestStaticParams(t *testing.T) { } // case 2: binary with spaces in its name - err = os.Symlink("/bin/true", "/tmp/with space") + err = os.Symlink("/bin/echo", "/tmp/with space") if err != nil { t.Fatalf("%v", err) } @@ -613,4 +613,12 @@ env: HOOK_head_commit.timestamp=2013-03-12T08:14:29-07:00 {"empty payload", "bitbucket", nil, `{}`, false, http.StatusOK, `Hook rules were not satisfied.`}, // test with no configured http return code, should default to 200 OK {"empty payload", "gitlab", nil, `{}`, false, http.StatusOK, `Hook rules were not satisfied.`}, + + // test capturing command output + {"don't capture output on success by default", "capture-command-output-on-success-not-by-default", nil, `{}`, false, http.StatusOK, ``}, + {"capture output on success with flag set", "capture-command-output-on-success-yes-with-flag", nil, `{}`, false, http.StatusOK, `arg: exit=0 +`}, + {"don't capture output on error by default", "capture-command-output-on-error-not-by-default", nil, `{}`, false, http.StatusInternalServerError, `Error occurred while executing the hook's command. Please check your logs for more details.`}, + {"capture output on error with extra flag set", "capture-command-output-on-error-yes-with-extra-flag", nil, `{}`, false, http.StatusInternalServerError, `arg: exit=1 +`}, }