Skip to content

Commit 214c440

Browse files
committed
Test environment config + global config
1 parent 079c74c commit 214c440

File tree

8 files changed

+39
-57
lines changed

8 files changed

+39
-57
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
test::param_from_node: Should not be displayed from common
3+
test::param_from_special: Should not be displayed from common
4+
test::param_from_common: Greets from data/common
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test::param_from_nodes: Greets from data/nodes
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test::param_from_nodes: Greets from data/nodes
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test::param_from_special: This should never be displayed!
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test::param_from_extra_special: Greets from extra-special

spec/octocatalog-diff/fixtures/repos/hiera5/hiera.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
version: 5
33
defaults:
4-
datadir: hieradata
4+
datadir: data
55
data_hash: yaml_data
66

77
hierarchy:
@@ -12,5 +12,9 @@ hierarchy:
1212
path: "%{::datacenter}.yaml"
1313
datadir: special
1414

15+
- name: "Extra-special data"
16+
path: "%{::datacenter}.yaml"
17+
datadir: extra-special
18+
1519
- name: "Common data"
1620
path: "common.yaml"
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
class test (
2-
$param_from_nodes = 'hard-coded',
3-
$param_from_special = 'hard-coded',
4-
$param_from_common = 'hard-coded'
2+
$param_from_nodes = 'hard-coded',
3+
$param_from_special = 'hard-coded',
4+
$param_from_extra_special = 'hard-coded',
5+
$param_from_common = 'hard-coded'
56
) {
67
file { '/tmp/nodes': content => $param_from_nodes }
78
file { '/tmp/special': content => $param_from_special }
9+
file { '/tmp/extra-special': content => $param_from_extra_special }
810
file { '/tmp/common': content => $param_from_common }
911
}

spec/octocatalog-diff/integration/hiera5_spec.rb

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,10 @@
1919
end
2020
end
2121

22-
context 'with --hiera-path-strip and per-item data directory' do
23-
if ENV['PUPPET_VERSION'].start_with?('3')
24-
it 'should run but not use hiera values under puppet 3' do
25-
argv = ['-n', 'rspec-node.github.net', '--hiera-path-strip', '/var/lib/puppet']
26-
hash = {
27-
hiera_config: 'config/hiera5-global.yaml',
28-
spec_fact_file: 'facts.yaml',
29-
spec_repo: 'hiera5',
30-
spec_catalog_old: 'catalog-empty.json'
31-
}
32-
result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
33-
expect(result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(result)
34-
35-
to_catalog = result.to
36-
37-
param1 = { 'content' => 'hard-coded' }
38-
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
39-
40-
param2 = { 'content' => 'hard-coded' }
41-
expect(to_catalog.resource(type: 'File', title: '/tmp/special')['parameters']).to eq(param2)
42-
43-
param3 = { 'content' => 'hard-coded' }
44-
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
45-
end
46-
else
22+
if ENV['PUPPET_VERSION'].start_with?('3')
23+
# Hiera 5 tests are not applicable
24+
else
25+
context 'with --hiera-path-strip and per-item data directory' do
4726
it 'should succeed in building the catalog' do
4827
argv = ['-n', 'rspec-node.github.net', '--hiera-path-strip', '/var/lib/puppet']
4928
hash = {
@@ -57,6 +36,7 @@
5736

5837
to_catalog = result.to
5938

39+
# Global configuration overrides environment configuration
6040
param1 = { 'content' => 'Greets from nodes' }
6141
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
6242

@@ -65,13 +45,15 @@
6545

6646
param3 = { 'content' => 'Greets from common' }
6747
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
48+
49+
# Comes from environment because there is no global configuration
50+
param4 = { 'content' => 'Greets from extra-special' }
51+
expect(to_catalog.resource(type: 'File', title: '/tmp/extra-special')['parameters']).to eq(param4)
6852
end
6953
end
70-
end
7154

72-
context 'with hiera 5 non-global, environment specific configuration' do
73-
if ENV['PUPPET_VERSION'].start_with?('3')
74-
it 'should run but not use hiera values under puppet 3' do
55+
context 'with hiera 5 non-global, environment specific configuration' do
56+
it 'should succeed in building the catalog and have proper diffs' do
7557
argv = ['-n', 'rspec-node.github.net']
7658
hash = {
7759
spec_fact_file: 'facts.yaml',
@@ -83,36 +65,18 @@
8365

8466
to_catalog = result.to
8567

86-
param1 = { 'content' => 'hard-coded' }
87-
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
88-
89-
param2 = { 'content' => 'hard-coded' }
90-
expect(to_catalog.resource(type: 'File', title: '/tmp/special')['parameters']).to eq(param2)
91-
92-
param3 = { 'content' => 'hard-coded' }
93-
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
94-
end
95-
else
96-
it 'should succeed in building the catalog' do
97-
argv = ['-n', 'rspec-node.github.net']
98-
hash = {
99-
spec_fact_file: 'facts.yaml',
100-
spec_repo: 'hiera5',
101-
spec_catalog_old: 'catalog-empty.json'
102-
}
103-
result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
104-
expect(result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(result)
105-
106-
to_catalog = result.to
107-
108-
param1 = { 'content' => 'Greets from nodes' }
68+
# All come from environment
69+
param1 = { 'content' => 'Greets from data/nodes' }
10970
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
11071

11172
param2 = { 'content' => 'Greets from special' }
11273
expect(to_catalog.resource(type: 'File', title: '/tmp/special')['parameters']).to eq(param2)
11374

114-
param3 = { 'content' => 'Greets from common' }
75+
param3 = { 'content' => 'Greets from data/common' }
11576
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
77+
78+
param4 = { 'content' => 'Greets from extra-special' }
79+
expect(to_catalog.resource(type: 'File', title: '/tmp/extra-special')['parameters']).to eq(param4)
11680
end
11781
end
11882
end

0 commit comments

Comments
 (0)