Commit f3512031 authored by Elan Ruusamäe's avatar Elan Ruusamäe Committed by Sean McGivern

DRY: add helpers for expect hook calls

parent 37148a6c
...@@ -26,10 +26,10 @@ describe GitlabCustomHook do ...@@ -26,10 +26,10 @@ describe GitlabCustomHook do
end end
# global hooks multiplexed # global hooks multiplexed
def create_global_hooks_d(which) def create_global_hooks_d(which, hook_name = 'hook')
create_hook('hooks/pre-receive.d/hook', which) create_hook('hooks/pre-receive.d/' + hook_name, which)
create_hook('hooks/update.d/hook', which) create_hook('hooks/update.d/' + hook_name, which)
create_hook('hooks/post-receive.d/hook', which) create_hook('hooks/post-receive.d/' + hook_name, which)
end end
# repo hooks # repo hooks
...@@ -40,10 +40,10 @@ describe GitlabCustomHook do ...@@ -40,10 +40,10 @@ describe GitlabCustomHook do
end end
# repo hooks multiplexed # repo hooks multiplexed
def create_repo_hooks_d(which) def create_repo_hooks_d(which, hook_name = 'hook')
create_hook('custom_hooks/pre-receive.d/hook', which) create_hook('custom_hooks/pre-receive.d/' + hook_name, which)
create_hook('custom_hooks/update.d/hook', which) create_hook('custom_hooks/update.d/' + hook_name, which)
create_hook('custom_hooks/post-receive.d/hook', which) create_hook('custom_hooks/post-receive.d/' + hook_name, which)
end end
def cleanup_hook_setup def cleanup_hook_setup
...@@ -51,6 +51,20 @@ describe GitlabCustomHook do ...@@ -51,6 +51,20 @@ describe GitlabCustomHook do
FileUtils.rm_rf(File.join(tmp_root_path, 'hooks')) FileUtils.rm_rf(File.join(tmp_root_path, 'hooks'))
end end
def expect_call_receive_hook(path)
expect(gitlab_custom_hook)
.to receive(:call_receive_hook)
.with(hook_path(path), changes)
.and_call_original
end
def expect_call_update_hook(path)
expect(gitlab_custom_hook)
.to receive(:system)
.with(vars, hook_path(path), ref_name, old_value, new_value)
.and_call_original
end
# setup paths # setup paths
# <repository>.git/hooks/ - symlink to gitlab-shell/hooks global dir # <repository>.git/hooks/ - symlink to gitlab-shell/hooks global dir
# <repository>.git/hooks/<hook_name> - executed by git itself, this is gitlab-shell/hooks/<hook_name> # <repository>.git/hooks/<hook_name> - executed by git itself, this is gitlab-shell/hooks/<hook_name>
...@@ -175,15 +189,9 @@ describe GitlabCustomHook do ...@@ -175,15 +189,9 @@ describe GitlabCustomHook do
end end
it "only executes the global hook" do it "only executes the global hook" do
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect_call_receive_hook("custom_hooks/pre-receive.d/hook")
.with(hook_path("custom_hooks/pre-receive.d/hook"), changes) expect_call_update_hook("custom_hooks/update.d/hook")
.and_call_original expect_call_receive_hook("custom_hooks/post-receive.d/hook")
expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path("custom_hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path("custom_hooks/post-receive.d/hook"), changes)
.and_call_original
gitlab_custom_hook.pre_receive(changes) gitlab_custom_hook.pre_receive(changes)
gitlab_custom_hook.update(ref_name, old_value, new_value) gitlab_custom_hook.update(ref_name, old_value, new_value)
...@@ -204,24 +212,12 @@ describe GitlabCustomHook do ...@@ -204,24 +212,12 @@ describe GitlabCustomHook do
end end
it "executes the relevant hooks" do it "executes the relevant hooks" do
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect_call_receive_hook("hooks/pre-receive.d/hook")
.with(hook_path("hooks/pre-receive.d/hook"), changes) expect_call_receive_hook("custom_hooks/pre-receive.d/hook")
.and_call_original expect_call_update_hook("hooks/update.d/hook")
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect_call_update_hook("custom_hooks/update.d/hook")
.with(hook_path("custom_hooks/pre-receive.d/hook"), changes) expect_call_receive_hook("hooks/post-receive.d/hook")
.and_call_original expect_call_receive_hook("custom_hooks/post-receive.d/hook")
expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path("hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original
expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path("custom_hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path("hooks/post-receive.d/hook"), changes)
.and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path("custom_hooks/post-receive.d/hook"), changes)
.and_call_original
gitlab_custom_hook.pre_receive(changes) gitlab_custom_hook.pre_receive(changes)
gitlab_custom_hook.update(ref_name, old_value, new_value) gitlab_custom_hook.update(ref_name, old_value, new_value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment