2015-11-25 19:20:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-22 10:24:41 -04:00
|
|
|
describe Gitlab::Git::HooksService, seed_helper: true do
|
2017-10-25 13:01:57 -04:00
|
|
|
let(:gl_id) { 'user-456' }
|
|
|
|
let(:gl_username) { 'janedoe' }
|
|
|
|
let(:user) { Gitlab::Git::User.new(gl_username, 'Jane Doe', 'janedoe@example.com', gl_id) }
|
2017-08-22 10:24:41 -04:00
|
|
|
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, 'project-123') }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:service) { described_class.new }
|
2017-10-25 13:01:57 -04:00
|
|
|
let(:blankrev) { Gitlab::Git::BLANK_SHA }
|
|
|
|
let(:oldrev) { SeedRepo::Commit::PARENT_ID }
|
|
|
|
let(:newrev) { SeedRepo::Commit::ID }
|
|
|
|
let(:ref) { 'refs/heads/feature' }
|
2015-11-25 19:20:40 -05:00
|
|
|
|
|
|
|
describe '#execute' do
|
2015-12-01 00:22:45 -05:00
|
|
|
context 'when receive hooks were successful' do
|
2017-10-25 13:01:57 -04:00
|
|
|
let(:hook) { double(:hook) }
|
|
|
|
|
|
|
|
it 'calls all three hooks' do
|
2015-12-01 00:22:45 -05:00
|
|
|
expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
|
2017-10-25 13:01:57 -04:00
|
|
|
expect(hook).to receive(:trigger).with(gl_id, gl_username, blankrev, newrev, ref)
|
|
|
|
.exactly(3).times.and_return([true, nil])
|
2015-12-01 00:22:45 -05:00
|
|
|
|
2017-10-25 13:01:57 -04:00
|
|
|
service.execute(user, repository, blankrev, newrev, ref) { }
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-01 00:22:45 -05:00
|
|
|
context 'when pre-receive hook failed' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not call post-receive hook' do
|
2016-07-04 08:30:22 -04:00
|
|
|
expect(service).to receive(:run_hook).with('pre-receive').and_return([false, ''])
|
2015-11-25 19:20:40 -05:00
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
2015-12-01 12:31:44 -05:00
|
|
|
expect do
|
2017-10-25 13:01:57 -04:00
|
|
|
service.execute(user, repository, blankrev, newrev, ref)
|
2017-08-22 08:18:09 -04:00
|
|
|
end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-01 00:22:45 -05:00
|
|
|
context 'when update hook failed' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not call post-receive hook' do
|
2016-07-04 08:30:22 -04:00
|
|
|
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-01 00:22:45 -05:00
|
|
|
expect(service).not_to receive(:run_hook).with('post-receive')
|
|
|
|
|
2015-12-01 12:31:44 -05:00
|
|
|
expect do
|
2017-10-25 13:01:57 -04:00
|
|
|
service.execute(user, repository, blankrev, newrev, ref)
|
2017-08-22 08:18:09 -04:00
|
|
|
end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
|
2015-12-01 00:22:45 -05:00
|
|
|
end
|
|
|
|
end
|
2015-11-25 19:20:40 -05:00
|
|
|
end
|
|
|
|
end
|