Skip to content

Commit c2e254f

Browse files
author
Kevin Paulisse
committed
Add coverage of #run_bootstrap
1 parent bafc777 commit c2e254f

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

spec/octocatalog-diff/tests/catalog-util/bootstrap_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,48 @@
189189
end
190190
end
191191
end
192+
193+
describe '#run_bootstrap' do
194+
before(:each) do
195+
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
196+
end
197+
198+
context 'with successful run' do
199+
before(:each) do
200+
expect(OctocatalogDiff::Bootstrap).to receive(:bootstrap).and_return(status_code: 0, output: 'worked')
201+
end
202+
203+
context 'with bootstrap debugging' do
204+
it 'should succeed and print debugging messages' do
205+
opts = { bootstrap_script: 'foo.sh', debug_bootstrap: true, path: '/tmp/bar' }
206+
result = described_class.run_bootstrap(@logger, opts)
207+
expect(result).to eq('worked')
208+
expect(@logger_str.string).to match(%r{Begin bootstrap with 'foo.sh' in /tmp/bar})
209+
expect(@logger_str.string).to match(/Bootstrap: worked/)
210+
expect(@logger_str.string).to match(%r{Success bootstrap in /tmp/bar})
211+
end
212+
end
213+
214+
context 'without bootstrap debugging' do
215+
it 'should succeed without debugging messages' do
216+
opts = { bootstrap_script: 'foo.sh', path: '/tmp/bar' }
217+
result = described_class.run_bootstrap(@logger, opts)
218+
expect(result).to eq('worked')
219+
expect(@logger_str.string).to match(%r{Begin bootstrap with 'foo.sh' in /tmp/bar})
220+
expect(@logger_str.string).not_to match(/Bootstrap: worked/)
221+
expect(@logger_str.string).to match(%r{Success bootstrap in /tmp/bar})
222+
end
223+
end
224+
end
225+
226+
context 'with failed run' do
227+
it 'should raise OctocatalogDiff::Errors::BootstrapError' do
228+
expect(OctocatalogDiff::Bootstrap).to receive(:bootstrap).and_return(status_code: 1, output: 'Oopsie')
229+
opts = { bootstrap_script: 'foo.sh', path: '/tmp/bar' }
230+
expect { described_class.run_bootstrap(@logger, opts) }.to raise_error(OctocatalogDiff::Errors::BootstrapError)
231+
expect(@logger_str.string).to match(%r{Begin bootstrap with 'foo.sh' in /tmp/bar})
232+
expect(@logger_str.string).to match(/Bootstrap: Oopsie/)
233+
end
234+
end
235+
end
192236
end

0 commit comments

Comments
 (0)