Skip to content

Commit 4cb164a

Browse files
authored
Merge pull request #165 from github/kpaulisse-fact-file-cli
Add integration test for CLI fact override being used over config file
2 parents ed4968c + 4860fcc commit 4cb164a

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ def install_fact_file(logger, options)
149149
raise ArgumentError, 'Called install_fact_file without node, or with an empty node'
150150
end
151151

152-
facts = if options[:fact_file]
152+
facts = if options[:facts].is_a?(OctocatalogDiff::Facts)
153+
options[:facts].dup
154+
elsif options[:fact_file]
153155
raise Errno::ENOENT, "Fact file #{options[:fact_file]} does not exist" unless File.file?(options[:fact_file])
154156
fact_file_opts = { fact_file_string: File.read(options[:fact_file]) }
155157
fact_file_opts[:backend] = Regexp.last_match(1).to_sym if options[:fact_file] =~ /.*\.(\w+)$/
156158
OctocatalogDiff::Facts.new(fact_file_opts)
157-
elsif options[:facts].is_a?(OctocatalogDiff::Facts)
158-
options[:facts].dup
159159
else
160160
raise ArgumentError, 'No facts passed to "install_fact_file" method'
161161
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This is a configuration file for octocatalog-diff
2+
3+
module OctocatalogDiff
4+
class Config
5+
def self.config
6+
{
7+
facts: OctocatalogDiff::Facts.new(
8+
backend: :yaml,
9+
fact_file_string: File.read(File.join(ENV['PUPPET_FACT_FILE_DIR'], 'valid-facts.yaml'))
10+
),
11+
fact_file: File.join(ENV['PUPPET_FACT_FILE_DIR'], 'valid-facts.yaml')
12+
}
13+
end
14+
end
15+
end

spec/octocatalog-diff/integration/fact_file_by_branch_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,60 @@
142142
expect(@result.stderr).to match(/Diffs computed for rspec-node.github.net/)
143143
end
144144
end
145+
146+
describe 'fact file from the configuration' do
147+
before(:all) do
148+
ENV['PUPPET_FACT_FILE_DIR'] = OctocatalogDiff::Spec.fixture_path('facts')
149+
@result = OctocatalogDiff::Integration.integration_cli(
150+
[
151+
'-n', 'rspec-node.github.net',
152+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/fact-overrides'),
153+
'--catalog-only',
154+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
155+
'-d'
156+
],
157+
OctocatalogDiff::Spec.fixture_path('cli-configs/fact-file.rb')
158+
)
159+
end
160+
161+
after(:all) do
162+
ENV.delete('PUPPET_FACT_FILE_DIR')
163+
end
164+
165+
it 'should exit with status 0' do
166+
expect(@result.exitcode).to eq(0), @result.stderr
167+
end
168+
169+
it 'should contain resources generated from the proper fact file' do
170+
expect(@result.stdout).to match(/"10\.20\.30\.40"/)
171+
end
172+
end
173+
174+
describe 'fact file overridden on the command line' do
175+
before(:all) do
176+
ENV['PUPPET_FACT_FILE_DIR'] = OctocatalogDiff::Spec.fixture_path('facts')
177+
@result = OctocatalogDiff::Integration.integration_cli(
178+
[
179+
'-n', 'rspec-node.github.net',
180+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/fact-overrides'),
181+
'--catalog-only',
182+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY,
183+
'-d',
184+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/valid-facts-different-ip.yaml')
185+
],
186+
OctocatalogDiff::Spec.fixture_path('cli-configs/fact-file.rb')
187+
)
188+
end
189+
190+
after(:all) do
191+
ENV.delete('PUPPET_FACT_FILE_DIR')
192+
end
193+
194+
it 'should exit with status 0' do
195+
expect(@result.exitcode).to eq(0), @result.stderr
196+
end
197+
198+
it 'should contain resources generated from the proper fact file' do
199+
expect(@result.stdout).to match(/"10\.30\.50\.70"/)
200+
end
201+
end

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def self.integration_with_puppetdb(server_opts, opts)
3131
end
3232

3333
# For an integration test, run the full CLI and get results
34-
def self.integration_cli(argv)
34+
def self.integration_cli(argv, override_env = nil)
3535
script = File.expand_path('../../../bin/octocatalog-diff', File.dirname(__FILE__))
3636
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') }
37+
env = { 'OCTOCATALOG_DIFF_CONFIG_FILE' => override_env || OctocatalogDiff::Spec.fixture_path('cli-configs/no-op.rb') }
3838
stdout, stderr, status = Open3.capture3(env, cmdline)
3939
OpenStruct.new(
4040
stdout: stdout,

0 commit comments

Comments
 (0)