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

spec/custom_hooks: cleanup helpers not to repeat repo path parameter

parent 8910d4b0
...@@ -17,33 +17,33 @@ describe GitlabCustomHook do ...@@ -17,33 +17,33 @@ describe GitlabCustomHook do
let(:gitlab_custom_hook) { GitlabCustomHook.new(tmp_repo_path, 'key_1') } let(:gitlab_custom_hook) { GitlabCustomHook.new(tmp_repo_path, 'key_1') }
def hook_path(repo_path, path) def hook_path(path)
File.join(repo_path, path.split('/')) File.join(tmp_repo_path, path.split('/'))
end end
def create_hook(repo_path, path, which) def create_hook(path, which)
FileUtils.ln_sf(which, hook_path(repo_path, path)) FileUtils.ln_sf(which, hook_path(path))
end end
# global hooks multiplexed # global hooks multiplexed
def create_global_hooks_d(path, which) def create_global_hooks_d(which)
create_hook(path, 'hooks/pre-receive.d/hook', which) create_hook('hooks/pre-receive.d/hook', which)
create_hook(path, 'hooks/update.d/hook', which) create_hook('hooks/update.d/hook', which)
create_hook(path, 'hooks/post-receive.d/hook', which) create_hook('hooks/post-receive.d/hook', which)
end end
# repo hooks # repo hooks
def create_repo_hooks(path, which) def create_repo_hooks(which)
create_hook(path, 'custom_hooks/pre-receive', which) create_hook('custom_hooks/pre-receive', which)
create_hook(path, 'custom_hooks/update', which) create_hook('custom_hooks/update', which)
create_hook(path, 'custom_hooks/post-receive', which) create_hook('custom_hooks/post-receive', which)
end end
# repo hooks multiplexed # repo hooks multiplexed
def create_repo_hooks_d(path, which) def create_repo_hooks_d(which)
create_hook(path, 'custom_hooks/pre-receive.d/hook', which) create_hook('custom_hooks/pre-receive.d/hook', which)
create_hook(path, 'custom_hooks/update.d/hook', which) create_hook('custom_hooks/update.d/hook', which)
create_hook(path, 'custom_hooks/post-receive.d/hook', which) create_hook('custom_hooks/post-receive.d/hook', which)
end end
def cleanup_hook_setup def cleanup_hook_setup
...@@ -84,8 +84,8 @@ describe GitlabCustomHook do ...@@ -84,8 +84,8 @@ describe GitlabCustomHook do
context 'with gl_id_test_hook' do context 'with gl_id_test_hook' do
before do before do
create_repo_hooks(tmp_repo_path, hook_gl_id) create_repo_hooks(hook_gl_id)
create_global_hooks_d(tmp_root_path, hook_gl_id) create_global_hooks_d(hook_gl_id)
end end
context 'pre_receive hook' do context 'pre_receive hook' do
...@@ -117,7 +117,7 @@ describe GitlabCustomHook do ...@@ -117,7 +117,7 @@ describe GitlabCustomHook do
context "having only successful repo hooks" do context "having only successful repo hooks" do
before do before do
create_repo_hooks(tmp_repo_path, hook_ok) create_repo_hooks(hook_ok)
end end
it "returns true" do it "returns true" do
...@@ -129,8 +129,8 @@ describe GitlabCustomHook do ...@@ -129,8 +129,8 @@ describe GitlabCustomHook do
context "having both successful repo and global hooks" do context "having both successful repo and global hooks" do
before do before do
create_repo_hooks(tmp_repo_path, hook_ok) create_repo_hooks(hook_ok)
create_global_hooks_d(tmp_root_path, hook_ok) create_global_hooks_d(hook_ok)
end end
it "returns true" do it "returns true" do
...@@ -142,8 +142,8 @@ describe GitlabCustomHook do ...@@ -142,8 +142,8 @@ describe GitlabCustomHook do
context "having failing repo and successful global hooks" do context "having failing repo and successful global hooks" do
before do before do
create_repo_hooks_d(tmp_repo_path, hook_fail) create_repo_hooks_d(hook_fail)
create_global_hooks_d(tmp_repo_path, hook_ok) create_global_hooks_d(hook_ok)
end end
it "returns false" do it "returns false" do
...@@ -154,13 +154,13 @@ describe GitlabCustomHook do ...@@ -154,13 +154,13 @@ describe GitlabCustomHook do
it "only executes the global hook" do it "only executes the global hook" do
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "custom_hooks/pre-receive.d/hook"), changes) .with(hook_path("custom_hooks/pre-receive.d/hook"), changes)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:system) expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path(tmp_repo_path, "custom_hooks/update.d/hook"), ref_name, old_value, new_value) .with(vars, hook_path("custom_hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "custom_hooks/post-receive.d/hook"), changes) .with(hook_path("custom_hooks/post-receive.d/hook"), changes)
.and_call_original .and_call_original
gitlab_custom_hook.pre_receive(changes) gitlab_custom_hook.pre_receive(changes)
...@@ -171,8 +171,8 @@ describe GitlabCustomHook do ...@@ -171,8 +171,8 @@ describe GitlabCustomHook do
context "having successful repo but failing global hooks" do context "having successful repo but failing global hooks" do
before do before do
create_repo_hooks_d(tmp_repo_path, hook_ok) create_repo_hooks_d(hook_ok)
create_global_hooks_d(tmp_repo_path, hook_fail) create_global_hooks_d(hook_fail)
end end
it "returns false" do it "returns false" do
...@@ -183,22 +183,22 @@ describe GitlabCustomHook do ...@@ -183,22 +183,22 @@ describe GitlabCustomHook do
it "executes the relevant hooks" do it "executes the relevant hooks" do
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "hooks/pre-receive.d/hook"), changes) .with(hook_path("hooks/pre-receive.d/hook"), changes)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "custom_hooks/pre-receive.d/hook"), changes) .with(hook_path("custom_hooks/pre-receive.d/hook"), changes)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:system) expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path(tmp_repo_path, "hooks/update.d/hook"), ref_name, old_value, new_value) .with(vars, hook_path("hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:system) expect(gitlab_custom_hook).to receive(:system)
.with(vars, hook_path(tmp_repo_path, "custom_hooks/update.d/hook"), ref_name, old_value, new_value) .with(vars, hook_path("custom_hooks/update.d/hook"), ref_name, old_value, new_value)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "hooks/post-receive.d/hook"), changes) .with(hook_path("hooks/post-receive.d/hook"), changes)
.and_call_original .and_call_original
expect(gitlab_custom_hook).to receive(:call_receive_hook) expect(gitlab_custom_hook).to receive(:call_receive_hook)
.with(hook_path(tmp_repo_path, "custom_hooks/post-receive.d/hook"), changes) .with(hook_path("custom_hooks/post-receive.d/hook"), changes)
.and_call_original .and_call_original
gitlab_custom_hook.pre_receive(changes) gitlab_custom_hook.pre_receive(changes)
......
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