Skip to content

Commit 7955b4a

Browse files
author
Kevin Paulisse
committed
Add an integration test that exercises bin/octocatalog-diff
1 parent cdd7031 commit 7955b4a

1 file changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# frozen_string_literal: true
2+
3+
# This is test coverage on the `bin/octocatalog-diff` script itself.
4+
5+
require_relative '../tests/spec_helper'
6+
require 'open3'
7+
require 'shellwords'
8+
9+
describe 'bin/octocatalog-diff' do
10+
let(:script) { File.expand_path('../../../bin/octocatalog-diff', File.dirname(__FILE__)) }
11+
12+
context 'config test' do
13+
context 'config file found' do
14+
it 'should display configuration settings and then exit 0' do
15+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
16+
argv = ['--config-test']
17+
18+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
19+
stdout, stderr, status = Open3.capture3(env, cmdline)
20+
21+
expect(status.exitstatus).to eq(0)
22+
expect(stdout).to eq('')
23+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
24+
expect(stderr).to match(/DEBUG -- : :header => \(Symbol\) :default/)
25+
expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/)
26+
expect(stderr).to match(/INFO -- : Exiting now because --config-test was specified/)
27+
end
28+
end
29+
30+
context 'invalid config file' do
31+
it 'should raise error and exit 1' do
32+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/invalid.rb') }
33+
argv = ['--config-test']
34+
35+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
36+
stdout, stderr, status = Open3.capture3(env, cmdline)
37+
38+
expect(status.exitstatus).to eq(1)
39+
expect(stdout).to eq('')
40+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/invalid.rb})
41+
expect(stderr).to match(/FATAL -- : RuntimeError error with.+Fizz Buzz/)
42+
end
43+
end
44+
end
45+
46+
context 'normal' do
47+
context 'with valid catalogs that differ' do
48+
it 'should display output and exit 2' do
49+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
50+
argv = [
51+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/default'),
52+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'),
53+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
54+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/facts.json'),
55+
'-n', 'rspec-node.github.net',
56+
'--no-color'
57+
]
58+
59+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
60+
stdout, stderr, status = Open3.capture3(env, cmdline)
61+
62+
expect(status.exitstatus).to eq(2), [stdout, stderr].join("\n")
63+
64+
out_lines = stdout.split(/\n/)
65+
expect(out_lines).to include('diff origin/master/rspec-node.github.net current/rspec-node.github.net')
66+
expect(out_lines).to include('+ File[/root/.ssh]')
67+
expect(out_lines).to include('+ System::User[bob]')
68+
69+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
70+
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(/INFO -- : Exiting now because --config-test was specified/)
73+
expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/)
74+
expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/)
75+
expect(stderr).to match(/INFO -- : Note: you can use --display-detail-add/)
76+
end
77+
end
78+
79+
context 'with no changes' do
80+
it 'should display output and exit 0' do
81+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
82+
argv = [
83+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/tiny-repo'),
84+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'),
85+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
86+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/facts.json'),
87+
'-n', 'rspec-node.github.net',
88+
'--no-color',
89+
'--no-hiera-config'
90+
]
91+
92+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
93+
stdout, stderr, status = Open3.capture3(env, cmdline)
94+
95+
expect(status.exitstatus).to eq(0), [stdout, stderr].join("\n")
96+
97+
expect(stdout).to eq('')
98+
99+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
100+
expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/)
101+
expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/)
102+
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
103+
expect(stderr).to match(/INFO -- : Catalogs compiled for rspec-node.github.net/)
104+
expect(stderr).to match(/INFO -- : Diffs computed for rspec-node.github.net/)
105+
expect(stderr).to match(/INFO -- : No differences/)
106+
end
107+
end
108+
109+
context 'when encountering an error in catalog compilation' do
110+
it 'should display error and exit 1' do
111+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
112+
argv = [
113+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/failing-catalog'),
114+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'),
115+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
116+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/facts.json'),
117+
'-n', 'rspec-node.github.net',
118+
'--no-color',
119+
'--no-hiera-config'
120+
]
121+
122+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
123+
stdout, stderr, status = Open3.capture3(env, cmdline)
124+
125+
expect(status.exitstatus).to eq(1), [stdout, stderr].join("\n")
126+
127+
expect(stdout).to eq('')
128+
129+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
130+
expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/)
131+
expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/)
132+
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
133+
expect(stderr).to match(/WARN -- : Failed build_catalog for ./)
134+
expect(stderr).to match(/OctocatalogDiff::Errors::CatalogError/)
135+
expect(stderr).to match(/Could not find class (::)?this::module::does::not::exist/)
136+
end
137+
end
138+
139+
context 'when encountering an error in usage' do
140+
it 'should display error and exit 1' do
141+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
142+
argv = [
143+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/failing-catalog'),
144+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'),
145+
'--no-color',
146+
'--no-hiera-config'
147+
]
148+
149+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
150+
stdout, stderr, status = Open3.capture3(env, cmdline)
151+
152+
expect(status.exitstatus).to eq(1), [stdout, stderr].join("\n")
153+
154+
expect(stdout).to eq('')
155+
156+
expect(stderr).to match(%r{Loading octocatalog-diff configuration from .+/cli-configs/valid.rb})
157+
expect(stderr).not_to match(/DEBUG -- : :header => \(Symbol\) :default/)
158+
expect(stderr).to match(/DEBUG -- : Loaded 3 settings from/)
159+
expect(stderr).not_to match(/INFO -- : Exiting now because --config-test was specified/)
160+
expect(stderr).to match(/Catalog for 'to' \(.\) failed to compile with/)
161+
expect(stderr).to match(/ArgumentError: Unable to compute facts for node./)
162+
end
163+
end
164+
end
165+
end

0 commit comments

Comments
 (0)