rspec-puppet-facts 2.0.5 → 3.0.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/.github/dependabot.yml +10 -1
- data/.github/workflows/release.yml +4 -4
- data/.github/workflows/test.yml +31 -7
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +76 -0
- data/CHANGELOG.md +58 -0
- data/Gemfile +4 -7
- data/README.md +24 -2
- data/Rakefile +11 -5
- data/ext/puppet_agent_components.json +1 -1
- data/lib/rspec-puppet-facts/version.rb +1 -1
- data/lib/rspec-puppet-facts.rb +73 -31
- data/rspec-puppet-facts.gemspec +12 -10
- data/spec/rspec_puppet_facts_spec.rb +323 -196
- metadata +75 -27
@@ -7,6 +7,10 @@ describe RspecPuppetFacts do
|
|
7
7
|
'spec/fixtures/metadata.json'
|
8
8
|
end
|
9
9
|
|
10
|
+
describe '.stringify_keys' do
|
11
|
+
it { expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) }
|
12
|
+
end
|
13
|
+
|
10
14
|
describe '.facter_version_for_puppet_version' do
|
11
15
|
subject(:facter_version) do
|
12
16
|
described_class.facter_version_for_puppet_version(puppet_version)
|
@@ -19,7 +23,7 @@ describe RspecPuppetFacts do
|
|
19
23
|
let(:puppet_version) { Puppet.version }
|
20
24
|
|
21
25
|
context 'when the component JSON file does not exist' do
|
22
|
-
before
|
26
|
+
before do
|
23
27
|
allow(File).to receive(:file?).with(component_json_path).and_return(false)
|
24
28
|
allow(described_class).to receive(:warning)
|
25
29
|
end
|
@@ -36,7 +40,7 @@ describe RspecPuppetFacts do
|
|
36
40
|
end
|
37
41
|
|
38
42
|
context 'when the component JSON file is unreadable' do
|
39
|
-
before
|
43
|
+
before do
|
40
44
|
allow(File).to receive(:readable?).with(component_json_path).and_return(false)
|
41
45
|
allow(described_class).to receive(:warning)
|
42
46
|
end
|
@@ -53,7 +57,7 @@ describe RspecPuppetFacts do
|
|
53
57
|
end
|
54
58
|
|
55
59
|
context 'when the component JSON file is unparseable' do
|
56
|
-
before
|
60
|
+
before do
|
57
61
|
io = StringIO.new('this is not JSON!')
|
58
62
|
allow(File).to receive(:open).with(component_json_path, anything).and_return(io)
|
59
63
|
allow(described_class).to receive(:warning)
|
@@ -112,7 +116,7 @@ describe RspecPuppetFacts do
|
|
112
116
|
context 'when passed a Puppet version lower than any known version' do
|
113
117
|
let(:puppet_version) { '1.0.0' }
|
114
118
|
|
115
|
-
before
|
119
|
+
before do
|
116
120
|
allow(described_class).to receive(:warning)
|
117
121
|
end
|
118
122
|
|
@@ -139,7 +143,7 @@ describe RspecPuppetFacts do
|
|
139
143
|
"operatingsystemrelease" => ['7'],
|
140
144
|
},
|
141
145
|
],
|
142
|
-
}
|
146
|
+
},
|
143
147
|
)
|
144
148
|
end
|
145
149
|
|
@@ -148,11 +152,11 @@ describe RspecPuppetFacts do
|
|
148
152
|
end
|
149
153
|
|
150
154
|
context 'set to true' do
|
151
|
-
before
|
155
|
+
before do
|
152
156
|
RSpec.configuration.facterdb_string_keys = true
|
153
157
|
end
|
154
158
|
|
155
|
-
after
|
159
|
+
after do
|
156
160
|
RSpec.configuration.facterdb_string_keys = false
|
157
161
|
end
|
158
162
|
|
@@ -162,7 +166,7 @@ describe RspecPuppetFacts do
|
|
162
166
|
end
|
163
167
|
|
164
168
|
context 'set to false' do
|
165
|
-
before
|
169
|
+
before do
|
166
170
|
RSpec.configuration.facterdb_string_keys = false
|
167
171
|
end
|
168
172
|
|
@@ -176,7 +180,7 @@ describe RspecPuppetFacts do
|
|
176
180
|
subject { on_supported_os }
|
177
181
|
|
178
182
|
context 'Without metadata.json' do
|
179
|
-
before
|
183
|
+
before do
|
180
184
|
expect(File).to receive(:file?).with('metadata.json').and_return false
|
181
185
|
end
|
182
186
|
|
@@ -185,10 +189,10 @@ describe RspecPuppetFacts do
|
|
185
189
|
|
186
190
|
context 'With a metadata.json' do
|
187
191
|
it 'can load the metadata file' do
|
188
|
-
allow(
|
189
|
-
|
190
|
-
expect(
|
191
|
-
expect(
|
192
|
+
allow(described_class).to receive(:metadata_file).and_return(metadata_file)
|
193
|
+
described_class.reset
|
194
|
+
expect(described_class.metadata).to be_a Hash
|
195
|
+
expect(described_class.metadata['name']).to eq 'mcanevet-mymodule'
|
192
196
|
end
|
193
197
|
|
194
198
|
context 'With a valid metadata.json' do
|
@@ -197,19 +201,19 @@ describe RspecPuppetFacts do
|
|
197
201
|
JSON.parse fixture
|
198
202
|
end
|
199
203
|
|
200
|
-
before
|
201
|
-
allow(
|
204
|
+
before do
|
205
|
+
allow(described_class).to receive(:metadata).and_return(metadata)
|
202
206
|
end
|
203
207
|
|
204
|
-
it '
|
208
|
+
it 'returns a hash' do
|
205
209
|
is_expected.to be_a Hash
|
206
210
|
end
|
207
211
|
|
208
|
-
it '
|
212
|
+
it 'has 5 elements' do
|
209
213
|
expect(subject.size).to eq 5
|
210
214
|
end
|
211
215
|
|
212
|
-
it '
|
216
|
+
it 'returns supported OS' do
|
213
217
|
expect(subject.keys.sort).to eq %w(
|
214
218
|
debian-7-x86_64
|
215
219
|
debian-8-x86_64
|
@@ -219,8 +223,8 @@ describe RspecPuppetFacts do
|
|
219
223
|
)
|
220
224
|
end
|
221
225
|
|
222
|
-
it '
|
223
|
-
allow(
|
226
|
+
it 'is able to filter the received OS facts' do
|
227
|
+
allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
|
224
228
|
expect(subject.keys.sort).to eq %w(
|
225
229
|
redhat-5-x86_64
|
226
230
|
redhat-6-x86_64
|
@@ -230,8 +234,8 @@ describe RspecPuppetFacts do
|
|
230
234
|
end
|
231
235
|
|
232
236
|
context 'With a broken metadata.json' do
|
233
|
-
before
|
234
|
-
allow(
|
237
|
+
before do
|
238
|
+
allow(described_class).to receive(:metadata).and_return(metadata)
|
235
239
|
end
|
236
240
|
|
237
241
|
context 'With a missing operatingsystem_support section' do
|
@@ -266,29 +270,29 @@ describe RspecPuppetFacts do
|
|
266
270
|
"operatingsystemrelease" => [
|
267
271
|
"7",
|
268
272
|
"8",
|
269
|
-
]
|
273
|
+
],
|
270
274
|
},
|
271
275
|
{
|
272
276
|
"operatingsystem" => "RedHat",
|
273
277
|
"operatingsystemrelease" => [
|
274
278
|
"5",
|
275
|
-
"6"
|
276
|
-
]
|
277
|
-
}
|
278
|
-
]
|
279
|
-
}
|
279
|
+
"6",
|
280
|
+
],
|
281
|
+
},
|
282
|
+
],
|
283
|
+
},
|
280
284
|
)
|
281
285
|
}
|
282
286
|
|
283
|
-
it '
|
287
|
+
it 'returns a hash' do
|
284
288
|
is_expected.to be_a Hash
|
285
289
|
end
|
286
290
|
|
287
|
-
it '
|
291
|
+
it 'has 4 elements' do
|
288
292
|
expect(subject.size).to eq 4
|
289
293
|
end
|
290
294
|
|
291
|
-
it '
|
295
|
+
it 'returns supported OS' do
|
292
296
|
expect(subject.keys.sort).to eq %w(
|
293
297
|
debian-7-x86_64
|
294
298
|
debian-8-x86_64
|
@@ -297,8 +301,8 @@ describe RspecPuppetFacts do
|
|
297
301
|
)
|
298
302
|
end
|
299
303
|
|
300
|
-
it '
|
301
|
-
allow(
|
304
|
+
it 'is able to filter the received OS facts' do
|
305
|
+
allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
|
302
306
|
expect(subject.keys.sort).to eq %w(
|
303
307
|
redhat-5-x86_64
|
304
308
|
redhat-6-x86_64
|
@@ -312,8 +316,8 @@ describe RspecPuppetFacts do
|
|
312
316
|
{
|
313
317
|
:supported_os => [
|
314
318
|
{ 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => '7' },
|
315
|
-
]
|
316
|
-
}
|
319
|
+
],
|
320
|
+
},
|
317
321
|
)
|
318
322
|
end
|
319
323
|
|
@@ -344,7 +348,7 @@ describe RspecPuppetFacts do
|
|
344
348
|
],
|
345
349
|
},
|
346
350
|
],
|
347
|
-
}
|
351
|
+
},
|
348
352
|
)
|
349
353
|
}
|
350
354
|
|
@@ -352,13 +356,15 @@ describe RspecPuppetFacts do
|
|
352
356
|
['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
|
353
357
|
end
|
354
358
|
|
355
|
-
it '
|
359
|
+
it 'returns a hash' do
|
356
360
|
expect(subject.class).to eq Hash
|
357
361
|
end
|
358
|
-
|
362
|
+
|
363
|
+
it 'has 3 elements' do
|
359
364
|
expect(subject.size).to eq(expected_fact_sets.size)
|
360
365
|
end
|
361
|
-
|
366
|
+
|
367
|
+
it 'returns supported OS' do
|
362
368
|
expect(subject.keys.sort).to eq(expected_fact_sets)
|
363
369
|
end
|
364
370
|
end
|
@@ -376,16 +382,19 @@ describe RspecPuppetFacts do
|
|
376
382
|
},
|
377
383
|
],
|
378
384
|
:facterversion => '2.4',
|
379
|
-
}
|
385
|
+
},
|
380
386
|
)
|
381
387
|
}
|
382
|
-
|
388
|
+
|
389
|
+
it 'returns a hash' do
|
383
390
|
expect(subject.class).to eq Hash
|
384
391
|
end
|
385
|
-
|
392
|
+
|
393
|
+
it 'has 1 elements' do
|
386
394
|
expect(subject.size).to eq 1
|
387
395
|
end
|
388
|
-
|
396
|
+
|
397
|
+
it 'returns supported OS' do
|
389
398
|
expect(subject.keys.sort).to eq [
|
390
399
|
'freebsd-10-amd64',
|
391
400
|
]
|
@@ -405,16 +414,19 @@ describe RspecPuppetFacts do
|
|
405
414
|
},
|
406
415
|
],
|
407
416
|
:facterversion => '2.4',
|
408
|
-
}
|
417
|
+
},
|
409
418
|
)
|
410
419
|
}
|
411
|
-
|
420
|
+
|
421
|
+
it 'returns a hash' do
|
412
422
|
expect(subject.class).to eq Hash
|
413
423
|
end
|
414
|
-
|
424
|
+
|
425
|
+
it 'has 1 elements' do
|
415
426
|
expect(subject.size).to eq 1
|
416
427
|
end
|
417
|
-
|
428
|
+
|
429
|
+
it 'returns supported OS' do
|
418
430
|
expect(subject.keys.sort).to eq [
|
419
431
|
'openbsd-5.7-amd64',
|
420
432
|
]
|
@@ -433,16 +445,19 @@ describe RspecPuppetFacts do
|
|
433
445
|
],
|
434
446
|
},
|
435
447
|
],
|
436
|
-
}
|
448
|
+
},
|
437
449
|
)
|
438
450
|
}
|
439
|
-
|
451
|
+
|
452
|
+
it 'returns a hash' do
|
440
453
|
expect(subject.class).to eq Hash
|
441
454
|
end
|
442
|
-
|
455
|
+
|
456
|
+
it 'has 1 elements' do
|
443
457
|
expect(subject.size).to eq 1
|
444
458
|
end
|
445
|
-
|
459
|
+
|
460
|
+
it 'returns supported OS' do
|
446
461
|
expect(subject.keys.sort).to eq %w(
|
447
462
|
solaris-11-i86pc
|
448
463
|
)
|
@@ -457,21 +472,24 @@ describe RspecPuppetFacts do
|
|
457
472
|
{
|
458
473
|
"operatingsystem" => "AIX",
|
459
474
|
"operatingsystemrelease" => [
|
460
|
-
"7.1", "7100"
|
475
|
+
"7.1", "7100",
|
461
476
|
],
|
462
477
|
},
|
463
478
|
],
|
464
|
-
:facterversion => '3.9'
|
465
|
-
}
|
479
|
+
:facterversion => '3.9',
|
480
|
+
},
|
466
481
|
)
|
467
482
|
}
|
468
|
-
|
483
|
+
|
484
|
+
it 'returns a hash' do
|
469
485
|
expect(subject.class).to eq Hash
|
470
486
|
end
|
471
|
-
|
487
|
+
|
488
|
+
it 'has 1 elements' do
|
472
489
|
expect(subject.size).to eq 1
|
473
490
|
end
|
474
|
-
|
491
|
+
|
492
|
+
it 'returns supported OS' do
|
475
493
|
# NOTE: See FACT-1827 for details on the IBM,8284-22A part
|
476
494
|
# That has to match whatever hardware generated the facts file.
|
477
495
|
expect(subject.keys.sort).to eq %w(
|
@@ -488,10 +506,10 @@ describe RspecPuppetFacts do
|
|
488
506
|
{
|
489
507
|
'operatingsystem' => 'Windows',
|
490
508
|
'operatingsystemrelease' => release,
|
491
|
-
}
|
509
|
+
},
|
492
510
|
],
|
493
511
|
:facterversion => facterversion,
|
494
|
-
}
|
512
|
+
},
|
495
513
|
)
|
496
514
|
end
|
497
515
|
|
@@ -535,6 +553,7 @@ describe RspecPuppetFacts do
|
|
535
553
|
|
536
554
|
it { is_expected.to be_a(Hash) }
|
537
555
|
it { is_expected.to have_attributes(:size => 1) }
|
556
|
+
|
538
557
|
it 'munges the operatingsystemmajrelease to 2016' do
|
539
558
|
is_expected.to include('windows-2016-x86_64' => an_instance_of(Hash))
|
540
559
|
end
|
@@ -549,20 +568,23 @@ describe RspecPuppetFacts do
|
|
549
568
|
{
|
550
569
|
"operatingsystem" => "SLES",
|
551
570
|
"operatingsystemrelease" => [
|
552
|
-
"11 SP1"
|
553
|
-
]
|
554
|
-
}
|
555
|
-
]
|
556
|
-
}
|
571
|
+
"11 SP1",
|
572
|
+
],
|
573
|
+
},
|
574
|
+
],
|
575
|
+
},
|
557
576
|
)
|
558
577
|
}
|
559
|
-
|
578
|
+
|
579
|
+
it 'returns a hash' do
|
560
580
|
expect(subject.class).to eq Hash
|
561
581
|
end
|
562
|
-
|
582
|
+
|
583
|
+
it 'has 1 elements' do
|
563
584
|
expect(subject.size).to eq 1
|
564
585
|
end
|
565
|
-
|
586
|
+
|
587
|
+
it 'returns supported OS' do
|
566
588
|
expect(subject.keys.sort).to eq [
|
567
589
|
'sles-11-x86_64',
|
568
590
|
]
|
@@ -580,13 +602,13 @@ describe RspecPuppetFacts do
|
|
580
602
|
"4",
|
581
603
|
],
|
582
604
|
},
|
583
|
-
]
|
584
|
-
}
|
605
|
+
],
|
606
|
+
},
|
585
607
|
)
|
586
608
|
}
|
587
609
|
|
588
|
-
it '
|
589
|
-
expect(
|
610
|
+
it 'outputs warning message' do
|
611
|
+
expect(described_class).to receive(:warning).with(/No facts were found in the FacterDB/)
|
590
612
|
subject
|
591
613
|
end
|
592
614
|
end
|
@@ -607,17 +629,19 @@ describe RspecPuppetFacts do
|
|
607
629
|
},
|
608
630
|
],
|
609
631
|
:facterversion => '2.4',
|
610
|
-
}
|
632
|
+
},
|
611
633
|
)
|
612
634
|
}
|
613
635
|
|
614
|
-
it '
|
636
|
+
it 'returns a hash' do
|
615
637
|
expect(subject.class).to eq Hash
|
616
638
|
end
|
617
|
-
|
639
|
+
|
640
|
+
it 'has 2 elements' do
|
618
641
|
expect(subject.size).to eq 2
|
619
642
|
end
|
620
|
-
|
643
|
+
|
644
|
+
it 'returns supported OS' do
|
621
645
|
expect(subject.keys.sort).to include(a_string_matching(/\Aarchlinux-\d+-x86_64/), 'debian-8-x86_64')
|
622
646
|
end
|
623
647
|
end
|
@@ -630,27 +654,24 @@ describe RspecPuppetFacts do
|
|
630
654
|
{
|
631
655
|
'operatingsystem' => 'IOS',
|
632
656
|
'operatingsystemrelease' => ['12.2(25)EWA9'],
|
633
|
-
}
|
657
|
+
},
|
634
658
|
],
|
635
|
-
}
|
659
|
+
},
|
636
660
|
)
|
637
661
|
end
|
638
662
|
|
639
|
-
before
|
640
|
-
allow(
|
641
|
-
allow(FacterDB).to receive(:get_facts).and_call_original
|
663
|
+
before do
|
664
|
+
allow(described_class).to receive(:warning).with(a_string_matching(/no facts were found/i))
|
642
665
|
end
|
643
666
|
|
644
667
|
it 'escapes the parens in the filter' do
|
645
|
-
filter =
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
),
|
651
|
-
]
|
668
|
+
filter = {
|
669
|
+
:operatingsystem => "IOS",
|
670
|
+
:operatingsystemrelease => "/^12\\.2\\(25\\)EWA9/",
|
671
|
+
:hardwaremodel => "x86_64",
|
672
|
+
}
|
652
673
|
|
653
|
-
expect(FacterDB).to receive(:get_facts).with(filter)
|
674
|
+
expect(FacterDB).to receive(:get_facts).with(filter).once
|
654
675
|
subject
|
655
676
|
end
|
656
677
|
|
@@ -660,58 +681,60 @@ describe RspecPuppetFacts do
|
|
660
681
|
end
|
661
682
|
|
662
683
|
context 'With a default Facter version specified in the RSpec configuration' do
|
663
|
-
before(:each) do
|
664
|
-
RSpec.configuration.default_facter_version = '3.1.0'
|
665
|
-
end
|
666
|
-
|
667
|
-
after(:each) do
|
668
|
-
RSpec.configuration.default_facter_version = Facter.version
|
669
|
-
end
|
670
|
-
|
671
684
|
subject do
|
672
685
|
on_supported_os(
|
673
686
|
supported_os: [
|
674
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
675
|
-
]
|
687
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
688
|
+
],
|
676
689
|
)
|
677
690
|
end
|
678
691
|
|
692
|
+
before do
|
693
|
+
RSpec.configuration.default_facter_version = '3.1.6'
|
694
|
+
end
|
695
|
+
|
696
|
+
after do
|
697
|
+
RSpec.configuration.default_facter_version = Facter.version
|
698
|
+
end
|
699
|
+
|
700
|
+
|
679
701
|
it 'returns facts from the specified default Facter version' do
|
680
702
|
is_expected.to match(
|
681
703
|
'centos-7-x86_64' => include(
|
682
|
-
:facterversion => /\A3\.1
|
683
|
-
)
|
704
|
+
:facterversion => /\A3\.1\./,
|
705
|
+
),
|
684
706
|
)
|
685
707
|
end
|
686
708
|
end
|
687
709
|
|
688
710
|
context 'With a version that is above the current gem' do
|
689
|
-
before(:each) do
|
690
|
-
allow(Facter).to receive(:version).and_return('2.4.5')
|
691
|
-
end
|
692
|
-
|
693
711
|
subject do
|
694
712
|
on_supported_os(
|
695
713
|
supported_os: [
|
696
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
714
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
697
715
|
],
|
698
|
-
facterversion: "2.6"
|
716
|
+
facterversion: "2.6",
|
699
717
|
)
|
700
718
|
end
|
701
719
|
|
702
|
-
|
703
|
-
|
720
|
+
before do
|
721
|
+
allow(Facter).to receive(:version).and_return('2.4.5')
|
722
|
+
end
|
723
|
+
|
724
|
+
|
725
|
+
it 'returns facts from a facter version matching version and below' do
|
704
726
|
is_expected.to match(
|
705
727
|
'centos-7-x86_64' => include(
|
706
|
-
:facterversion => /\
|
707
|
-
)
|
728
|
+
:facterversion => /\A2\.[0-6]\./,
|
729
|
+
),
|
708
730
|
)
|
709
731
|
end
|
710
732
|
|
711
733
|
context 'With SPEC_FACTS_STRICT set to `yes`' do
|
712
|
-
before
|
713
|
-
allow(
|
734
|
+
before do
|
735
|
+
allow(described_class).to receive(:spec_facts_strict?).and_return(true)
|
714
736
|
end
|
737
|
+
|
715
738
|
it 'errors' do
|
716
739
|
expect { subject }.to raise_error ArgumentError, /No facts were found in the FacterDB.*aborting/
|
717
740
|
end
|
@@ -722,15 +745,15 @@ describe RspecPuppetFacts do
|
|
722
745
|
subject do
|
723
746
|
on_supported_os(
|
724
747
|
supported_os: [
|
725
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
748
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
726
749
|
],
|
727
|
-
facterversion: '3.1'
|
750
|
+
facterversion: '3.1',
|
728
751
|
)
|
729
752
|
end
|
730
753
|
|
731
754
|
it 'returns facts from a facter version matching 3.1' do
|
732
755
|
is_expected.to match(
|
733
|
-
'centos-7-x86_64' => include(:facterversion => '3.1.6')
|
756
|
+
'centos-7-x86_64' => include(:facterversion => '3.1.6'),
|
734
757
|
)
|
735
758
|
end
|
736
759
|
end
|
@@ -739,15 +762,15 @@ describe RspecPuppetFacts do
|
|
739
762
|
subject do
|
740
763
|
on_supported_os(
|
741
764
|
supported_os: [
|
742
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
765
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
743
766
|
],
|
744
|
-
facterversion: '3.1.2'
|
767
|
+
facterversion: '3.1.2',
|
745
768
|
)
|
746
769
|
end
|
747
770
|
|
748
771
|
it 'returns facts from a facter version matching 3.1' do
|
749
772
|
is_expected.to match(
|
750
|
-
'centos-7-x86_64' => include(:facterversion => '3.1.6')
|
773
|
+
'centos-7-x86_64' => include(:facterversion => '3.1.6'),
|
751
774
|
)
|
752
775
|
end
|
753
776
|
end
|
@@ -756,15 +779,15 @@ describe RspecPuppetFacts do
|
|
756
779
|
subject do
|
757
780
|
on_supported_os(
|
758
781
|
supported_os: [
|
759
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
782
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
760
783
|
],
|
761
|
-
facterversion: '3.3'
|
784
|
+
facterversion: '3.3',
|
762
785
|
)
|
763
786
|
end
|
764
787
|
|
765
788
|
it 'returns facts from a facter version matching 3.3' do
|
766
789
|
is_expected.to match(
|
767
|
-
'centos-7-x86_64' => include(:facterversion => '3.3.0')
|
790
|
+
'centos-7-x86_64' => include(:facterversion => '3.3.0'),
|
768
791
|
)
|
769
792
|
end
|
770
793
|
end
|
@@ -773,15 +796,15 @@ describe RspecPuppetFacts do
|
|
773
796
|
subject do
|
774
797
|
on_supported_os(
|
775
798
|
supported_os: [
|
776
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
799
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
777
800
|
],
|
778
|
-
facterversion: '3.3.2'
|
801
|
+
facterversion: '3.3.2',
|
779
802
|
)
|
780
803
|
end
|
781
804
|
|
782
805
|
it 'returns facts from a facter version matching 3.3' do
|
783
806
|
is_expected.to match(
|
784
|
-
'centos-7-x86_64' => include(:facterversion => '3.3.0')
|
807
|
+
'centos-7-x86_64' => include(:facterversion => '3.3.0'),
|
785
808
|
)
|
786
809
|
end
|
787
810
|
end
|
@@ -790,15 +813,15 @@ describe RspecPuppetFacts do
|
|
790
813
|
subject do
|
791
814
|
on_supported_os(
|
792
815
|
supported_os: [
|
793
|
-
{ 'operatingsystem' => 'SLES', 'operatingsystemrelease' => ['11'] }
|
816
|
+
{ 'operatingsystem' => 'SLES', 'operatingsystemrelease' => ['11'] },
|
794
817
|
],
|
795
|
-
facterversion: '2.1.0'
|
818
|
+
facterversion: '2.1.0',
|
796
819
|
)
|
797
820
|
end
|
798
821
|
|
799
822
|
it 'splits the operatingsystemrelease fact value to get the major release' do
|
800
823
|
is_expected.to match(
|
801
|
-
'sles-11-x86_64' => include(:operatingsystemrelease => '11.3')
|
824
|
+
'sles-11-x86_64' => include(:operatingsystemrelease => '11.3'),
|
802
825
|
)
|
803
826
|
end
|
804
827
|
end
|
@@ -807,9 +830,9 @@ describe RspecPuppetFacts do
|
|
807
830
|
let(:method_call) do
|
808
831
|
on_supported_os(
|
809
832
|
supported_os: [
|
810
|
-
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
|
833
|
+
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
811
834
|
],
|
812
|
-
facterversion: '3'
|
835
|
+
facterversion: '3',
|
813
836
|
)
|
814
837
|
end
|
815
838
|
|
@@ -824,33 +847,36 @@ describe RspecPuppetFacts do
|
|
824
847
|
on_supported_os(
|
825
848
|
supported_os: [
|
826
849
|
{ 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
|
827
|
-
{ 'operatingsystem' => 'OpenSuSE', 'operatingsystemrelease' => %w[42] }
|
850
|
+
{ 'operatingsystem' => 'OpenSuSE', 'operatingsystemrelease' => %w[42] },
|
828
851
|
],
|
829
|
-
facterversion: '3.9.5'
|
852
|
+
facterversion: '3.9.5',
|
830
853
|
)
|
831
854
|
end
|
832
855
|
|
833
|
-
before
|
856
|
+
before do
|
834
857
|
allow(FacterDB).to receive(:get_facts).and_call_original
|
835
858
|
allow(FacterDB).to receive(:get_facts).with(
|
836
|
-
|
837
|
-
).
|
859
|
+
{:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^7/", :hardwaremodel=>"x86_64"},
|
860
|
+
).and_wrap_original do |m, *args|
|
861
|
+
m.call(*args).reject { |facts| facts[:facterversion].start_with?('3.9.') }
|
862
|
+
end
|
838
863
|
end
|
839
864
|
|
840
865
|
it 'returns CentOS facts from a facter version matching 3.8' do
|
841
866
|
is_expected.to include(
|
842
|
-
'centos-7-x86_64' => include(:facterversion => '3.8.0')
|
867
|
+
'centos-7-x86_64' => include(:facterversion => '3.8.0'),
|
843
868
|
)
|
844
869
|
end
|
870
|
+
|
845
871
|
it 'returns OpenSuSE facts from a facter version matching 3.9' do
|
846
872
|
is_expected.to include(
|
847
|
-
'opensuse-42-x86_64' => include(:facterversion => '3.9.2')
|
873
|
+
'opensuse-42-x86_64' => include(:facterversion => '3.9.2'),
|
848
874
|
)
|
849
875
|
end
|
850
876
|
end
|
851
877
|
end
|
852
878
|
|
853
|
-
|
879
|
+
describe '#add_custom_fact' do
|
854
880
|
subject {
|
855
881
|
on_supported_os(
|
856
882
|
{
|
@@ -859,56 +885,81 @@ describe RspecPuppetFacts do
|
|
859
885
|
"operatingsystem" => "RedHat",
|
860
886
|
"operatingsystemrelease" => [
|
861
887
|
"6",
|
862
|
-
"7"
|
863
|
-
]
|
864
|
-
}
|
865
|
-
]
|
866
|
-
}
|
888
|
+
"7",
|
889
|
+
],
|
890
|
+
},
|
891
|
+
],
|
892
|
+
},
|
867
893
|
)
|
868
894
|
}
|
869
895
|
|
870
|
-
before
|
871
|
-
|
896
|
+
before do
|
897
|
+
described_class.reset
|
872
898
|
end
|
873
899
|
|
874
900
|
it 'adds a simple fact and value' do
|
875
901
|
add_custom_fact 'root_home', '/root'
|
876
|
-
expect(subject['redhat-7-x86_64'][
|
902
|
+
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
|
903
|
+
end
|
904
|
+
|
905
|
+
it 'merges a fact value into fact when merge_facts passed' do
|
906
|
+
add_custom_fact :identity, { 'user' => 'test_user' }, merge_facts: true
|
907
|
+
expect(subject['redhat-7-x86_64'][:identity]).to eq(
|
908
|
+
{
|
909
|
+
"gid"=>0,
|
910
|
+
"group"=>"root",
|
911
|
+
"privileged"=>true,
|
912
|
+
"uid"=>0,
|
913
|
+
"user"=>"test_user"
|
914
|
+
})
|
915
|
+
end
|
916
|
+
|
917
|
+
it 'overwrites fact' do
|
918
|
+
add_custom_fact :identity, { 'user' => 'other_user' }
|
919
|
+
expect(subject['redhat-7-x86_64'][:identity]).to eq(
|
920
|
+
{
|
921
|
+
"user"=>"other_user"
|
922
|
+
})
|
877
923
|
end
|
878
924
|
|
879
925
|
it 'confines a fact to a particular operating system' do
|
880
926
|
add_custom_fact 'root_home', '/root', :confine => 'redhat-7-x86_64'
|
881
|
-
expect(subject['redhat-7-x86_64'][
|
882
|
-
expect(subject['redhat-6-x86_64'][
|
927
|
+
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
|
928
|
+
expect(subject['redhat-6-x86_64'][:root_home]).to be_nil
|
883
929
|
end
|
884
930
|
|
885
931
|
it 'excludes a fact from a particular operating system' do
|
886
932
|
add_custom_fact 'root_home', '/root', :exclude => 'redhat-7-x86_64'
|
887
|
-
expect(subject['redhat-7-x86_64'][
|
888
|
-
expect(subject['redhat-6-x86_64'][
|
933
|
+
expect(subject['redhat-7-x86_64'][:root_home]).to be_nil
|
934
|
+
expect(subject['redhat-6-x86_64'][:root_home]).to eq '/root'
|
889
935
|
end
|
890
936
|
|
891
937
|
it 'takes a proc as a value' do
|
892
938
|
add_custom_fact 'root_home', ->(_os, _facts) { '/root' }
|
893
|
-
expect(subject['redhat-7-x86_64'][
|
939
|
+
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
|
940
|
+
end
|
941
|
+
|
942
|
+
it 'accepts sym fact key and stores fact key as sym' do
|
943
|
+
add_custom_fact :root_home, ->(_os, _facts) { '/root' }
|
944
|
+
expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
|
894
945
|
end
|
895
946
|
end
|
896
947
|
|
897
|
-
|
898
|
-
it '
|
899
|
-
|
948
|
+
describe '#misc' do
|
949
|
+
it 'has a common facts structure' do
|
950
|
+
described_class.reset
|
900
951
|
expect(subject.common_facts).to be_a Hash
|
901
952
|
expect(subject.common_facts).not_to be_empty
|
902
953
|
end
|
903
954
|
|
904
|
-
it '
|
955
|
+
it 'does not add "augeasversion" if Augeas is supported' do
|
905
956
|
allow(described_class).to receive(:augeas?).and_return(false)
|
906
|
-
|
957
|
+
described_class.reset
|
907
958
|
expect(subject.common_facts).not_to include(:augeasversion)
|
908
959
|
end
|
909
960
|
|
910
|
-
it '
|
911
|
-
module
|
961
|
+
it 'determines the Augeas version if Augeas is supported' do
|
962
|
+
module AugeasStub # rubocop:todo Lint/ConstantDefinitionInBlock
|
912
963
|
NO_MODL_AUTOLOAD = true
|
913
964
|
def self.open(*_args)
|
914
965
|
self
|
@@ -919,19 +970,19 @@ describe RspecPuppetFacts do
|
|
919
970
|
end
|
920
971
|
|
921
972
|
allow(described_class).to receive(:augeas?).and_return(true)
|
922
|
-
stub_const('Augeas',
|
923
|
-
|
973
|
+
stub_const('Augeas', AugeasStub)
|
974
|
+
described_class.reset
|
924
975
|
expect(subject.common_facts[:augeasversion]).to eq 'my_version'
|
925
976
|
end
|
926
977
|
|
927
978
|
context 'when mcollective is available' do
|
928
|
-
module
|
979
|
+
module MCollectiveStub # rubocop:todo Lint/ConstantDefinitionInBlock
|
929
980
|
VERSION = 'my_version'
|
930
981
|
end
|
931
982
|
|
932
|
-
before
|
983
|
+
before do
|
933
984
|
allow(described_class).to receive(:mcollective?).and_return(true)
|
934
|
-
stub_const('MCollective',
|
985
|
+
stub_const('MCollective', MCollectiveStub)
|
935
986
|
described_class.reset
|
936
987
|
end
|
937
988
|
|
@@ -941,7 +992,7 @@ describe RspecPuppetFacts do
|
|
941
992
|
end
|
942
993
|
|
943
994
|
context 'when mcollective is not available' do
|
944
|
-
before
|
995
|
+
before do
|
945
996
|
allow(described_class).to receive(:mcollective?).and_return(false)
|
946
997
|
described_class.reset
|
947
998
|
end
|
@@ -952,69 +1003,145 @@ describe RspecPuppetFacts do
|
|
952
1003
|
end
|
953
1004
|
end
|
954
1005
|
|
955
|
-
describe '.
|
1006
|
+
describe '.facter_version_to_strict_requirement' do
|
1007
|
+
subject { described_class.facter_version_to_strict_requirement(version) }
|
1008
|
+
|
1009
|
+
context 'when passed a version that is a complex requirement' do
|
1010
|
+
let(:version) { '~> 2.4' }
|
1011
|
+
|
1012
|
+
it { is_expected.to be_instance_of(Gem::Requirement) }
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
context 'when passed a version that is major' do
|
1016
|
+
let(:version) { '1' }
|
1017
|
+
|
1018
|
+
it { is_expected.to be_instance_of(Gem::Requirement) }
|
1019
|
+
end
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
describe '.facter_version_to_strict_requirement_string' do
|
1023
|
+
subject { described_class.facter_version_to_strict_requirement_string(version) }
|
1024
|
+
|
1025
|
+
context 'when passed a version that is a complex requirement' do
|
1026
|
+
let(:version) { '~> 2.4' }
|
1027
|
+
|
1028
|
+
it { is_expected.to eq('~> 2.4') }
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
context 'when passed a version that is major' do
|
1032
|
+
let(:version) { '1' }
|
1033
|
+
|
1034
|
+
it { is_expected.to eq('~> 1.0') }
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
context 'when passed a version that is major.minor' do
|
1038
|
+
let(:version) { '1.2' }
|
1039
|
+
|
1040
|
+
it { is_expected.to eq('~> 1.2.0') }
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
context 'when passed a version that is major.minor.patch' do
|
1044
|
+
let(:version) { '1.2.3' }
|
1045
|
+
|
1046
|
+
it { is_expected.to eq('~> 1.2.3.0') }
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
describe '.facter_version_to_loose_requirement' do
|
1051
|
+
subject { described_class.facter_version_to_loose_requirement(version) }
|
1052
|
+
|
1053
|
+
context 'when passed a version that is a complex requirement' do
|
1054
|
+
let(:version) { '~> 2.4' }
|
1055
|
+
|
1056
|
+
it { is_expected.to be_nil }
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
context 'when passed a version that is major' do
|
1060
|
+
let(:version) { '1' }
|
1061
|
+
|
1062
|
+
it { is_expected.to be_instance_of(Gem::Requirement) }
|
1063
|
+
end
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
describe '.facter_version_to_loose_requirement_string' do
|
1067
|
+
subject { described_class.facter_version_to_loose_requirement_string(version) }
|
1068
|
+
|
1069
|
+
context 'when passed a version that is a complex requirement (1)' do
|
1070
|
+
let(:version) { '~> 2.4' }
|
1071
|
+
|
1072
|
+
it { is_expected.to be_nil }
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
context 'when passed a version that is a complex requirement (2)' do
|
1076
|
+
let(:version) { '>= 3 < 5' }
|
1077
|
+
|
1078
|
+
it { is_expected.to be_nil }
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
context 'when passed a version that is major (1)' do
|
1082
|
+
let(:version) { '1' }
|
1083
|
+
|
1084
|
+
it { is_expected.to eq('< 2') }
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
context 'when passed a version that is major (2)' do
|
1088
|
+
let(:version) { '9' }
|
1089
|
+
|
1090
|
+
it { is_expected.to eq('< 10') }
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
context 'when passed a version that is major (3)' do
|
1094
|
+
let(:version) { '10' }
|
1095
|
+
|
1096
|
+
it { is_expected.to eq('< 11') }
|
1097
|
+
end
|
1098
|
+
|
956
1099
|
context 'when passed a version that is major.minor (1)' do
|
957
|
-
|
1100
|
+
let(:version) { '1.2' }
|
958
1101
|
|
959
|
-
it
|
960
|
-
is_expected.to eq('/\A1\.2\./')
|
961
|
-
end
|
1102
|
+
it { is_expected.to eq('< 1.3') }
|
962
1103
|
end
|
963
1104
|
|
964
1105
|
context 'when passed a version that is major.minor (2)' do
|
965
|
-
|
1106
|
+
let(:version) { '10.2' }
|
966
1107
|
|
967
|
-
it
|
968
|
-
is_expected.to eq('/\A10\.2\./')
|
969
|
-
end
|
1108
|
+
it { is_expected.to eq('< 10.3') }
|
970
1109
|
end
|
971
1110
|
|
972
1111
|
context 'when passed a version that is major.minor (3)' do
|
973
|
-
|
1112
|
+
let(:version) { '1.20' }
|
974
1113
|
|
975
|
-
it
|
976
|
-
is_expected.to eq('/\A1\.20\./')
|
977
|
-
end
|
1114
|
+
it { is_expected.to eq('< 1.21') }
|
978
1115
|
end
|
979
1116
|
|
980
1117
|
context 'when passed a version that is major.minor (4)' do
|
981
|
-
|
1118
|
+
let(:version) { '10.20' }
|
982
1119
|
|
983
|
-
it
|
984
|
-
is_expected.to eq('/\A10\.20\./')
|
985
|
-
end
|
1120
|
+
it { is_expected.to eq('< 10.21') }
|
986
1121
|
end
|
987
1122
|
|
988
1123
|
context 'when passed a version that is major.minor.patch (1)' do
|
989
|
-
|
1124
|
+
let(:version) { '1.2.3' }
|
990
1125
|
|
991
|
-
it
|
992
|
-
is_expected.to eq('/\A1\.2\./')
|
993
|
-
end
|
1126
|
+
it { is_expected.to eq('< 1.3') }
|
994
1127
|
end
|
995
1128
|
|
996
1129
|
context 'when passed a version that is major.minor.patch (2)' do
|
997
|
-
|
1130
|
+
let(:version) { '10.2.3' }
|
998
1131
|
|
999
|
-
it
|
1000
|
-
is_expected.to eq('/\A10\.2\./')
|
1001
|
-
end
|
1132
|
+
it { is_expected.to eq('< 10.3') }
|
1002
1133
|
end
|
1003
1134
|
|
1004
1135
|
context 'when passed a version that is major.minor.patch (3)' do
|
1005
|
-
|
1136
|
+
let(:version) { '1.20.3' }
|
1006
1137
|
|
1007
|
-
it
|
1008
|
-
is_expected.to eq('/\A1\.20\./')
|
1009
|
-
end
|
1138
|
+
it { is_expected.to eq('< 1.21') }
|
1010
1139
|
end
|
1011
1140
|
|
1012
1141
|
context 'when passed a version that is major.minor.patch (4)' do
|
1013
|
-
|
1142
|
+
let(:version) { '10.20.3' }
|
1014
1143
|
|
1015
|
-
it
|
1016
|
-
is_expected.to eq('/\A10\.20\./')
|
1017
|
-
end
|
1144
|
+
it { is_expected.to eq('< 10.21') }
|
1018
1145
|
end
|
1019
1146
|
end
|
1020
1147
|
end
|