summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-12-09 15:52:20 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-12-16 23:32:25 +0530
commitc937aec1f7ba1f102995fefaef2141e7ed90f5fd (patch)
tree203f2dcc15ae1d2ac61e34e6bf0b8553e1d05f92 /spec/lib/gitlab
parenta2b39feb1a3ae6fe2615418bb759bf39125e5d0e (diff)
downloadgitlab-ce-c937aec1f7ba1f102995fefaef2141e7ed90f5fd.tar.gz
Check the exit code while invoking git in the force push check.
Previously, we were calling out to `popen` without asserting on the returned exit-code. Now we raise a `RuntimeError` if the exit code is non-zero.
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/checks/force_push_spec.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/lib/gitlab/checks/force_push_spec.rb b/spec/lib/gitlab/checks/force_push_spec.rb
new file mode 100644
index 00000000000..f6288011494
--- /dev/null
+++ b/spec/lib/gitlab/checks/force_push_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Gitlab::Checks::ChangeAccess, lib: true do
+ let(:project) { create(:project) }
+
+ context "exit code checking" do
+ it "does not raise a runtime error if the `popen` call to git returns a zero exit code" do
+ allow(Gitlab::Popen).to receive(:popen).and_return(['normal output', 0])
+
+ expect { Gitlab::Checks::ForcePush.force_push?(project, 'oldrev', 'newrev') }.not_to raise_error
+ end
+
+ it "raises a runtime error if the `popen` call to git returns a non-zero exit code" do
+ allow(Gitlab::Popen).to receive(:popen).and_return(['error', 1])
+
+ expect { Gitlab::Checks::ForcePush.force_push?(project, 'oldrev', 'newrev') }.to raise_error(RuntimeError)
+ end
+ end
+end