[QA] Fail early if a Git command fails
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
790a51a427
commit
95b5832366
3 changed files with 8 additions and 8 deletions
|
@ -12,6 +12,7 @@ module QA
|
||||||
module Git
|
module Git
|
||||||
class Repository
|
class Repository
|
||||||
include Scenario::Actable
|
include Scenario::Actable
|
||||||
|
RepositoryCommandError = Class.new(StandardError)
|
||||||
|
|
||||||
attr_writer :use_lfs
|
attr_writer :use_lfs
|
||||||
attr_accessor :env_vars
|
attr_accessor :env_vars
|
||||||
|
@ -205,6 +206,10 @@ module QA
|
||||||
output.chomp!
|
output.chomp!
|
||||||
Runtime::Logger.debug "Git: output=[#{output}], exitstatus=[#{status.exitstatus}]"
|
Runtime::Logger.debug "Git: output=[#{output}], exitstatus=[#{status.exitstatus}]"
|
||||||
|
|
||||||
|
unless status.success?
|
||||||
|
raise RepositoryCommandError, "The command #{command} failed (#{status.exitstatus}) with the following output:\n#{output}"
|
||||||
|
end
|
||||||
|
|
||||||
Result.new(status.exitstatus == 0, output)
|
Result.new(status.exitstatus == 0, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,7 @@ module QA
|
||||||
it 'user without push rights fails to push to the protected branch' do
|
it 'user without push rights fails to push to the protected branch' do
|
||||||
create_protected_branch(allow_to_push: false)
|
create_protected_branch(allow_to_push: false)
|
||||||
|
|
||||||
push = push_new_file(branch_name)
|
expect { push_new_file(branch_name) }.to raise_error(QA::Git::Repository::RepositoryCommandError, /remote: GitLab: You are not allowed to push code to protected branches on this project\.([\s\S]+)\[remote rejected\] #{branch_name} -> #{branch_name} \(pre-receive hook declined\)/)
|
||||||
|
|
||||||
expect(push.output)
|
|
||||||
.to match(/remote\: GitLab\: You are not allowed to push code to protected branches on this project/)
|
|
||||||
expect(push.output)
|
|
||||||
.to match(/\[remote rejected\] #{branch_name} -> #{branch_name} \(pre-receive hook declined\)/)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ describe QA::Git::Repository do
|
||||||
|
|
||||||
describe '#clone' do
|
describe '#clone' do
|
||||||
it 'is unable to resolve host' do
|
it 'is unable to resolve host' do
|
||||||
expect(repository.clone).to include("fatal: unable to access 'http://root@foo/bar.git/'")
|
expect { repository.clone }.to raise_error(described_class::RepositoryCommandError, /The command .* failed \(128\) with the following output/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ describe QA::Git::Repository do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails to push changes' do
|
it 'fails to push changes' do
|
||||||
expect(repository.push_changes).to include("error: failed to push some refs to 'http://root@foo/bar.git'")
|
expect { repository.push_changes }.to raise_error(described_class::RepositoryCommandError, /The command .* failed \(1\) with the following output/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue