Skip to content

Commit b999ccc

Browse files
committed
Hiera 5 depends on puppet minor version too...
1 parent a7a967b commit b999ccc

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

spec/octocatalog-diff/integration/hiera5_spec.rb

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
require_relative 'integration_helper'
44

5+
module OctocatalogDiff
6+
class Spec
7+
def self.hiera5?(puppet_version = ENV['PUPPET_VERSION'])
8+
if puppet_version.nil?
9+
raise 'Unable to determine Puppet version used for this test.'
10+
end
11+
major_version, minor_version = puppet_version.split('.').map(&:to_i)
12+
13+
# hiera5 is present in >= 5, absent in <= 3
14+
return true if major_version >= 5
15+
return false if major_version <= 3
16+
17+
# hiera5 was introduced in Puppet 4.9
18+
minor_version >= 9
19+
end
20+
end
21+
end
22+
523
describe 'repository with hiera 5' do
624
context 'with --hiera-path and per-item data directory' do
725
it 'should fail because per-item datadir is not supported with --hiera-path' do
@@ -19,9 +37,36 @@
1937
end
2038
end
2139

22-
if ENV['PUPPET_VERSION'] && ENV['PUPPET_VERSION'].start_with?('3')
23-
# Hiera 5 tests are not applicable
24-
else
40+
# Even if there's an old hiera version, still test the branch-specific hiera config stuff.
41+
unless OctocatalogDiff::Spec.hiera5?
42+
context 'with --to-hiera-config and --from-hiera-config' do
43+
it 'should succeed in building the catalog' do
44+
argv = ['-n', 'rspec-node.github.net', '--to-hiera-path', 'hieradata', '--from-hiera-path', 'data']
45+
hash = {
46+
hiera_config: 'config/hiera3-global.yaml',
47+
spec_fact_file: 'facts.yaml',
48+
spec_repo: 'hiera5',
49+
spec_catalog_old: 'catalog-empty.json'
50+
}
51+
result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
52+
expect(result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(result)
53+
54+
to_catalog = result.to
55+
56+
param1 = { 'content' => 'Greets from nodes' }
57+
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
58+
59+
param2 = { 'content' => 'Should not be displayed from common' }
60+
expect(to_catalog.resource(type: 'File', title: '/tmp/special')['parameters']).to eq(param2)
61+
62+
param3 = { 'content' => 'Greets from common' }
63+
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
64+
end
65+
end
66+
end
67+
68+
# Run these tests for Hiera 5
69+
if OctocatalogDiff::Spec.hiera5?
2570
context 'with --hiera-path-strip and per-item data directory' do
2671
it 'should succeed in building the catalog' do
2772
argv = ['-n', 'rspec-node.github.net', '--hiera-path-strip', '/var/lib/puppet']
@@ -127,6 +172,9 @@
127172
new_value: 'Greets from common'
128173
}
129174
expect(OctocatalogDiff::Spec.diff_match?(result.diffs, diff3)).to eq(true)
175+
176+
# Even with a hiera 3 global file, Puppet 4.9 will start to recognize `<root dir>/hiera.yaml`
177+
# so there is no difference reported for the "extra-special" hiera setup.
130178
end
131179
end
132180

0 commit comments

Comments
 (0)