Skip to content

Commit 8404c7b

Browse files
author
Kevin Paulisse
committed
Update integration test with JSON test cases
1 parent 06f8d5f commit 8404c7b

1 file changed

Lines changed: 59 additions & 3 deletions

File tree

spec/octocatalog-diff/integration/script_spec.rb

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# This is test coverage on the `bin/octocatalog-diff` script itself.
44

55
require_relative '../tests/spec_helper'
6+
require 'json'
67
require 'open3'
78
require 'shellwords'
89

@@ -68,14 +69,69 @@
6869

6970
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
7071
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/)
7273
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
7374
expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/)
7475
expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/)
7576
expect(stderr).to match(/INFO -- : Note: you can use --display-detail-add/)
7677
end
7778
end
7879

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+
79135
context 'with no changes' do
80136
it 'should display output and exit 0' do
81137
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
@@ -98,7 +154,7 @@
98154

99155
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
100156
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/)
102158
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
103159
expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/)
104160
expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/)
@@ -128,7 +184,7 @@
128184

129185
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
130186
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/)
132188
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
133189
expect(stderr).to match(/WARN -- : Failed build_catalog for ./)
134190
expect(stderr).to match(/OctocatalogDiff::Errors::CatalogError/)

0 commit comments

Comments
 (0)