Skip to content

Commit

Permalink
Add tests for capturing command output
Browse files Browse the repository at this point in the history
and fix running tests on macOS, where there is no
/bin/true...
  • Loading branch information
Greg Dubicki committed Nov 11, 2017
1 parent 0d3d290 commit e2f6e4e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
44 changes: 44 additions & 0 deletions test/hooks.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
24 changes: 24 additions & 0 deletions test/hooks.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
`},
}

0 comments on commit e2f6e4e

Please sign in to comment.