|
4 | 4 |
|
5 | 5 | require OctocatalogDiff::Spec.require_path('catalog-util/git') |
6 | 6 | require OctocatalogDiff::Spec.require_path('errors') |
| 7 | +require OctocatalogDiff::Spec.require_path('util/scriptrunner') |
7 | 8 |
|
8 | 9 | require 'ostruct' |
9 | 10 |
|
|
48 | 49 | context 'with valid directory' do |
49 | 50 | context 'with successful script run' do |
50 | 51 | it 'should log proper messages and not raise error' do |
51 | | - expect(described_class).to receive(:create_git_checkout_script).and_return('/tmp/baz.sh') |
52 | | - expect(Open3).to receive(:capture2e) |
53 | | - .with('/tmp/baz.sh', chdir: '/tmp/bar') |
54 | | - .and_return(['asldfkj', OpenStruct.new(exitstatus: 0)]) |
| 52 | + script_runner = double |
| 53 | + expect(script_runner).to receive(:run).and_return('') |
| 54 | + expect(OctocatalogDiff::Util::ScriptRunner).to receive(:new).and_return(script_runner) |
| 55 | + |
55 | 56 | opts = { branch: 'foo', path: '/tmp/bar', basedir: '/tmp/bar', logger: @logger } |
56 | 57 | described_class.check_out_git_archive(opts) |
57 | 58 | expect(@logger_str.string).to match(%r{Success git archive /tmp/bar:foo}) |
|
60 | 61 |
|
61 | 62 | context 'with failed script run' do |
62 | 63 | it 'should raise OctocatalogDiff::Errors::GitCheckoutError' do |
63 | | - expect(described_class).to receive(:create_git_checkout_script).and_return('/tmp/baz.sh') |
64 | | - expect(Open3).to receive(:capture2e) |
65 | | - .with('/tmp/baz.sh', chdir: '/tmp/bar') |
66 | | - .and_return(['errors abound', OpenStruct.new(exitstatus: 1)]) |
| 64 | + script_runner = double |
| 65 | + expect(script_runner).to receive(:run).and_raise(OctocatalogDiff::Util::ScriptRunner::ScriptException) |
| 66 | + expect(script_runner).to receive(:output).and_return('errors abound') |
| 67 | + expect(OctocatalogDiff::Util::ScriptRunner).to receive(:new).and_return(script_runner) |
| 68 | + |
67 | 69 | opts = { branch: 'foo', path: '/tmp/bar', basedir: '/tmp/bar', logger: @logger } |
68 | 70 | expect do |
69 | 71 | described_class.check_out_git_archive(opts) |
|
73 | 75 | end |
74 | 76 | end |
75 | 77 |
|
76 | | - describe '#create_git_checkout_script' do |
77 | | - it 'should create the temporary script' do |
78 | | - result = described_class.create_git_checkout_script('foo', '/tmp/baz') |
79 | | - expect(result).to be_a_kind_of(String) |
80 | | - expect(File.file?(result)).to eq(true) |
81 | | - |
82 | | - text = File.read(result) |
83 | | - expect(text).to match(/git archive --format=tar foo \|/) |
84 | | - expect(text).to match(%r{\( cd /tmp/baz && tar -xf - \)}) |
85 | | - |
86 | | - expect(File.executable?(result)).to eq(true) |
87 | | - end |
88 | | - end |
89 | | - |
90 | 78 | describe '#branch_sha' do |
91 | 79 | context 'with invalid directory' do |
92 | 80 | it 'should raise Errno::ENOENT if basedir is nil' do |
|
0 commit comments