2015-12-23 02:04:40 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe GitHooksService do
|
2015-12-23 02:04:40 +05:30
|
|
|
include RepoHelpers
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:service) { described_class.new }
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
@blankrev = Gitlab::Git::BLANK_SHA
|
|
|
|
@oldrev = sample_commit.parent_id
|
|
|
|
@newrev = sample_commit.id
|
|
|
|
@ref = 'refs/heads/feature'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'when receive hooks were successful' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'calls post-receive hook' do
|
2016-08-24 12:49:21 +05:30
|
|
|
hook = double(trigger: [true, nil])
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
service.execute(user, project, @blankrev, @newrev, @ref) { }
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pre-receive hook failed' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not call post-receive hook' do
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(service).to receive(:run_hook).with('pre-receive').and_return([false, ''])
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
|
|
|
expect do
|
2017-09-10 17:25:29 +05:30
|
|
|
service.execute(user, project, @blankrev, @newrev, @ref)
|
2015-12-23 02:04:40 +05:30
|
|
|
end.to raise_error(GitHooksService::PreReceiveError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when update hook failed' do
|
2016-09-13 17:45:13 +05:30
|
|
|
it 'does not call post-receive hook' do
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil])
|
|
|
|
expect(service).to receive(:run_hook).with('update').and_return([false, ''])
|
2015-12-23 02:04:40 +05:30
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
|
|
|
expect do
|
2017-09-10 17:25:29 +05:30
|
|
|
service.execute(user, project, @blankrev, @newrev, @ref)
|
2015-12-23 02:04:40 +05:30
|
|
|
end.to raise_error(GitHooksService::PreReceiveError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|