|
3 | 3 | # This is test coverage on the `bin/octocatalog-diff` script itself. |
4 | 4 |
|
5 | 5 | require_relative '../tests/spec_helper' |
| 6 | +require 'json' |
6 | 7 | require 'open3' |
7 | 8 | require 'shellwords' |
8 | 9 |
|
|
68 | 69 |
|
69 | 70 | expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb}) |
70 | 71 | expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/) |
71 | | - expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/) |
| 72 | + expect(stderr).not_to match(/DEBUG -- : Loaded 3 settings from/) |
72 | 73 | expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/) |
73 | 74 | expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/) |
74 | 75 | expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/) |
75 | 76 | expect(stderr).to match(/INFO -- : Note: you can use --display-detail-add/) |
76 | 77 | end |
77 | 78 | end |
78 | 79 |
|
| 80 | + context 'writing output to JSON file' do |
| 81 | + before(:each) { @tempdir = Dir.mktmpdir } |
| 82 | + after(:each) { OctocatalogDiff::Spec.clean_up_tmpdir(@tempdir) } |
| 83 | + |
| 84 | + it 'should write JSON to an output file' do |
| 85 | + env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') } |
| 86 | + argv = [ |
| 87 | + '--to-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/catalog-1.json'), |
| 88 | + '--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/catalog-2.json'), |
| 89 | + '-o', File.join(@tempdir, 'output.json'), |
| 90 | + '--output-format', 'json', |
| 91 | + '-d' |
| 92 | + ] |
| 93 | + |
| 94 | + cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ') |
| 95 | + stdout, stderr, status = Open3.capture3(env, cmdline) |
| 96 | + |
| 97 | + expect(status.exitstatus).to eq(2), [stdout, stderr].join("\n") |
| 98 | + |
| 99 | + expect(stdout).to eq('') |
| 100 | + |
| 101 | + expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb}) |
| 102 | + expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/) |
| 103 | + expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/) |
| 104 | + expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/) |
| 105 | + expect(stderr).to match(/DEBUG -- : Initialized OctocatalogDiff::Catalog::JSON for from-catalog/) |
| 106 | + expect(stderr).to match(/Exiting hashdiff_initial; changes: 6, nested changes: 9/) |
| 107 | + |
| 108 | + j = JSON.parse(File.read(File.join(@tempdir, 'output.json'))) |
| 109 | + expect(j).to be_a_kind_of(Hash) |
| 110 | + answer = { |
| 111 | + 'diff_type' => '!', |
| 112 | + 'type' => 'Package', |
| 113 | + 'title' => 'rubygems1.8', |
| 114 | + 'structure' => ['parameters', 'old-parameter'], |
| 115 | + 'old_value' => nil, |
| 116 | + 'new_value' => 'old value', |
| 117 | + 'old_file' => '/environments/production/modules/ruby/manifests/system.pp', |
| 118 | + 'old_line' => 27, |
| 119 | + 'new_file' => '/environments/production/modules/ruby/manifests/system.pp', |
| 120 | + 'new_line' => 27, |
| 121 | + 'old_location' => { |
| 122 | + 'file' => '/environments/production/modules/ruby/manifests/system.pp', |
| 123 | + 'line' => 27 |
| 124 | + }, |
| 125 | + 'new_location' => { |
| 126 | + 'file' => '/environments/production/modules/ruby/manifests/system.pp', |
| 127 | + 'line' => 27 |
| 128 | + } |
| 129 | + } |
| 130 | + expect(j['diff']).to include(answer) |
| 131 | + expect(j['header']).to eq('diff origin/master/my.rspec.node current/my.rspec.node') |
| 132 | + end |
| 133 | + end |
| 134 | + |
79 | 135 | context 'with no changes' do |
80 | 136 | it 'should display output and exit 0' do |
81 | 137 | env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') } |
|
98 | 154 |
|
99 | 155 | expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb}) |
100 | 156 | expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/) |
101 | | - expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/) |
| 157 | + expect(stderr).not_to match(/DEBUG -- : Loaded 3 settings from/) |
102 | 158 | expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/) |
103 | 159 | expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/) |
104 | 160 | expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/) |
|
128 | 184 |
|
129 | 185 | expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb}) |
130 | 186 | expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/) |
131 | | - expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/) |
| 187 | + expect(stderr).not_to match(/DEBUG -- : Loaded 3 settings from/) |
132 | 188 | expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/) |
133 | 189 | expect(stderr).to match(/WARN -- : Failed build_catalog for ./) |
134 | 190 | expect(stderr).to match(/OctocatalogDiff::Errors::CatalogError/) |
|
0 commit comments