|
| 1 | +# Integration tests around specifying a bootstrap script to confirm: |
| 2 | +# - Bootstrap script failing => failure of octocatalog-diff process |
| 3 | +# - Bootstrap debugging printed with --debug-bootstrap enabled |
| 4 | +# - Bootstrap debugging printed when bootstrap script fails |
| 5 | + |
| 6 | +require 'fileutils' |
| 7 | +require_relative 'integration_helper' |
| 8 | + |
| 9 | +describe 'bootstrap script integration test' do |
| 10 | + context 'with --bootstrap-current not specified' do |
| 11 | + it 'should not run the bootstrap script' do |
| 12 | + result = OctocatalogDiff::Integration.integration( |
| 13 | + spec_catalog_old: 'catalog-empty.json', |
| 14 | + spec_fact_file: 'facts.yaml', |
| 15 | + argv: [ |
| 16 | + '--basedir', OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), |
| 17 | + '--bootstrap-script', 'config/bootstrap.sh', |
| 18 | + '--to', '.' |
| 19 | + ] |
| 20 | + ) |
| 21 | + expect(result[:exitcode]).to eq(-1) |
| 22 | + expect(result[:exception].message).to match(/Could not find class (::)?test for rspec-node.xyz.github.net/) |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context 'when a bootstrap script fails' do |
| 27 | + before(:all) do |
| 28 | + @repo_dir = Dir.mktmpdir |
| 29 | + FileUtils.cp_r OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), @repo_dir |
| 30 | + |
| 31 | + @result = OctocatalogDiff::Integration.integration( |
| 32 | + spec_catalog_old: 'catalog-empty.json', |
| 33 | + spec_fact_file: 'facts.yaml', |
| 34 | + argv: [ |
| 35 | + '--basedir', File.join(@repo_dir, 'bootstrap'), |
| 36 | + '--bootstrap-current', |
| 37 | + '--bootstrap-script', 'config/broken-bootstrap.sh', |
| 38 | + '--no-parallel', |
| 39 | + '--to', '.' |
| 40 | + ] |
| 41 | + ) |
| 42 | + end |
| 43 | + |
| 44 | + after(:all) do |
| 45 | + OctocatalogDiff::Spec.clean_up_tmpdir(@repo_dir) |
| 46 | + end |
| 47 | + |
| 48 | + it 'should exit with error status' do |
| 49 | + expect(@result[:exitcode]).to eq(-1), OctocatalogDiff::Integration.format_exception(@result) |
| 50 | + end |
| 51 | + |
| 52 | + it 'should print error from bootstrap failing' do |
| 53 | + expect(@result[:exception].message).to match(/Catalog for 'to' \(.\) failed to compile with.+::BootstrapError/) |
| 54 | + expect(@result[:exception].message).to match(/OctocatalogDiff::CatalogUtil::Bootstrap::BootstrapError/) |
| 55 | + expect(@result[:exception].message).not_to match(/Could not find class (::)?test/) |
| 56 | + end |
| 57 | + |
| 58 | + it 'should print debugging output from bootstrap script' do |
| 59 | + expect(@result[:logs]).to match(/Bootstrap: Fail, stdout/) |
| 60 | + expect(@result[:logs]).to match(/Bootstrap: Fail, stderr/) |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context 'when a bootstrap script succeeds' do |
| 65 | + context 'with bootstrap debugging enabled' do |
| 66 | + before(:all) do |
| 67 | + @repo_dir = Dir.mktmpdir |
| 68 | + FileUtils.cp_r OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), @repo_dir |
| 69 | + |
| 70 | + @result = OctocatalogDiff::Integration.integration( |
| 71 | + spec_catalog_old: 'catalog-empty.json', |
| 72 | + spec_fact_file: 'facts.yaml', |
| 73 | + argv: [ |
| 74 | + '--basedir', File.join(@repo_dir, 'bootstrap'), |
| 75 | + '--bootstrap-current', |
| 76 | + '--bootstrap-script', 'config/bootstrap.sh', |
| 77 | + '--debug-bootstrap', |
| 78 | + '--no-parallel', |
| 79 | + '--to', '.' |
| 80 | + ] |
| 81 | + ) |
| 82 | + end |
| 83 | + |
| 84 | + after(:all) do |
| 85 | + OctocatalogDiff::Spec.clean_up_tmpdir(@repo_dir) |
| 86 | + end |
| 87 | + |
| 88 | + it 'should exit with success status' do |
| 89 | + expect(@result[:exitcode]).to eq(2), OctocatalogDiff::Integration.format_exception(@result) |
| 90 | + end |
| 91 | + |
| 92 | + it 'should contain the added resource' do |
| 93 | + answer = [ |
| 94 | + '+', |
| 95 | + "File\f/tmp/foo", |
| 96 | + { |
| 97 | + 'type' => 'File', |
| 98 | + 'title' => '/tmp/foo', |
| 99 | + 'tags' => %w(class file test), |
| 100 | + 'exported' => false, |
| 101 | + 'parameters' => { 'content' => "Test 123\n" } |
| 102 | + } |
| 103 | + ] |
| 104 | + expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true) |
| 105 | + end |
| 106 | + |
| 107 | + it 'should print debugging output from bootstrap script' do |
| 108 | + expect(@result[:logs]).to match(/Bootstrap: Hello, stdout/) |
| 109 | + expect(@result[:logs]).to match(/Bootstrap: Hello, stderr/) |
| 110 | + end |
| 111 | + end |
| 112 | + |
| 113 | + context 'with bootstrap debugging disabled' do |
| 114 | + before(:all) do |
| 115 | + @repo_dir = Dir.mktmpdir |
| 116 | + FileUtils.cp_r OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), @repo_dir |
| 117 | + |
| 118 | + @result = OctocatalogDiff::Integration.integration( |
| 119 | + spec_catalog_old: 'catalog-empty.json', |
| 120 | + spec_fact_file: 'facts.yaml', |
| 121 | + argv: [ |
| 122 | + '--basedir', File.join(@repo_dir, 'bootstrap'), |
| 123 | + '--bootstrap-current', |
| 124 | + '--bootstrap-script', 'config/bootstrap.sh', |
| 125 | + '--no-parallel', |
| 126 | + '--to', '.' |
| 127 | + ] |
| 128 | + ) |
| 129 | + end |
| 130 | + |
| 131 | + after(:all) do |
| 132 | + OctocatalogDiff::Spec.clean_up_tmpdir(@repo_dir) |
| 133 | + end |
| 134 | + |
| 135 | + it 'should exit with success status' do |
| 136 | + expect(@result[:exitcode]).to eq(2), OctocatalogDiff::Integration.format_exception(@result) |
| 137 | + end |
| 138 | + |
| 139 | + it 'should contain the added resource' do |
| 140 | + answer = [ |
| 141 | + '+', |
| 142 | + "File\f/tmp/foo", |
| 143 | + { |
| 144 | + 'type' => 'File', |
| 145 | + 'title' => '/tmp/foo', |
| 146 | + 'tags' => %w(class file test), |
| 147 | + 'exported' => false, |
| 148 | + 'parameters' => { 'content' => "Test 123\n" } |
| 149 | + } |
| 150 | + ] |
| 151 | + expect(OctocatalogDiff::Spec.array_contains_partial_array?(@result[:diffs], answer)).to eq(true) |
| 152 | + end |
| 153 | + |
| 154 | + it 'should not print debugging output from bootstrap script' do |
| 155 | + expect(@result[:logs]).not_to match(/Bootstrap:.*/) |
| 156 | + end |
| 157 | + end |
| 158 | + end |
| 159 | +end |
0 commit comments