Skip to content

Commit b21df89

Browse files
committed
provide test for failed git clone
1 parent 0e8fd6a commit b21df89

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

assets/lib/in.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def ref
2121

2222
system("git clone --depth 1 #{uri} #{destination} 1>&2")
2323

24-
fail 'git clone failed' unless $?.exitstatus == 0
24+
raise 'git clone failed' unless $CHILD_STATUS.exitstatus == 0
2525

2626
Dir.chdir(destination) do
2727
system('git submodule update --init --recursive 1>&2')

assets/lib/out.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
id = Dir.chdir(path) { `git config --get pullrequest.id`.chomp }
1818
sha = Dir.chdir(path) { `git rev-parse HEAD`.chomp }
1919

20-
fail 'could not get pullrequest `id` from repository' unless id
21-
2220
repo = Repository.new(name: input['source']['repo'])
2321

2422
metadata = [{ name: 'status', value: input['params']['status'] }]

spec/integration/in_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def commit(msg)
3838
end
3939

4040
it 'returns the correct JSON metadata' do
41-
output = get(version: { ref: @ref, pr: '1' }, source: { uri: git_uri, repo: 'jtarchie/test' })
41+
output, = get(version: { ref: @ref, pr: '1' }, source: { uri: git_uri, repo: 'jtarchie/test' })
4242
expect(output).to eq('version' => { 'ref' => @ref, 'pr' => '1' },
4343
'metadata' => [{
4444
'name' => 'url',
@@ -59,4 +59,11 @@ def commit(msg)
5959
value = git('rev-parse --abbrev-ref HEAD', dest_dir)
6060
expect(value).to eq 'pr-1'
6161
end
62+
63+
context 'when the git clone fails' do
64+
it 'provides a helpful erorr message' do
65+
_, error = get(version: { ref: @ref, pr: '1' }, source: { uri: 'invalid_git_uri', repo: 'jtarchie/test' })
66+
expect(error).to include 'git clone failed'
67+
end
68+
end
6269
end

spec/spec_helper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ def get(payload = {})
2929
path = ['./assets/in', '/opt/resource/in'].find { |p| File.exist? p }
3030
payload[:source][:no_ssl_verify] = true
3131

32-
output = `echo '#{JSON.generate(payload)}' | env http_proxy=#{proxy.url} #{path} #{dest_dir}`
33-
JSON.parse(output)
32+
output, error, = with_resource do |_dir|
33+
Open3.capture3("echo '#{JSON.generate(payload)}' | env http_proxy=#{proxy.url} #{path} #{dest_dir}")
34+
end
35+
[(begin
36+
JSON.parse(output)
37+
rescue
38+
nil
39+
end), error]
3440
end
3541

3642
def put(payload = {})

0 commit comments

Comments
 (0)