Skip to content

Commit 29d42f6

Browse files
author
Kevin Paulisse
committed
Add additional integration test to fact override, to exercise CLI
1 parent 4173dc8 commit 29d42f6

4 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is a configuration file for octocatalog-diff
2+
3+
module OctocatalogDiff
4+
class Config
5+
def self.config
6+
{}
7+
end
8+
end
9+
end

spec/octocatalog-diff/integration/fact_override_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
require_relative 'integration_helper'
44

5+
require 'json'
6+
57
describe 'fact override integration' do
68
# The 'answer' to one of the tests below
79
let(:foofoo_params) do
@@ -163,3 +165,59 @@
163165
end
164166
end
165167
end
168+
169+
describe 'fact override via CLI' do
170+
before(:all) do
171+
@result = OctocatalogDiff::Integration.integration_cli(
172+
[
173+
'-n', 'rspec-node.github.net',
174+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/fact-overrides'),
175+
'--bootstrapped-from-dir', OctocatalogDiff::Spec.fixture_path('repos/fact-overrides'),
176+
'--to-fact-override', 'ipaddress=10.30.50.70',
177+
'--from-fact-override', 'foofoo=barbar',
178+
'--output-format', 'json',
179+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'),
180+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
181+
'-d'
182+
]
183+
)
184+
end
185+
186+
it 'should exit with status 2' do
187+
expect(@result.exitcode).to eq(2), @result.stderr
188+
end
189+
190+
it 'should contain the correct diffs' do
191+
parse_result = JSON.parse(@result.stdout)['diff'].map { |x| OctocatalogDiff::Spec.remove_file_and_line(x) }
192+
expect(parse_result.size).to eq(2)
193+
expect(parse_result).to include(
194+
'diff_type' => '~',
195+
'type' => 'File',
196+
'title' => '/tmp/ipaddress',
197+
'structure' => %w(parameters content),
198+
'old_value' => '10.20.30.40',
199+
'new_value' => '10.30.50.70'
200+
)
201+
expect(parse_result).to include(
202+
'diff_type' => '-',
203+
'type' => 'File',
204+
'title' => '/tmp/foofoo',
205+
'structure' => [],
206+
'old_value' => {
207+
'type' => 'File',
208+
'title' => '/tmp/foofoo',
209+
'tags' => %w(class default file node test),
210+
'exported' => false,
211+
'parameters' => { 'content' => 'barbar' }
212+
},
213+
'new_value' => nil
214+
)
215+
end
216+
217+
it 'should log the correct messages' do
218+
expect(@result.stderr).to match(/Catalog for . will be built with OctocatalogDiff::Catalog::Computed/)
219+
expect(@result.stderr).to match(/Override ipaddress from "10.20.30.40" to "10.30.50.70"/)
220+
expect(@result.stderr).to match(/Override foofoo from nil to "barbar"/)
221+
expect(@result.stderr).to match(/Diffs computed for rspec-node.github.net/)
222+
end
223+
end

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require OctocatalogDiff::Spec.require_path('/errors')
44

55
require 'json'
6+
require 'open3'
67
require 'ostruct'
78
require 'shellwords'
89
require 'stringio'
@@ -29,6 +30,19 @@ def self.integration_with_puppetdb(server_opts, opts)
2930
ENV['PUPPETDB_URL'] = puppetdb_url_save
3031
end
3132

33+
# For an integration test, run the full CLI and get results
34+
def self.integration_cli(argv)
35+
script = File.expand_path('../../../bin/octocatalog-diff', File.dirname(__FILE__))
36+
cmdline = [script, argv].flatten.map { |x| Shellwords.escape(x) }.join(' ')
37+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => OctocatalogDiff::Spec.fixture_path('cli-configs/no-op.rb') }
38+
stdout, stderr, status = Open3.capture3(env, cmdline)
39+
OpenStruct.new(
40+
stdout: stdout,
41+
stderr: stderr,
42+
exitcode: status.exitstatus
43+
)
44+
end
45+
3246
# For an integration test, run catalog-diff and get results
3347
def self.integration(options = {})
3448
# Passed argv -- can be a string or an array

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ def self.setup_logger
217217
# remove the file and line locations. This takes the JSON result from catalog-diff and returns
218218
# a cleaned-up array of diffs.
219219
def self.remove_file_and_line(diff)
220+
if diff.is_a?(Hash)
221+
result = diff.dup
222+
%w(new_location old_location new_line old_line new_file old_file).each { |x| result.delete(x) }
223+
return result
224+
end
220225
obj = diff if diff.is_a?(Array)
221226
obj = diff['diff'] if diff.is_a?(Hash) && diff.key?('diff')
222227
raise ArgumentError, diff.inspect unless obj.is_a?(Array)

0 commit comments

Comments
 (0)