hieracles 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,14 +76,20 @@ describe Hieracles::Formats::Console do
76
76
  describe ".build_params_line" do
77
77
  context "when not merged" do
78
78
  let(:expected) {
79
- "\e[32m[1]\e[0m \e[36mparams.this.var\e[0m value2\n"+
80
- " \e[97m[0] params.this.var value1\e[0m\n"
79
+ "[-] \e[36mparams.this.var\e[0m value1\n" +
80
+ " \e[97m[0] params.this.var value1\e[0m\n" +
81
+ " \e[97m[1] params.this.var value2\e[0m\n"
81
82
  }
82
83
  let(:params) {
83
- [
84
- { file: 'path1', value: 'value1', merged: 'value1'},
85
- { file: 'path2', value: 'value2', merged: 'value2'},
86
- ]
84
+ {
85
+ file: '-',
86
+ value: 'value1',
87
+ overriden: true,
88
+ found_in: [
89
+ { file: 'path1', value: 'value1' },
90
+ { file: 'path2', value: 'value2' }
91
+ ]
92
+ }
87
93
  }
88
94
  before {
89
95
  console_format.instance_variable_set(:@colors,
@@ -100,14 +106,19 @@ describe Hieracles::Formats::Console do
100
106
  context "when merged" do
101
107
  let(:expected) {
102
108
  "[-] \e[36mparams.this.var\e[0m [\"value1\", \"value2\"]\n"+
103
- " \e[97m[1] params.this.var [\"value2\"]\e[0m\n"+
104
- " \e[97m[0] params.this.var [\"value1\"]\e[0m\n"
109
+ " \e[97m[0] params.this.var [\"value1\"]\e[0m\n"+
110
+ " \e[97m[1] params.this.var [\"value2\"]\e[0m\n"
105
111
  }
106
112
  let(:params) {
107
- [
108
- { file: 'path1', value: ['value1'], merged: ['value1'] },
109
- { file: 'path2', value: ['value2'], merged: ['value1','value2'] }
110
- ]
113
+ {
114
+ file: '-',
115
+ value: ['value1','value2'],
116
+ overriden: true,
117
+ found_in: [
118
+ { file: 'path1', value: ['value1'] },
119
+ { file: 'path2', value: ['value2'] }
120
+ ]
121
+ }
111
122
  }
112
123
  before {
113
124
  console_format.instance_variable_set(:@colors,
@@ -66,38 +66,22 @@ describe Hieracles::Formats::Csv do
66
66
 
67
67
  describe ".build_params_line" do
68
68
  context "with array values" do
69
- context "when not merged" do
70
- let(:expected) {
71
- "0;1;params.this.var;[\"value1\"];0\n"+
72
- "1;0;params.this.var;[\"value1\"];1\n"
73
- }
74
- let(:params) {
75
- [
76
- { file: 'path1', value: ['value1'], merged: ['value1'] },
77
- { file: 'path2', value: ['value1'], merged: ['value1'] },
78
- ]
79
- }
80
- before {
81
- allow(node).to receive(:files).and_return(['path1', 'path2'])
82
- }
83
- it "outputs proper text" do
84
- expect(csv_format.send :build_params_line,
85
- "params.this.var",
86
- params,
87
- nil).to eq expected
88
- end
89
- end
90
69
  context "when merged" do
91
70
  let(:expected) {
92
- "0;0;params.this.var;[\"value1\", \"value2\"];0\n"+
93
- "0;1;params.this.var;[\"value2\"];1\n"+
94
- "1;0;params.this.var;[\"value1\"];1\n"
71
+ "0;0;params.this.var;[\"value1\", \"value2\"];0\n" +
72
+ "1;0;params.this.var;[\"value1\"];1\n" +
73
+ "0;1;params.this.var;[\"value2\"];1\n"
95
74
  }
96
75
  let(:params) {
97
- [
98
- { file: 'path1', value: ['value1'], merged: ['value1'] },
99
- { file: 'path2', value: ['value2'], merged: ['value1','value2'] },
100
- ]
76
+ {
77
+ file: '-',
78
+ value: ['value1','value2'],
79
+ overriden: true,
80
+ found_in: [
81
+ { file: 'path1', value: ['value1'] },
82
+ { file: 'path2', value: ['value2'] }
83
+ ]
84
+ }
101
85
  }
102
86
  before {
103
87
  allow(node).to receive(:files).and_return(['path1', 'path2'])
@@ -112,14 +96,20 @@ describe Hieracles::Formats::Csv do
112
96
  end
113
97
  context "with non-array values" do
114
98
  let(:expected) {
115
- "0;1;params.this.var;value2;0\n"+
116
- "1;0;params.this.var;value1;1\n"
99
+ "0;0;params.this.var;value1;0\n" +
100
+ "1;0;params.this.var;value1;1\n" +
101
+ "0;1;params.this.var;value2;1\n"
117
102
  }
118
103
  let(:params) {
119
- [
120
- { file: 'path1', value: 'value1', merged: 'value1' },
121
- { file: 'path2', value: 'value2', merged: 'value2' },
122
- ]
104
+ {
105
+ file: '-',
106
+ value: 'value1',
107
+ overriden: true,
108
+ found_in: [
109
+ { file: 'path1', value: 'value1' },
110
+ { file: 'path2', value: 'value2' }
111
+ ]
112
+ }
123
113
  }
124
114
  before {
125
115
  allow(node).to receive(:files).and_return(['path1', 'path2'])
@@ -75,14 +75,20 @@ describe Hieracles::Formats::Plain do
75
75
  describe ".build_params_line" do
76
76
  context "when not merged" do
77
77
  let(:expected) {
78
- "[1] params.this.var value2\n"+
79
- " [0] params.this.var value1\n"
78
+ "[-] params.this.var value1\n" +
79
+ " [0] params.this.var value1\n" +
80
+ " [1] params.this.var value2\n"
80
81
  }
81
82
  let(:params) {
82
- [
83
- { file: 'path1', value: 'value1', merged: 'value1'},
84
- { file: 'path2', value: 'value2', merged: 'value2'},
85
- ]
83
+ {
84
+ file: '-',
85
+ value: 'value1',
86
+ overriden: true,
87
+ found_in: [
88
+ { file: 'path1', value: 'value1' },
89
+ { file: 'path2', value: 'value2' }
90
+ ]
91
+ }
86
92
  }
87
93
  before {
88
94
  plain_format.instance_variable_set(:@index,
@@ -99,14 +105,19 @@ describe Hieracles::Formats::Plain do
99
105
  context "when merged" do
100
106
  let(:expected) {
101
107
  "[-] params.this.var [\"value1\", \"value2\"]\n"+
102
- " [1] params.this.var [\"value2\"]\n"+
103
- " [0] params.this.var [\"value1\"]\n"
108
+ " [0] params.this.var [\"value1\"]\n"+
109
+ " [1] params.this.var [\"value2\"]\n"
104
110
  }
105
111
  let(:params) {
106
- [
107
- { file: 'path1', value: ['value1'], merged: ['value1'] },
108
- { file: 'path2', value: ['value2'], merged: ['value1','value2'] },
109
- ]
112
+ {
113
+ file: '-',
114
+ value: ['value1','value2'],
115
+ overriden: true,
116
+ found_in: [
117
+ { file: 'path1', value: ['value1'] },
118
+ { file: 'path2', value: ['value2'] }
119
+ ]
120
+ }
110
121
  }
111
122
  before {
112
123
  plain_format.instance_variable_set(:@index,
@@ -70,10 +70,14 @@ describe Hieracles::Formats::Yaml do
70
70
  before {
71
71
  allow(node).to receive(:params).with(true).and_return(
72
72
  {
73
- 'params.this.var' => [{
74
- file: 'some/file',
75
- value: 'value1'
76
- }]
73
+ 'params.this.var' => {
74
+ file: 'some/file',
75
+ value: 'value1',
76
+ overriden: false,
77
+ found_in: [
78
+ { file: 'some/file', value: 'value1' }
79
+ ]
80
+ }
77
81
  }
78
82
  )
79
83
  allow(node).to receive(:params_tree).with(true).and_return(
@@ -98,10 +102,14 @@ describe Hieracles::Formats::Yaml do
98
102
  before {
99
103
  allow(node).to receive(:params).and_return(
100
104
  {
101
- 'params.this.var' => [{
102
- file: 'some/file',
103
- value: 'value1'
104
- }]
105
+ 'params.this.var' => {
106
+ file: 'some/file',
107
+ value: 'value1',
108
+ overriden: false,
109
+ found_in: [
110
+ { file: 'some/file', value: 'value1' }
111
+ ]
112
+ }
105
113
  }
106
114
  )
107
115
  allow(node).to receive(:params_tree).and_return(
@@ -129,10 +137,14 @@ describe Hieracles::Formats::Yaml do
129
137
  before {
130
138
  allow(node).to receive(:params).and_return(
131
139
  {
132
- 'params.this.var' => [{
133
- file: 'some/file',
134
- value: 'value1'
135
- }]
140
+ 'params.this.var' => {
141
+ file: 'some/file',
142
+ value: 'value1',
143
+ overriden: false,
144
+ found_in: [
145
+ { file: 'some/file', value: 'value1' }
146
+ ]
147
+ }
136
148
  }
137
149
  )
138
150
  allow(node).to receive(:params_tree).and_return(
@@ -157,10 +169,14 @@ describe Hieracles::Formats::Yaml do
157
169
  before {
158
170
  allow(node).to receive(:params).with(false).and_return(
159
171
  {
160
- 'params.this.var' => [{
161
- file: 'some/file',
162
- value: 'value1'
163
- }]
172
+ 'params.this.var' => {
173
+ file: 'some/file',
174
+ value: 'value1',
175
+ overriden: false,
176
+ found_in: [
177
+ { file: 'some/file', value: 'value1' }
178
+ ]
179
+ }
164
180
  }
165
181
  )
166
182
  allow(node).to receive(:params_tree).with(false).and_return(
@@ -181,10 +197,14 @@ describe Hieracles::Formats::Yaml do
181
197
  context "with a simple string key-value" do
182
198
  let(:params) {
183
199
  {
184
- 'key' => [{
185
- file: 'what/file',
186
- value: 'value'
187
- }]
200
+ 'key' => {
201
+ file: 'what/file',
202
+ value: 'value',
203
+ overriden: false,
204
+ found_in: [
205
+ { file: 'what/file', value: 'value1' }
206
+ ]
207
+ }
188
208
  }
189
209
  }
190
210
  let(:input) {
@@ -198,10 +218,14 @@ describe Hieracles::Formats::Yaml do
198
218
  context "with various boolean type of key-values (true)" do
199
219
  let(:params) {
200
220
  {
201
- 'key' => [{
202
- file: 'what/file',
203
- value: 'true'
204
- }]
221
+ 'key' => {
222
+ file: 'what/file',
223
+ value: true,
224
+ overriden: false,
225
+ found_in: [
226
+ { file: 'what/file', value: true }
227
+ ]
228
+ }
205
229
  }
206
230
  }
207
231
  let(:input) {
@@ -215,10 +239,14 @@ describe Hieracles::Formats::Yaml do
215
239
  context "with various null type of key-values (nil)" do
216
240
  let(:params) {
217
241
  {
218
- 'key' => [{
219
- file: 'what/file',
220
- value: nil
221
- }]
242
+ 'key' => {
243
+ file: 'what/file',
244
+ value: nil,
245
+ overriden: false,
246
+ found_in: [
247
+ { file: 'what/file', value: nil }
248
+ ]
249
+ }
222
250
  }
223
251
  }
224
252
  let(:input) {
@@ -232,10 +260,14 @@ describe Hieracles::Formats::Yaml do
232
260
  context "with various boolean type of key-values (false)" do
233
261
  let(:params) {
234
262
  {
235
- 'key' => [{
236
- file: 'what/file',
237
- value: 'false'
238
- }]
263
+ 'key' => {
264
+ file: 'what/file',
265
+ value: 'false',
266
+ overriden: false,
267
+ found_in: [
268
+ { file: 'what/file', value: 'false' }
269
+ ]
270
+ }
239
271
  }
240
272
  }
241
273
  let(:input) {
@@ -249,10 +281,14 @@ describe Hieracles::Formats::Yaml do
249
281
  context "with various fixnum type of key-values" do
250
282
  let(:params) {
251
283
  {
252
- 'key' => [{
253
- file: 'what/file',
254
- value: '3'
255
- }]
284
+ 'key' => {
285
+ file: 'what/file',
286
+ value: '3',
287
+ overriden: false,
288
+ found_in: [
289
+ { file: 'what/file', value: '3' }
290
+ ]
291
+ }
256
292
  }
257
293
  }
258
294
  let(:input) {
@@ -266,10 +302,14 @@ describe Hieracles::Formats::Yaml do
266
302
  context "with various float type of key-values" do
267
303
  let(:params) {
268
304
  {
269
- 'key' => [{
270
- file: 'what/file',
271
- value: '0.3'
272
- }]
305
+ 'key' => {
306
+ file: 'what/file',
307
+ value: '0.3',
308
+ overriden: false,
309
+ found_in: [
310
+ { file: 'what/file', value: '0.3' }
311
+ ]
312
+ }
273
313
  }
274
314
  }
275
315
  let(:input) {
@@ -283,10 +323,14 @@ describe Hieracles::Formats::Yaml do
283
323
  context "with a simple array key-value" do
284
324
  let(:params) {
285
325
  {
286
- 'key' => [{
287
- file: 'what/file',
288
- value: ['value1', 'value2']
289
- }]
326
+ 'key' => {
327
+ file: 'what/file',
328
+ value: ['value1', 'value2'],
329
+ overriden: false,
330
+ found_in: [
331
+ { file: 'what/file', value: ['value1', 'value2'] }
332
+ ]
333
+ }
290
334
  }
291
335
  }
292
336
  let(:input) {
@@ -306,18 +350,15 @@ describe Hieracles::Formats::Yaml do
306
350
  context "with a double array key-value" do
307
351
  let(:params) {
308
352
  {
309
- 'key' => [
310
- {
311
- file: 'what/file',
312
- value: ['value1', 'value2'],
313
- merged: ['value1', 'value2']
314
- },
315
- {
316
- file: 'what/other-file',
317
- value: ['value3'],
318
- merged: ['value1', 'value2', 'value3']
319
- }
320
- ]
353
+ 'key' => {
354
+ file: '-',
355
+ value: ['value3'],
356
+ overriden: true,
357
+ found_in: [
358
+ { file: 'what/file', value: ['value3'] },
359
+ { file: 'what/other-file', value: ['value1', 'value2'] }
360
+ ]
361
+ }
321
362
  }
322
363
  }
323
364
  let(:hiera) { Struct.new( :merge_behavior ) }
@@ -326,7 +367,7 @@ describe Hieracles::Formats::Yaml do
326
367
  { 'key' => ['value3'] }
327
368
  }
328
369
  let(:expected) {
329
- "\nkey: \n # what/other-file\n - value3"
370
+ "\nkey: \n # what/file\n # what/other-file\n - value3"
330
371
  }
331
372
  before {
332
373
  allow(node).to receive(:hiera).and_return(
@@ -353,10 +394,14 @@ describe Hieracles::Formats::Yaml do
353
394
  context "with a 2-levels string key-value" do
354
395
  let(:params) {
355
396
  {
356
- 'key.sublevel' => [{
357
- file: 'what/file',
358
- value: 'value'
359
- }]
397
+ 'key.sublevel' => {
398
+ file: 'what/file',
399
+ value: 'value',
400
+ overriden: false,
401
+ found_in: [
402
+ { file: 'what/file', value: 'value' }
403
+ ]
404
+ }
360
405
  }
361
406
  }
362
407
  let(:input) {
@@ -374,14 +419,22 @@ describe Hieracles::Formats::Yaml do
374
419
  context "with 2 2-levels string key-value" do
375
420
  let(:params) {
376
421
  {
377
- 'key.sublevel' => [{
378
- file: 'what/file',
379
- value: 'value'
380
- }],
381
- 'key.sublevel2' => [{
382
- file: 'what/file2',
383
- value: 'value2'
384
- }]
422
+ 'key.sublevel' => {
423
+ file: 'what/file',
424
+ value: 'value',
425
+ overriden: false,
426
+ found_in: [
427
+ { file: 'what/file', value: 'value' }
428
+ ]
429
+ },
430
+ 'key.sublevel2' => {
431
+ file: 'what/file2',
432
+ value: 'value2',
433
+ overriden: false,
434
+ found_in: [
435
+ { file: 'what/file2', value: 'value2' }
436
+ ]
437
+ }
385
438
  }
386
439
  }
387
440
  let(:input) {
@@ -400,10 +453,14 @@ describe Hieracles::Formats::Yaml do
400
453
  context "with a 3-levels string key-value" do
401
454
  let(:params) {
402
455
  {
403
- 'key.sublevel.subsublevel' => [{
404
- file: 'what/file',
405
- value: 'value'
406
- }]
456
+ 'key.sublevel.subsublevel' => {
457
+ file: 'what/file',
458
+ value: 'value',
459
+ overriden: false,
460
+ found_in: [
461
+ { file: 'what/file', value: 'value' }
462
+ ]
463
+ }
407
464
  }
408
465
  }
409
466
  let(:input) {
@@ -423,14 +480,22 @@ describe Hieracles::Formats::Yaml do
423
480
  context "with a 3-levels double string key-value" do
424
481
  let(:params) {
425
482
  {
426
- 'key.sublevel.subsublevel' => [{
427
- file: 'what/file',
428
- value: 'value'
429
- }],
430
- 'key2.sublevel' => [{
431
- file: 'what/file2',
432
- value: 'value'
433
- }]
483
+ 'key.sublevel.subsublevel' => {
484
+ file: 'what/file',
485
+ value: 'value',
486
+ overriden: false,
487
+ found_in: [
488
+ { file: 'what/file', value: 'value' }
489
+ ]
490
+ },
491
+ 'key2.sublevel' => {
492
+ file: 'what/file2',
493
+ value: 'value',
494
+ overriden: false,
495
+ found_in: [
496
+ { file: 'what/file2', value: 'value' }
497
+ ]
498
+ }
434
499
  }
435
500
  }
436
501
  let(:input) {
@@ -454,20 +519,23 @@ describe Hieracles::Formats::Yaml do
454
519
  context "with a 3-levels double string key-value and override" do
455
520
  let(:params) {
456
521
  {
457
- 'key.sublevel.subsublevel' => [{
458
- file: 'what/file',
459
- value: 'value'
460
- }],
461
- 'key2.sublevel' => [
462
- {
463
- file: 'what/file2',
464
- value: 'value'
465
- },
466
- {
467
- file: 'what/file1',
468
- value: 'value2'
469
- }
470
- ]
522
+ 'key.sublevel.subsublevel' => {
523
+ file: 'what/file',
524
+ value: 'value',
525
+ overriden: false,
526
+ found_in: [
527
+ { file: 'what/file', value: 'value' }
528
+ ]
529
+ },
530
+ 'key2.sublevel' => {
531
+ file: '-',
532
+ value: 'value',
533
+ overriden: true,
534
+ found_in: [
535
+ { file: 'what/file2', value: 'value' },
536
+ { file: 'what/file1', value: 'value2' }
537
+ ]
538
+ }
471
539
  }
472
540
  }
473
541
  let(:input) {
@@ -484,7 +552,7 @@ describe Hieracles::Formats::Yaml do
484
552
  }
485
553
  let(:expected) {
486
554
  "\nkey: \n sublevel: \n subsublevel: value # what/file" +
487
- "\nkey2: \n sublevel: value2 # what/file1"
555
+ "\nkey2: \n sublevel: value2 # what/file2 # what/file1"
488
556
  }
489
557
  it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
490
558
  end
@@ -11,7 +11,7 @@ describe Hieracles::Hiera do
11
11
  hierafile: 'hiera_no.yaml'
12
12
  } }
13
13
  it 'raises an error' do
14
- expect { Hieracles::Config.load(options) }.to raise_error(IOError)
14
+ expect { Hieracles::Config.new(options) }.to raise_error(IOError)
15
15
  end
16
16
  end
17
17
 
@@ -24,8 +24,8 @@ describe Hieracles::Hiera do
24
24
  let(:expected){
25
25
  File.expand_path(File.join(options[:basepath], options[:hierafile]))
26
26
  }
27
- let(:hiera) { Hieracles::Hiera.new }
28
- before { Hieracles::Config.load(options) }
27
+ let(:config) { Hieracles::Config.new options }
28
+ let(:hiera) { Hieracles::Hiera.new config }
29
29
  it 'load the file' do
30
30
  expect(hiera.instance_variable_get :@loaded).to be_a Hash
31
31
  expect(hiera.instance_variable_get :@hierafile).to eq expected
@@ -35,14 +35,14 @@ describe Hieracles::Hiera do
35
35
  end
36
36
 
37
37
  describe '.datapath' do
38
- before { Hieracles::Config.load(options) }
38
+ let(:config) { Hieracles::Config.new options }
39
+ let(:hiera) { Hieracles::Hiera.new config }
39
40
  context 'hiera file do not have a yaml backend' do
40
41
  let(:options) { {
41
42
  config: 'spec/files/config.yml',
42
43
  basepath: 'spec/files',
43
44
  hierafile: 'hiera_no_yamlbackend.yaml'
44
45
  } }
45
- let(:hiera) { Hieracles::Hiera.new }
46
46
  it 'raises an error' do
47
47
  expect { hiera.datapath }.to raise_error(TypeError)
48
48
  end
@@ -53,7 +53,6 @@ describe Hieracles::Hiera do
53
53
  basepath: 'spec/files',
54
54
  hierafile: 'hiera_yamlbackend_notfound.yaml'
55
55
  } }
56
- let(:hiera) { Hieracles::Hiera.new }
57
56
  it 'raises an error' do
58
57
  expect { hiera.datapath }.to raise_error(IOError)
59
58
  end
@@ -66,8 +65,7 @@ describe Hieracles::Hiera do
66
65
  basepath: 'spec/files'
67
66
  }
68
67
  }
69
- let(:hiera) { Hieracles::Hiera.new }
70
- let(:expected) { File.expand_path(File.join(Hieracles::Config.basepath, 'params')) }
68
+ let(:expected) { File.expand_path(File.join(config.basepath, 'params')) }
71
69
  it 'returns params path' do
72
70
  expect(hiera.datapath).to eq expected
73
71
  end
@@ -75,7 +73,6 @@ describe Hieracles::Hiera do
75
73
  end
76
74
 
77
75
  describe '.datadir' do
78
- before { Hieracles::Config.load(options) }
79
76
  let(:options) {
80
77
  {
81
78
  config: 'spec/files/config.yml',
@@ -83,12 +80,12 @@ describe Hieracles::Hiera do
83
80
  basepath: 'spec/files'
84
81
  }
85
82
  }
86
- let(:hiera) { Hieracles::Hiera.new }
83
+ let(:config) { Hieracles::Config.new options }
84
+ let(:hiera) { Hieracles::Hiera.new config }
87
85
  it { expect(hiera.datadir).to eq 'params/' }
88
86
  end
89
87
 
90
88
  context "with proper params" do
91
- before { Hieracles::Config.load(options) }
92
89
  let(:options) {
93
90
  {
94
91
  config: 'spec/files/config.yml',
@@ -96,7 +93,8 @@ describe Hieracles::Hiera do
96
93
  hierafile: 'hiera.yaml'
97
94
  }
98
95
  }
99
- let(:hiera) { Hieracles::Hiera.new }
96
+ let(:config) { Hieracles::Config.new options }
97
+ let(:hiera) { Hieracles::Hiera.new config }
100
98
 
101
99
  describe '.hierarchy' do
102
100
  let(:expected) { [