Skip to content

Commit 2233807

Browse files
committed
Create hiera5 integration test
1 parent 8194485 commit 2233807

File tree

8 files changed

+57
-5
lines changed

8 files changed

+57
-5
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
version: 5
33
defaults:
4-
datadir: hieradata
4+
datadir: /var/lib/puppet/environments/%{::environment}/hieradata
55
data_hash: yaml_data
66

77
hierarchy:
88
- name: "Default structure data"
9-
path: "nodes/%{app}.yaml"
9+
path: "nodes/%{::fqdn}.yaml"
1010

1111
- name: "Special data"
12-
path: "%{app}.yaml"
13-
datadir: "special"
12+
path: "%{::datacenter}.yaml"
13+
datadir: /var/lib/puppet/environments/%{::environment}/special
1414

1515
- name: "Common data"
1616
path: "common.yaml"
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 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 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node default {
2+
include test
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class test (
2+
String $param_from_nodes = 'hard-coded',
3+
String $param_from_special = 'hard-coded',
4+
String $param_from_common = 'hard-coded'
5+
) {
6+
file { '/tmp/nodes': content => $param_from_nodes }
7+
file { '/tmp/special': content => $param_from_special }
8+
file { '/tmp/common': content => $param_from_common }
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
test::param_from_special: Greets from special

spec/octocatalog-diff/integration/hiera5_spec.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,41 @@
66
context 'with --hiera-path and per-item data directory' do
77
it 'should fail because per-item datadir is not supported with --hiera-path' do
88
argv = ['-n', 'rspec-node.github.net']
9-
hash = { hiera_config: 'config/hiera5-global.yaml', spec_fact_file: 'facts.yaml', spec_repo: 'hiera5' }
9+
hash = {
10+
hiera_config: 'config/hiera5-global.yaml',
11+
spec_fact_file: 'facts.yaml',
12+
spec_repo: 'hiera5',
13+
spec_catalog_old: 'catalog-empty.json'
14+
}
1015
result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
1116
expect(result.exitcode).to eq(-1), OctocatalogDiff::Integration.format_exception(result)
1217
expect(result.exception).to be_a_kind_of(ArgumentError)
1318
expect(result.exception.message).to match(/Hierarchy item .+ has a datadir/)
1419
end
1520
end
21+
22+
context 'with --hiera-path-strip and per-item data directory' do
23+
it 'should succeed in building the catalog' do
24+
argv = ['-n', 'rspec-node.github.net', '--hiera-path-strip', '/var/lib/puppet']
25+
hash = {
26+
hiera_config: 'config/hiera5-global.yaml',
27+
spec_fact_file: 'facts.yaml',
28+
spec_repo: 'hiera5',
29+
spec_catalog_old: 'catalog-empty.json'
30+
}
31+
result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
32+
expect(result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(result)
33+
34+
to_catalog = result.to
35+
36+
param1 = { 'content' => 'Greets from nodes' }
37+
expect(to_catalog.resource(type: 'File', title: '/tmp/nodes')['parameters']).to eq(param1)
38+
39+
param2 = { 'content' => 'Greets from special' }
40+
expect(to_catalog.resource(type: 'File', title: '/tmp/special')['parameters']).to eq(param2)
41+
42+
param3 = { 'content' => 'Greets from common' }
43+
expect(to_catalog.resource(type: 'File', title: '/tmp/common')['parameters']).to eq(param3)
44+
end
45+
end
1646
end

0 commit comments

Comments
 (0)