|
2 | 2 |
|
3 | 3 | require_relative 'integration_helper'
|
4 | 4 |
|
| 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 | + |
5 | 23 | describe 'repository with hiera 5' do
|
6 | 24 | context 'with --hiera-path and per-item data directory' do
|
7 | 25 | it 'should fail because per-item datadir is not supported with --hiera-path' do
|
|
19 | 37 | end
|
20 | 38 | end
|
21 | 39 |
|
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? |
25 | 70 | context 'with --hiera-path-strip and per-item data directory' do
|
26 | 71 | it 'should succeed in building the catalog' do
|
27 | 72 | argv = ['-n', 'rspec-node.github.net', '--hiera-path-strip', '/var/lib/puppet']
|
|
127 | 172 | new_value: 'Greets from common'
|
128 | 173 | }
|
129 | 174 | 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. |
130 | 178 | end
|
131 | 179 | end
|
132 | 180 |
|
|
0 commit comments