summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-08-22 16:24:41 +0200
committerJacob Vosmaer <jacob@gitlab.com>2017-08-23 10:45:20 +0200
commitc47b947a7360f21cc1438462587c6e284b40e230 (patch)
treef11b41d95001494ab7d0dabc60eeae10419db88a /spec/lib/gitlab/git
parentdc7c6bede27abd4507072276ef23b40a74ee297a (diff)
downloadgitlab-ce-c47b947a7360f21cc1438462587c6e284b40e230.tar.gz
Move GitHooksService tests
Diffstat (limited to 'spec/lib/gitlab/git')
-rw-r--r--spec/lib/gitlab/git/hooks_service_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/hooks_service_spec.rb b/spec/lib/gitlab/git/hooks_service_spec.rb
new file mode 100644
index 00000000000..e9c0209fe3b
--- /dev/null
+++ b/spec/lib/gitlab/git/hooks_service_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+
+describe Gitlab::Git::HooksService, seed_helper: true do
+ let(:committer) { Gitlab::Git::Committer.new('Jane Doe', 'janedoe@example.com', 'user-456') }
+ let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, 'project-123') }
+ let(:service) { described_class.new }
+
+ before do
+ @blankrev = Gitlab::Git::BLANK_SHA
+ @oldrev = SeedRepo::Commit::PARENT_ID
+ @newrev = SeedRepo::Commit::ID
+ @ref = 'refs/heads/feature'
+ end
+
+ describe '#execute' do
+ context 'when receive hooks were successful' do
+ it 'calls post-receive hook' do
+ hook = double(trigger: [true, nil])
+ expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook)
+
+ service.execute(committer, repository, @blankrev, @newrev, @ref) { }
+ end
+ end
+
+ context 'when pre-receive hook failed' do
+ it 'does not call post-receive hook' do
+ expect(service).to receive(:run_hook).with('pre-receive').and_return([false, ''])
+ expect(service).not_to receive(:run_hook).with('post-receive')
+
+ expect do
+ service.execute(committer, repository, @blankrev, @newrev, @ref)
+ end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
+ end
+ end
+
+ context 'when update hook failed' do
+ it 'does not call post-receive hook' do
+ expect(service).to receive(:run_hook).with('pre-receive').and_return([true, nil])
+ expect(service).to receive(:run_hook).with('update').and_return([false, ''])
+ expect(service).not_to receive(:run_hook).with('post-receive')
+
+ expect do
+ service.execute(committer, repository, @blankrev, @newrev, @ref)
+ end.to raise_error(Gitlab::Git::HooksService::PreReceiveError)
+ end
+ end
+ end
+end