hieracles 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +16 -7
- data/lib/hieracles/config.rb +20 -6
- data/lib/hieracles/format.rb +9 -0
- data/lib/hieracles/formats/console.rb +5 -19
- data/lib/hieracles/formats/csv.rb +4 -4
- data/lib/hieracles/formats/plain.rb +1 -1
- data/lib/hieracles/hiera.rb +2 -2
- data/lib/hieracles/interpolate.rb +1 -13
- data/lib/hieracles/node.rb +1 -1
- data/lib/hieracles/registry.rb +3 -3
- data/spec/lib/config_spec.rb +34 -10
- data/spec/lib/formats/console_spec.rb +53 -20
- data/spec/lib/formats/csv_spec.rb +42 -19
- data/spec/lib/formats/plain_spec.rb +46 -20
- data/spec/lib/hiera_spec.rb +7 -3
- data/spec/lib/node_spec.rb +9 -9
- data/spec/lib/registry_spec.rb +15 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f625244beacbc27c040813044b27538be1cc238
|
4
|
+
data.tar.gz: 43ee5e5416918b571def1e2ff14283c51f0b5d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52464e962c93a456f3911e9800991293a5250d3e8a9c39570d26792e46ca7def773f6eac6f486d6fb0a2b27cc947cfcc914bd1ebf8734c9d5287dd7f650e978c
|
7
|
+
data.tar.gz: 0502cf9ed9ee1c641a521990d94b5af61fa775307621b659679b663629c6c4e5b4dbed6c50418cd65717f7bd38ac03fea9a24363fdd9cc348272d641b8694acd
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Hieracles Changelog
|
2
2
|
=======================
|
3
3
|
|
4
|
+
### 0.2.0 - 2015-11-24
|
5
|
+
- fix merging for unsorted arrays
|
6
|
+
- translate all paths to absolute paths,
|
7
|
+
so that hc can be executed out of puppet dir
|
8
|
+
|
4
9
|
### 0.1.7 - 2015-11-23
|
5
10
|
- various fixes on deep_merge behavior
|
6
11
|
|
data/README.md
CHANGED
@@ -46,16 +46,25 @@ At first launch it will create a configuration file in `~/.config/hieracles/conf
|
|
46
46
|
|
47
47
|
Configuration variables are:
|
48
48
|
|
49
|
-
-
|
50
|
-
|
51
|
-
-
|
52
|
-
|
53
|
-
-
|
54
|
-
|
55
|
-
-
|
49
|
+
- basepath (alias localpath)
|
50
|
+
This is where your puppet repo is cloned
|
51
|
+
- classpath
|
52
|
+
where to find classes defined in the ENC
|
53
|
+
- modulepath
|
54
|
+
where to find modules called in the classes
|
55
|
+
- encpath
|
56
|
+
where to read information about each nodes
|
57
|
+
- hierafile
|
58
|
+
where to find a hierafile customised for your local puppet installation
|
59
|
+
- format
|
60
|
+
can be plain, console, csv, yaml, rawyaml, json
|
61
|
+
- defaultscope
|
62
|
+
a hash defining scope variables that will be used if not defined by a facts file or by params passed as arguments
|
56
63
|
|
57
64
|
For an example setup you can check in `spec/files`.
|
58
65
|
|
66
|
+
If you don't specify the basepath, your current location will be used as a base path.
|
67
|
+
|
59
68
|
Usage
|
60
69
|
-------------
|
61
70
|
|
data/lib/hieracles/config.rb
CHANGED
@@ -17,11 +17,11 @@ module Hieracles
|
|
17
17
|
@extraparams = extract_params(options[:params])
|
18
18
|
values = get_config(@optionfile)
|
19
19
|
@server = values['server']
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@hierafile = options[:hierafile] || values['hierafile'] || 'hiera.yaml'
|
20
|
+
@basepath = File.expand_path(options[:basepath] || values['basepath'] || values['localpath'] || '.')
|
21
|
+
@classpath = build_path(values['classpath'])
|
22
|
+
@modulepath = resolve_path(values['modulepath'] || 'modules')
|
23
|
+
@encpath = resolve_path(options[:encpath] || values['encpath'] || 'enc')
|
24
|
+
@hierafile = resolve_path(options[:hierafile] || values['hierafile'] || 'hiera.yaml')
|
25
25
|
@format = (options[:format] || values['format'] || 'console').capitalize
|
26
26
|
facts_file = options[:yaml_facts] || options[:json_facts]
|
27
27
|
facts_format = options[:json_facts] ? :json : :yaml
|
@@ -61,7 +61,7 @@ module Hieracles
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def path(what)
|
64
|
-
|
64
|
+
send(what.to_sym)
|
65
65
|
end
|
66
66
|
|
67
67
|
def load_facts(file, format)
|
@@ -72,5 +72,19 @@ module Hieracles
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def resolve_path(path)
|
76
|
+
if File.exists?(File.expand_path(path))
|
77
|
+
File.expand_path(path)
|
78
|
+
elsif File.exists?(File.expand_path(File.join(@basepath, path)))
|
79
|
+
File.expand_path(File.join(@basepath, path))
|
80
|
+
else
|
81
|
+
raise IOError, "File #{path} not found."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_path(path)
|
86
|
+
File.expand_path(File.join(@basepath, path))
|
87
|
+
end
|
88
|
+
|
75
89
|
end
|
76
90
|
end
|
data/lib/hieracles/format.rb
CHANGED
@@ -54,5 +54,14 @@ module Hieracles
|
|
54
54
|
def build_modules_line(key, value)
|
55
55
|
"#{__callee__} not implemented, please inherit from the Hieracles::Format class to implement a format.\n"
|
56
56
|
end
|
57
|
+
|
58
|
+
def is_merged?(v)
|
59
|
+
v[:value].is_a?(Array) && (v[:value] | v[:merged]) != v[:value]
|
60
|
+
end
|
61
|
+
|
62
|
+
def sanitize(v)
|
63
|
+
v.to_s.gsub('%', '%%')
|
64
|
+
end
|
65
|
+
|
57
66
|
end
|
58
67
|
end
|
@@ -55,30 +55,16 @@ module Hieracles
|
|
55
55
|
first = value.pop
|
56
56
|
filecolor_index = @colors[first[:file]]
|
57
57
|
filecolor = COLORS[filecolor_index]
|
58
|
-
if
|
59
|
-
output << format("%s #{COLORS[5]} %s\n",
|
60
|
-
|
61
|
-
key,
|
62
|
-
first[:merged].to_s.gsub('%', '%%')
|
63
|
-
)
|
64
|
-
output << format(" #{COLORS[8]} #{COLORS[8]} #{COLORS[8]}\n",
|
65
|
-
"[#{filecolor_index}]",
|
66
|
-
key,
|
67
|
-
first[:value].to_s.gsub('%', '%%')
|
68
|
-
)
|
58
|
+
if is_merged? first
|
59
|
+
output << format("%s #{COLORS[5]} %s\n", "[-]", key, sanitize(first[:merged]) )
|
60
|
+
output << format(" #{COLORS[8]}\n", "[#{filecolor_index}] #{key} #{sanitize(first[:value])}" )
|
69
61
|
else
|
70
|
-
output << format("#{filecolor} #{COLORS[5]} %s\n",
|
71
|
-
"[#{filecolor_index}]",
|
72
|
-
key,
|
73
|
-
first[:value].to_s.gsub('%', '%%')
|
74
|
-
)
|
62
|
+
output << format("#{filecolor} #{COLORS[5]} %s\n", "[#{filecolor_index}]", key, sanitize(first[:value]) )
|
75
63
|
end
|
76
64
|
while value.count > 0
|
77
65
|
overriden = value.pop
|
78
66
|
filecolor_index = @colors[overriden[:file]]
|
79
|
-
output << format(" #{COLORS[8]}\n",
|
80
|
-
"[#{filecolor_index}] #{key} #{overriden[:value]}"
|
81
|
-
)
|
67
|
+
output << format(" #{COLORS[8]}\n", "[#{filecolor_index}] #{key} #{overriden[:value]}")
|
82
68
|
end
|
83
69
|
end
|
84
70
|
output
|
@@ -29,14 +29,14 @@ module Hieracles
|
|
29
29
|
output = ''
|
30
30
|
if !filter || Regexp.new(filter).match(key)
|
31
31
|
first = value.pop
|
32
|
-
if
|
33
|
-
output << make_csv(in_what_file(first[:file]) +
|
34
|
-
[key, first[:value].to_s, '0'])
|
35
|
-
else
|
32
|
+
if is_merged? first
|
36
33
|
output << make_csv(in_what_file('-') +
|
37
34
|
[key, first[:merged].to_s, '0'])
|
38
35
|
output << make_csv(in_what_file(first[:file]) +
|
39
36
|
[key, first[:value].to_s, '1'])
|
37
|
+
else
|
38
|
+
output << make_csv(in_what_file(first[:file]) +
|
39
|
+
[key, first[:value].to_s, '0'])
|
40
40
|
end
|
41
41
|
while value.count > 0
|
42
42
|
overriden = value.pop
|
@@ -41,7 +41,7 @@ module Hieracles
|
|
41
41
|
if !filter || Regexp.new(filter).match(key)
|
42
42
|
first = value.pop
|
43
43
|
filecolor_index = @index[first[:file]]
|
44
|
-
if
|
44
|
+
if is_merged? first
|
45
45
|
output << "[-] #{key} #{first[:merged]}\n"
|
46
46
|
output << " [#{filecolor_index}] #{key} #{first[:value]}\n"
|
47
47
|
else
|
data/lib/hieracles/hiera.rb
CHANGED
@@ -2,8 +2,8 @@ module Hieracles
|
|
2
2
|
class Hiera
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
raise IOError, "Hierafile #{Config.hierafile} not found." unless File.exist? Config.
|
6
|
-
@hierafile = Config.
|
5
|
+
raise IOError, "Hierafile #{Config.hierafile} not found." unless File.exist? Config.hierafile
|
6
|
+
@hierafile = Config.hierafile
|
7
7
|
@loaded = YAML.load_file(@hierafile)
|
8
8
|
end
|
9
9
|
|
@@ -23,22 +23,10 @@ module Hieracles
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# makes possible to set input and output
|
26
|
-
def setio(input, output)
|
26
|
+
def setio(input=STDIN, output=STDOUT)
|
27
27
|
@@input = input
|
28
28
|
@@output = output
|
29
29
|
end
|
30
30
|
|
31
|
-
private
|
32
|
-
|
33
|
-
# defaults to STDIN
|
34
|
-
def input
|
35
|
-
@@input ||= STDIN
|
36
|
-
end
|
37
|
-
|
38
|
-
# defaults to STDOUT
|
39
|
-
def output
|
40
|
-
@@output ||= STDOUT
|
41
|
-
end
|
42
|
-
|
43
31
|
end
|
44
32
|
end
|
data/lib/hieracles/node.rb
CHANGED
data/lib/hieracles/registry.rb
CHANGED
@@ -4,17 +4,17 @@ module Hieracles
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def farms(config)
|
7
|
-
@_farms ||= Dir.glob(
|
7
|
+
@_farms ||= Dir.glob(format(config.classpath, '*')).sort
|
8
8
|
end
|
9
9
|
|
10
10
|
def nodes(config)
|
11
|
-
@_nodes ||= Dir.glob(File.join(config.
|
11
|
+
@_nodes ||= Dir.glob(File.join(config.encpath, '*.yaml')).sort.map do |f|
|
12
12
|
File.basename(f, '.yaml')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def modules(config)
|
17
|
-
@_modules ||= Dir.glob(File.join(config.
|
17
|
+
@_modules ||= Dir.glob(File.join(config.modulepath, '*')).sort.map do |f|
|
18
18
|
File.basename(f)
|
19
19
|
end
|
20
20
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -4,14 +4,24 @@ describe Hieracles::Config do
|
|
4
4
|
describe '.load' do
|
5
5
|
context 'with an existing file' do
|
6
6
|
let(:options) do
|
7
|
-
{
|
7
|
+
{
|
8
|
+
config: 'spec/files/config.yml',
|
9
|
+
basepath: 'spec/files'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
let(:expected) do
|
13
|
+
{
|
14
|
+
classpath: File.expand_path('spec/files/farm_modules/%s.pp'),
|
15
|
+
modulepath: File.expand_path('spec/files/modules'),
|
16
|
+
hierafile: File.expand_path('spec/files/hiera.yaml')
|
17
|
+
}
|
8
18
|
end
|
9
19
|
before { Hieracles::Config.load options }
|
10
20
|
|
11
21
|
it 'initialize config values' do
|
12
|
-
expect(Hieracles::Config.classpath).to eq
|
13
|
-
expect(Hieracles::Config.modulepath).to eq
|
14
|
-
expect(Hieracles::Config.hierafile).to eq
|
22
|
+
expect(Hieracles::Config.classpath).to eq expected[:classpath]
|
23
|
+
expect(Hieracles::Config.modulepath).to eq expected[:modulepath]
|
24
|
+
expect(Hieracles::Config.hierafile).to eq expected[:hierafile]
|
15
25
|
expect(Hieracles::Config.format).to eq 'Console'
|
16
26
|
end
|
17
27
|
end
|
@@ -19,21 +29,35 @@ describe Hieracles::Config do
|
|
19
29
|
context 'with additional parameters' do
|
20
30
|
let(:hierapath) { 'hiera.yaml' }
|
21
31
|
let(:options) do
|
22
|
-
{
|
32
|
+
{
|
33
|
+
config: 'spec/files/config.yml',
|
34
|
+
basepath: 'spec/files',
|
35
|
+
hierafile: hierapath
|
36
|
+
}
|
37
|
+
end
|
38
|
+
let(:expected) do
|
39
|
+
{
|
40
|
+
classpath: File.expand_path('spec/files/farm_modules/%s.pp'),
|
41
|
+
modulepath: File.expand_path('spec/files/modules'),
|
42
|
+
hierafile: File.expand_path('spec/files/hiera.yaml')
|
43
|
+
}
|
23
44
|
end
|
24
45
|
before { Hieracles::Config.load options }
|
25
46
|
|
26
47
|
it 'initialize config values' do
|
27
|
-
expect(Hieracles::Config.classpath).to eq
|
28
|
-
expect(Hieracles::Config.modulepath).to eq
|
29
|
-
expect(Hieracles::Config.hierafile).to eq
|
48
|
+
expect(Hieracles::Config.classpath).to eq expected[:classpath]
|
49
|
+
expect(Hieracles::Config.modulepath).to eq expected[:modulepath]
|
50
|
+
expect(Hieracles::Config.hierafile).to eq expected[:hierafile]
|
30
51
|
expect(Hieracles::Config.format).to eq 'Console'
|
31
52
|
end
|
32
53
|
end
|
33
54
|
|
34
55
|
context 'without an existing config file' do
|
35
56
|
let(:options) do
|
36
|
-
{
|
57
|
+
{
|
58
|
+
basepath: 'spec/files',
|
59
|
+
config: 'spec/files/config_no.yml'
|
60
|
+
}
|
37
61
|
end
|
38
62
|
before do
|
39
63
|
FileUtils.rm(options[:config]) if File.exist? options[:config]
|
@@ -46,7 +70,7 @@ describe Hieracles::Config do
|
|
46
70
|
end
|
47
71
|
|
48
72
|
it 'initialize config values' do
|
49
|
-
expect(Hieracles::Config.classpath).to eq 'manifests/classes/%s.pp'
|
73
|
+
expect(Hieracles::Config.classpath).to eq File.expand_path('spec/files/manifests/classes/%s.pp')
|
50
74
|
end
|
51
75
|
end
|
52
76
|
end
|
@@ -53,26 +53,52 @@ describe Hieracles::Formats::Console do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe ".build_params_line" do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
56
|
+
context "when not merged" do
|
57
|
+
let(:expected) {
|
58
|
+
"\e[32m[1]\e[0m \e[36mparams.this.var\e[0m value2\n"+
|
59
|
+
" \e[97m[0] params.this.var value1\e[0m\n"
|
60
|
+
}
|
61
|
+
let(:params) {
|
62
|
+
[
|
63
|
+
{ file: 'path1', value: 'value1', merged: 'value1'},
|
64
|
+
{ file: 'path2', value: 'value2', merged: 'value2'},
|
65
|
+
]
|
66
|
+
}
|
67
|
+
before {
|
68
|
+
console_format.instance_variable_set(:@colors,
|
69
|
+
{'path1' => 0, 'path2' => 1}
|
70
|
+
)
|
71
|
+
}
|
72
|
+
it "outputs proper text" do
|
73
|
+
expect(console_format.send :build_params_line,
|
74
|
+
"params.this.var",
|
75
|
+
params,
|
76
|
+
nil).to eq expected
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context "when merged" do
|
80
|
+
let(:expected) {
|
81
|
+
"[-] \e[36mparams.this.var\e[0m [\"value1\", \"value2\"]\n"+
|
82
|
+
" \e[97m[1] params.this.var [\"value2\"]\e[0m\n"+
|
83
|
+
" \e[97m[0] params.this.var [\"value1\"]\e[0m\n"
|
84
|
+
}
|
85
|
+
let(:params) {
|
86
|
+
[
|
87
|
+
{ file: 'path1', value: ['value1'], merged: ['value1'] },
|
88
|
+
{ file: 'path2', value: ['value2'], merged: ['value1','value2'] }
|
89
|
+
]
|
90
|
+
}
|
91
|
+
before {
|
92
|
+
console_format.instance_variable_set(:@colors,
|
93
|
+
{'path1' => 0, 'path2' => 1}
|
94
|
+
)
|
95
|
+
}
|
96
|
+
it "outputs proper text" do
|
97
|
+
expect(console_format.send :build_params_line,
|
98
|
+
"params.this.var",
|
99
|
+
params,
|
100
|
+
nil).to eq expected
|
101
|
+
end
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
@@ -104,4 +130,11 @@ describe Hieracles::Formats::Console do
|
|
104
130
|
end
|
105
131
|
end
|
106
132
|
end
|
133
|
+
|
134
|
+
describe ".sanitize" do
|
135
|
+
let(:value) { "something with % inside" }
|
136
|
+
let(:expected) { "something with %% inside" }
|
137
|
+
it { expect(console_format.send :sanitize, value).to eq expected }
|
138
|
+
end
|
139
|
+
|
107
140
|
end
|
@@ -51,25 +51,48 @@ describe Hieracles::Formats::Csv do
|
|
51
51
|
|
52
52
|
describe ".build_params_line" do
|
53
53
|
context "with array values" do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
54
|
+
context "when not merged" do
|
55
|
+
let(:expected) {
|
56
|
+
"0;1;params.this.var;[\"value1\"];0\n"+
|
57
|
+
"1;0;params.this.var;[\"value1\"];1\n"
|
58
|
+
}
|
59
|
+
let(:params) {
|
60
|
+
[
|
61
|
+
{ file: 'path1', value: ['value1'], merged: ['value1'] },
|
62
|
+
{ file: 'path2', value: ['value1'], merged: ['value1'] },
|
63
|
+
]
|
64
|
+
}
|
65
|
+
before {
|
66
|
+
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
67
|
+
}
|
68
|
+
it "outputs proper text" do
|
69
|
+
expect(csv_format.send :build_params_line,
|
70
|
+
"params.this.var",
|
71
|
+
params,
|
72
|
+
nil).to eq expected
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context "when merged" do
|
76
|
+
let(:expected) {
|
77
|
+
"0;0;params.this.var;[\"value1\", \"value2\"];0\n"+
|
78
|
+
"0;1;params.this.var;[\"value2\"];1\n"+
|
79
|
+
"1;0;params.this.var;[\"value1\"];1\n"
|
80
|
+
}
|
81
|
+
let(:params) {
|
82
|
+
[
|
83
|
+
{ file: 'path1', value: ['value1'], merged: ['value1'] },
|
84
|
+
{ file: 'path2', value: ['value2'], merged: ['value1','value2'] },
|
85
|
+
]
|
86
|
+
}
|
87
|
+
before {
|
88
|
+
allow(node).to receive(:files).and_return(['path1', 'path2'])
|
89
|
+
}
|
90
|
+
it "outputs proper text" do
|
91
|
+
expect(csv_format.send :build_params_line,
|
92
|
+
"params.this.var",
|
93
|
+
params,
|
94
|
+
nil).to eq expected
|
95
|
+
end
|
73
96
|
end
|
74
97
|
end
|
75
98
|
context "with non-array values" do
|
@@ -53,26 +53,52 @@ describe Hieracles::Formats::Plain do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe ".build_params_line" do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
56
|
+
context "when not merged" do
|
57
|
+
let(:expected) {
|
58
|
+
"[1] params.this.var value2\n"+
|
59
|
+
" [0] params.this.var value1\n"
|
60
|
+
}
|
61
|
+
let(:params) {
|
62
|
+
[
|
63
|
+
{ file: 'path1', value: 'value1', merged: 'value1'},
|
64
|
+
{ file: 'path2', value: 'value2', merged: 'value2'},
|
65
|
+
]
|
66
|
+
}
|
67
|
+
before {
|
68
|
+
plain_format.instance_variable_set(:@index,
|
69
|
+
{'path1' => 0, 'path2' => 1}
|
70
|
+
)
|
71
|
+
}
|
72
|
+
it "outputs proper text" do
|
73
|
+
expect(plain_format.send :build_params_line,
|
74
|
+
"params.this.var",
|
75
|
+
params,
|
76
|
+
nil).to eq expected
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context "when merged" do
|
80
|
+
let(:expected) {
|
81
|
+
"[-] params.this.var [\"value1\", \"value2\"]\n"+
|
82
|
+
" [1] params.this.var [\"value2\"]\n"+
|
83
|
+
" [0] params.this.var [\"value1\"]\n"
|
84
|
+
}
|
85
|
+
let(:params) {
|
86
|
+
[
|
87
|
+
{ file: 'path1', value: ['value1'], merged: ['value1'] },
|
88
|
+
{ file: 'path2', value: ['value2'], merged: ['value1','value2'] },
|
89
|
+
]
|
90
|
+
}
|
91
|
+
before {
|
92
|
+
plain_format.instance_variable_set(:@index,
|
93
|
+
{'path1' => 0, 'path2' => 1}
|
94
|
+
)
|
95
|
+
}
|
96
|
+
it "outputs proper text" do
|
97
|
+
expect(plain_format.send :build_params_line,
|
98
|
+
"params.this.var",
|
99
|
+
params,
|
100
|
+
nil).to eq expected
|
101
|
+
end
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
data/spec/lib/hiera_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hieracles::Hiera do
|
4
|
-
before { Hieracles::Config.load(options) }
|
5
4
|
|
6
5
|
describe '.new' do
|
7
6
|
|
8
7
|
context 'hiera file not found' do
|
9
|
-
let(:options) { {
|
8
|
+
let(:options) { {
|
9
|
+
basepath: 'spec/files',
|
10
10
|
config: 'spec/files/config.yml',
|
11
11
|
basepath: 'spec/files',
|
12
12
|
hierafile: 'hiera_no.yaml'
|
13
13
|
} }
|
14
14
|
it 'raises an error' do
|
15
|
-
expect { Hieracles::
|
15
|
+
expect { Hieracles::Config.load(options) }.to raise_error(IOError)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -26,6 +26,7 @@ describe Hieracles::Hiera do
|
|
26
26
|
File.expand_path(File.join(options[:basepath], options[:hierafile]))
|
27
27
|
}
|
28
28
|
let(:hiera) { Hieracles::Hiera.new }
|
29
|
+
before { Hieracles::Config.load(options) }
|
29
30
|
it 'load the file' do
|
30
31
|
expect(hiera.instance_variable_get :@loaded).to be_a Hash
|
31
32
|
expect(hiera.instance_variable_get :@hierafile).to eq expected
|
@@ -35,6 +36,7 @@ describe Hieracles::Hiera do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
describe '.datapath' do
|
39
|
+
before { Hieracles::Config.load(options) }
|
38
40
|
context 'hiera file do not have a yaml backend' do
|
39
41
|
let(:options) { {
|
40
42
|
config: 'spec/files/config.yml',
|
@@ -74,6 +76,7 @@ describe Hieracles::Hiera do
|
|
74
76
|
end
|
75
77
|
|
76
78
|
describe '.datadir' do
|
79
|
+
before { Hieracles::Config.load(options) }
|
77
80
|
let(:options) {
|
78
81
|
{
|
79
82
|
config: 'spec/files/config.yml',
|
@@ -86,6 +89,7 @@ describe Hieracles::Hiera do
|
|
86
89
|
end
|
87
90
|
|
88
91
|
context "with proper params" do
|
92
|
+
before { Hieracles::Config.load(options) }
|
89
93
|
let(:options) {
|
90
94
|
{
|
91
95
|
config: 'spec/files/config.yml',
|
data/spec/lib/node_spec.rb
CHANGED
@@ -155,9 +155,9 @@ describe Hieracles::Node do
|
|
155
155
|
context "no unfound modules" do
|
156
156
|
let(:expected) {
|
157
157
|
{
|
158
|
-
"fake_module" => "modules/fake_module",
|
159
|
-
"fake_module2" => "modules/fake_module2",
|
160
|
-
"fake_module3" => "modules/fake_module3"
|
158
|
+
"fake_module" => File.expand_path("spec/files/modules/fake_module"),
|
159
|
+
"fake_module2" => File.expand_path("spec/files/modules/fake_module2"),
|
160
|
+
"fake_module3" => File.expand_path("spec/files/modules/fake_module3")
|
161
161
|
}
|
162
162
|
}
|
163
163
|
it { expect(node.modules).to eq expected }
|
@@ -166,8 +166,8 @@ describe Hieracles::Node do
|
|
166
166
|
let(:node) { Hieracles::Node.new 'server2.example.com', options }
|
167
167
|
let(:expected) {
|
168
168
|
{
|
169
|
-
"fake_module" => "modules/fake_module",
|
170
|
-
"fake_module2" => "modules/fake_module2",
|
169
|
+
"fake_module" => File.expand_path("spec/files/modules/fake_module"),
|
170
|
+
"fake_module2" => File.expand_path("spec/files/modules/fake_module2"),
|
171
171
|
"fake_module4" => nil
|
172
172
|
}
|
173
173
|
}
|
@@ -181,11 +181,11 @@ describe Hieracles::Node do
|
|
181
181
|
let(:node) { Hieracles::Node.new 'server4.example.com', options }
|
182
182
|
let(:expected) {
|
183
183
|
{
|
184
|
-
"fake_module" => "modules/fake_module",
|
185
|
-
"fake_module2" => "modules/fake_module2",
|
184
|
+
"fake_module" => File.expand_path("spec/files/modules/fake_module"),
|
185
|
+
"fake_module2" => File.expand_path("spec/files/modules/fake_module2"),
|
186
186
|
"fake_module4" => nil,
|
187
|
-
"faux_module1" => "modules/faux_module1",
|
188
|
-
"faux_module2" => "modules/faux_module2"
|
187
|
+
"faux_module1" => File.expand_path("spec/files/modules/faux_module1"),
|
188
|
+
"faux_module2" => File.expand_path("spec/files/modules/faux_module2")
|
189
189
|
}
|
190
190
|
}
|
191
191
|
it { expect(node.modules).to eq expected }
|
data/spec/lib/registry_spec.rb
CHANGED
@@ -5,12 +5,15 @@ describe Hieracles::Registry do
|
|
5
5
|
|
6
6
|
describe '.farms' do
|
7
7
|
let(:options) do
|
8
|
-
{
|
8
|
+
{
|
9
|
+
config: 'spec/files/config.yml',
|
10
|
+
basepath: 'spec/files'
|
11
|
+
}
|
9
12
|
end
|
10
13
|
let(:expected) { [
|
11
|
-
File.join(
|
12
|
-
File.join(
|
13
|
-
File.join(
|
14
|
+
File.join(Hieracles::Config.basepath, 'farm_modules', 'dev.pp'),
|
15
|
+
File.join(Hieracles::Config.basepath, 'farm_modules', 'dev2.pp'),
|
16
|
+
File.join(Hieracles::Config.basepath, 'farm_modules', 'dev4.pp')
|
14
17
|
] }
|
15
18
|
before { Hieracles::Config.load options}
|
16
19
|
it { expect(Hieracles::Registry.farms Hieracles::Config).to eq expected }
|
@@ -18,7 +21,10 @@ describe Hieracles::Registry do
|
|
18
21
|
|
19
22
|
describe '.nodes' do
|
20
23
|
let(:options) do
|
21
|
-
{
|
24
|
+
{
|
25
|
+
config: 'spec/files/config.yml',
|
26
|
+
basepath: 'spec/files'
|
27
|
+
}
|
22
28
|
end
|
23
29
|
let(:expected) { [
|
24
30
|
'server.example.com',
|
@@ -32,7 +38,10 @@ describe Hieracles::Registry do
|
|
32
38
|
|
33
39
|
describe '.modules' do
|
34
40
|
let(:options) do
|
35
|
-
{
|
41
|
+
{
|
42
|
+
config: 'spec/files/config.yml',
|
43
|
+
basepath: 'spec/files'
|
44
|
+
}
|
36
45
|
end
|
37
46
|
let(:expected) { [
|
38
47
|
'fake_module',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hieracles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|