|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../tests/spec_helper' |
| 4 | + |
| 5 | +require 'open3' |
| 6 | +require 'shellwords' |
| 7 | + |
| 8 | +describe 'bin/octocatalog-diff' do |
| 9 | + let(:script) { File.expand_path('../../../bin/octocatalog-diff', File.dirname(__FILE__)) } |
| 10 | + let(:ls_l) { Open3.capture2e("ls -l #{script}").first } |
| 11 | + let(:config_test) { '--config-test' } |
| 12 | + let(:normal_settings) do |
| 13 | + [ |
| 14 | + '-d', |
| 15 | + '-n rspec-node.github.net', |
| 16 | + '--fact-file', OctocatalogDiff::Spec.fixture_path('facts/facts.yaml'), |
| 17 | + '--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'), |
| 18 | + '--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/default'), |
| 19 | + '--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY |
| 20 | + ].map { |x| Shellwords.escape(x) }.join(' ') |
| 21 | + end |
| 22 | + |
| 23 | + it 'should exist' do |
| 24 | + expect(File.file?(script)).to eq(true), ls_l |
| 25 | + end |
| 26 | + |
| 27 | + it 'should be executable' do |
| 28 | + expect(File.executable?(script)).to eq(true), ls_l |
| 29 | + end |
| 30 | + |
| 31 | + context 'with an invalid configuration file' do |
| 32 | + let(:cfg) { OctocatalogDiff::Spec.fixture_path('cli-configs/invalid.rb') } |
| 33 | + let(:env) { { 'OCTOCATALOG_DIFF_CONFIG_FILE' => cfg } } |
| 34 | + |
| 35 | + it 'should error with --config-test' do |
| 36 | + text, status = Open3.capture2e(env, "#{script} #{config_test}") |
| 37 | + expect(status.exitstatus).to eq(1), text |
| 38 | + expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/invalid.rb}) |
| 39 | + expect(text).to match(/FATAL .+: Fizz Buzz/) |
| 40 | + end |
| 41 | + |
| 42 | + it 'should error with normal settings' do |
| 43 | + text, status = Open3.capture2e(env, "#{script} #{normal_settings}") |
| 44 | + expect(status.exitstatus).to eq(1), text |
| 45 | + expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/invalid.rb}) |
| 46 | + expect(text).to match(/FATAL .+: Fizz Buzz/) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context 'with a valid configuration file' do |
| 51 | + let(:cfg) { OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') } |
| 52 | + let(:env) { { 'OCTOCATALOG_DIFF_CONFIG_FILE' => cfg } } |
| 53 | + |
| 54 | + it 'should print values with --config-test and exit' do |
| 55 | + text, status = Open3.capture2e(env, "#{script} #{config_test}") |
| 56 | + expect(status.exitstatus).to eq(0), text |
| 57 | + expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/valid.rb}) |
| 58 | + expect(text).to match(/:header => \(Symbol\) :default/) |
| 59 | + expect(text).to match(%r{:hiera_config => \(String\) "config/hiera.yaml"}) |
| 60 | + expect(text).to match(/:hiera_path => \(String\) "hieradata"/) |
| 61 | + expect(text).to match(/Exiting now because --config-test was specified/) |
| 62 | + end |
| 63 | + |
| 64 | + it 'should print settings details and then invoke the main CLI' do |
| 65 | + text, status = Open3.capture2e(env, "#{script} #{normal_settings}") |
| 66 | + expect(status.exitstatus).to eq(2), text |
| 67 | + expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/valid.rb}) |
| 68 | + expect(text).to match(%r{Loaded 3 settings from .+/fixtures/cli-configs/valid.rb}) |
| 69 | + expect(text).to match(/Initialized OctocatalogDiff::Catalog::Computed for to-catalog/) |
| 70 | + expect(text).to match(/Entering catdiff; catalog sizes: 2, 21/) |
| 71 | + expect(text).to match(/Entering filter_diffs_for_absent_files with 14 diffs/) |
| 72 | + expect(text).to match(/Added resources: 14/) |
| 73 | + expect(text).to match(/\+ Ssh_authorized_key\[root@6def27049c06f48eea8b8f37329f40799d07dc84\]/) |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments