rspec-puppet-facts 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,9 @@ describe RspecPuppetFacts do
8
8
  end
9
9
 
10
10
  describe '.stringify_keys' do
11
- it { expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } }) }
11
+ it {
12
+ expect(described_class.stringify_keys({ os: { family: 'RedHat' } })).to eq({ 'os' => { 'family' => 'RedHat' } })
13
+ }
12
14
  end
13
15
 
14
16
  describe '.facter_version_for_puppet_version' do
@@ -137,10 +139,10 @@ describe RspecPuppetFacts do
137
139
  subject(:result) do
138
140
  on_supported_os(
139
141
  {
140
- :supported_os => [
142
+ supported_os: [
141
143
  {
142
- "operatingsystem" => "Debian",
143
- "operatingsystemrelease" => ['7'],
144
+ 'operatingsystem' => 'Debian',
145
+ 'operatingsystemrelease' => ['12'],
144
146
  },
145
147
  ],
146
148
  },
@@ -148,7 +150,7 @@ describe RspecPuppetFacts do
148
150
  end
149
151
 
150
152
  let(:get_keys) do
151
- proc { |r| r.keys + r.select { |_,v| v.is_a?(Hash) }.map { |_,v| get_keys.call(v) }.flatten }
153
+ proc { |r| r.keys + r.select { |_, v| v.is_a?(Hash) }.map { |_, v| get_keys.call(v) }.flatten }
152
154
  end
153
155
 
154
156
  context 'set to true' do
@@ -161,7 +163,7 @@ describe RspecPuppetFacts do
161
163
  end
162
164
 
163
165
  it 'returns a fact set with all the keys as Strings' do
164
- expect(get_keys.call(result['debian-7-x86_64'])).to all(be_a(String))
166
+ expect(get_keys.call(result['debian-12-x86_64'])).to all(be_a(String))
165
167
  end
166
168
  end
167
169
 
@@ -171,7 +173,7 @@ describe RspecPuppetFacts do
171
173
  end
172
174
 
173
175
  it 'returns a fact set with all the keys as Symbols or Strings' do
174
- expect(get_keys.call(result['debian-7-x86_64'])).to all(be_a(Symbol).or(be_a(String)))
176
+ expect(get_keys.call(result['debian-12-x86_64'])).to all(be_a(Symbol).or(be_a(String)))
175
177
  end
176
178
  end
177
179
  end
@@ -209,26 +211,22 @@ describe RspecPuppetFacts do
209
211
  is_expected.to be_a Hash
210
212
  end
211
213
 
212
- it 'has 5 elements' do
213
- expect(subject.size).to eq 5
214
- end
215
-
216
214
  it 'returns supported OS' do
217
- expect(subject.keys.sort).to eq %w(
218
- debian-7-x86_64
219
- debian-8-x86_64
220
- redhat-5-x86_64
221
- redhat-6-x86_64
222
- redhat-7-x86_64
215
+ expect(subject.keys).to contain_exactly(
216
+ 'debian-11-x86_64',
217
+ 'debian-12-x86_64',
218
+ 'redhat-7-x86_64',
219
+ 'redhat-8-x86_64',
220
+ 'redhat-9-x86_64',
223
221
  )
224
222
  end
225
223
 
226
224
  it 'is able to filter the received OS facts' do
227
225
  allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
228
- expect(subject.keys.sort).to eq %w(
229
- redhat-5-x86_64
230
- redhat-6-x86_64
231
- redhat-7-x86_64
226
+ expect(subject.keys).to contain_exactly(
227
+ 'redhat-7-x86_64',
228
+ 'redhat-8-x86_64',
229
+ 'redhat-9-x86_64',
232
230
  )
233
231
  end
234
232
  end
@@ -249,63 +247,58 @@ describe RspecPuppetFacts do
249
247
  context 'With a wrong operatingsystem_support section' do
250
248
  let(:metadata) do
251
249
  {
252
- 'operatingsystem_support' => 'Ubuntu',
250
+ 'operatingsystem_support' => 'Ubuntu',
253
251
  }
254
252
  end
255
253
 
256
254
  it { expect { subject }.to raise_error(StandardError, /Unknown operatingsystem support/) }
257
255
  end
258
256
  end
259
-
260
257
  end
261
258
  end
262
259
 
263
260
  context 'When specifying supported_os' do
264
- subject {
261
+ subject do
265
262
  on_supported_os(
266
263
  {
267
- :supported_os => [
264
+ supported_os: [
268
265
  {
269
- "operatingsystem" => "Debian",
270
- "operatingsystemrelease" => [
271
- "7",
272
- "8",
266
+ 'operatingsystem' => 'Debian',
267
+ 'operatingsystemrelease' => %w[
268
+ 11
269
+ 12
273
270
  ],
274
271
  },
275
272
  {
276
- "operatingsystem" => "RedHat",
277
- "operatingsystemrelease" => [
278
- "5",
279
- "6",
273
+ 'operatingsystem' => 'RedHat',
274
+ 'operatingsystemrelease' => %w[
275
+ 8
276
+ 9
280
277
  ],
281
278
  },
282
279
  ],
283
280
  },
284
281
  )
285
- }
282
+ end
286
283
 
287
284
  it 'returns a hash' do
288
285
  is_expected.to be_a Hash
289
286
  end
290
287
 
291
- it 'has 4 elements' do
292
- expect(subject.size).to eq 4
293
- end
294
-
295
288
  it 'returns supported OS' do
296
- expect(subject.keys.sort).to eq %w(
297
- debian-7-x86_64
298
- debian-8-x86_64
299
- redhat-5-x86_64
300
- redhat-6-x86_64
289
+ expect(subject.keys).to contain_exactly(
290
+ 'debian-11-x86_64',
291
+ 'debian-12-x86_64',
292
+ 'redhat-8-x86_64',
293
+ 'redhat-9-x86_64',
301
294
  )
302
295
  end
303
296
 
304
297
  it 'is able to filter the received OS facts' do
305
298
  allow(described_class).to receive(:spec_facts_os_filter).and_return('redhat')
306
- expect(subject.keys.sort).to eq %w(
307
- redhat-5-x86_64
308
- redhat-6-x86_64
299
+ expect(subject.keys).to contain_exactly(
300
+ 'redhat-8-x86_64',
301
+ 'redhat-9-x86_64',
309
302
  )
310
303
  end
311
304
  end
@@ -314,8 +307,8 @@ describe RspecPuppetFacts do
314
307
  subject(:factsets) do
315
308
  on_supported_os(
316
309
  {
317
- :supported_os => [
318
- { 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => '7' },
310
+ supported_os: [
311
+ { 'operatingsystem' => 'RedHat', 'operatingsystemrelease' => '9' },
319
312
  ],
320
313
  },
321
314
  )
@@ -325,287 +318,245 @@ describe RspecPuppetFacts do
325
318
  expect(factsets).to be_a(Hash)
326
319
  end
327
320
 
328
- it 'returns a single fact set' do
329
- expect(factsets.size).to eq(1)
330
- end
331
-
332
321
  it 'returns a fact set for the specified release' do
333
- expect(factsets).to include('redhat-7-x86_64' => include(:operatingsystemmajrelease => '7'))
322
+ expect(factsets).to match('redhat-9-x86_64' => include(operatingsystemmajrelease: '9'))
334
323
  end
335
324
  end
336
325
 
337
326
  context 'When testing Ubuntu' do
338
- subject {
327
+ subject do
339
328
  on_supported_os(
340
329
  {
341
- :supported_os => [
330
+ supported_os: [
342
331
  {
343
- "operatingsystem" => "Ubuntu",
344
- "operatingsystemrelease" => [
345
- "12.04",
346
- "14.04",
347
- "16.04",
332
+ 'operatingsystem' => 'Ubuntu',
333
+ 'operatingsystemrelease' => [
334
+ '18.04',
335
+ '20.04',
336
+ '22.04',
348
337
  ],
349
338
  },
350
339
  ],
351
340
  },
352
341
  )
353
- }
354
-
355
- let(:expected_fact_sets) do
356
- ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
357
342
  end
358
343
 
359
344
  it 'returns a hash' do
360
- expect(subject.class).to eq Hash
361
- end
362
-
363
- it 'has 3 elements' do
364
- expect(subject.size).to eq(expected_fact_sets.size)
345
+ expect(subject).to be_a Hash
365
346
  end
366
347
 
367
348
  it 'returns supported OS' do
368
- expect(subject.keys.sort).to eq(expected_fact_sets)
349
+ expect(subject.keys).to contain_exactly(
350
+ 'ubuntu-18.04-x86_64',
351
+ 'ubuntu-20.04-x86_64',
352
+ 'ubuntu-22.04-x86_64',
353
+ )
369
354
  end
370
355
  end
371
356
 
372
357
  context 'When testing FreeBSD 10' do
373
- subject {
358
+ subject do
374
359
  on_supported_os(
375
360
  {
376
- :supported_os => [
361
+ supported_os: [
377
362
  {
378
- "operatingsystem" => "FreeBSD",
379
- "operatingsystemrelease" => [
380
- "10",
363
+ 'operatingsystem' => 'FreeBSD',
364
+ 'operatingsystemrelease' => [
365
+ '13',
381
366
  ],
382
367
  },
383
368
  ],
384
- :facterversion => '2.4',
369
+ facterversion: '4.5',
385
370
  },
386
371
  )
387
- }
388
-
389
- it 'returns a hash' do
390
- expect(subject.class).to eq Hash
391
372
  end
392
373
 
393
- it 'has 1 elements' do
394
- expect(subject.size).to eq 1
374
+ it 'returns a hash' do
375
+ expect(subject).to be_a Hash
395
376
  end
396
377
 
397
378
  it 'returns supported OS' do
398
- expect(subject.keys.sort).to eq [
399
- 'freebsd-10-amd64',
400
- ]
379
+ expect(subject.keys).to contain_exactly(
380
+ 'freebsd-13-amd64',
381
+ )
401
382
  end
402
383
  end
403
384
 
404
385
  context 'When testing OpenBSD' do
405
- subject {
386
+ subject do
406
387
  on_supported_os(
407
388
  {
408
- :supported_os => [
389
+ supported_os: [
409
390
  {
410
- "operatingsystem" => "OpenBSD",
411
- "operatingsystemrelease" => [
412
- "5.7",
391
+ 'operatingsystem' => 'OpenBSD',
392
+ 'operatingsystemrelease' => [
393
+ '7.5',
413
394
  ],
414
395
  },
415
396
  ],
416
- :facterversion => '2.4',
397
+ facterversion: '4.7',
417
398
  },
418
399
  )
419
- }
420
-
421
- it 'returns a hash' do
422
- expect(subject.class).to eq Hash
423
400
  end
424
401
 
425
- it 'has 1 elements' do
426
- expect(subject.size).to eq 1
402
+ it 'returns a hash' do
403
+ expect(subject).to be_a Hash
427
404
  end
428
405
 
429
406
  it 'returns supported OS' do
430
- expect(subject.keys.sort).to eq [
431
- 'openbsd-5.7-amd64',
432
- ]
407
+ expect(subject.keys).to contain_exactly(
408
+ 'openbsd-7-amd64',
409
+ )
433
410
  end
434
411
  end
435
412
 
436
- context 'When testing Solaris 11', :if => Facter.version.to_f >= 2.0 do
437
- subject {
413
+ context 'When testing Solaris 11' do
414
+ subject do
438
415
  on_supported_os(
439
- {
440
- :supported_os => [
441
- {
442
- "operatingsystem" => "Solaris",
443
- "operatingsystemrelease" => [
444
- "11",
445
- ],
446
- },
416
+ {
417
+ supported_os: [
418
+ {
419
+ 'operatingsystem' => 'Solaris',
420
+ 'operatingsystemrelease' => [
421
+ '11',
447
422
  ],
448
- },
423
+ },
424
+ ],
425
+ facterversion: '4.0',
426
+ },
449
427
  )
450
- }
451
-
452
- it 'returns a hash' do
453
- expect(subject.class).to eq Hash
454
428
  end
455
429
 
456
- it 'has 1 elements' do
457
- expect(subject.size).to eq 1
430
+ it 'returns a hash' do
431
+ expect(subject).to be_a Hash
458
432
  end
459
433
 
460
434
  it 'returns supported OS' do
461
- expect(subject.keys.sort).to eq %w(
462
- solaris-11-i86pc
435
+ pending('2024-06-07: we dont have a suitable solaris 11 factset in facterdb')
436
+ expect(subject.keys).to contain_exactly(
437
+ 'solaris-11-i86pc',
463
438
  )
464
439
  end
465
440
  end
466
441
 
467
442
  context 'When testing AIX 7.1' do
468
- subject {
443
+ subject do
469
444
  on_supported_os(
470
- {
471
- :supported_os => [
472
- {
473
- "operatingsystem" => "AIX",
474
- "operatingsystemrelease" => [
475
- "7.1", "7100",
476
- ],
477
- },
445
+ {
446
+ supported_os: [
447
+ {
448
+ 'operatingsystem' => 'AIX',
449
+ 'operatingsystemrelease' => [
450
+ '7.1', '7100',
478
451
  ],
479
- :facterversion => '3.9',
480
- },
452
+ },
453
+ ],
454
+ facterversion: '3.9',
455
+ },
481
456
  )
482
- }
483
-
484
- it 'returns a hash' do
485
- expect(subject.class).to eq Hash
486
457
  end
487
458
 
488
- it 'has 1 elements' do
489
- expect(subject.size).to eq 1
459
+ it 'returns a hash' do
460
+ expect(subject).to be_a Hash
490
461
  end
491
462
 
492
463
  it 'returns supported OS' do
493
464
  # NOTE: See FACT-1827 for details on the IBM,8284-22A part
494
465
  # That has to match whatever hardware generated the facts file.
495
- expect(subject.keys.sort).to eq %w(
496
- aix-7100-IBM,8284-22A
466
+ pending('2024-06-07: we dont have a suitable solaris 11 factset in facterdb')
467
+ expect(subject.keys).to contain_exactly(
468
+ 'aix-7100-IBM,8284-22A',
497
469
  )
498
470
  end
499
471
  end
500
472
 
501
- context 'When testing Windows', :if => Facter.version.to_f >= 2.4 do
473
+ context 'When testing Windows' do
502
474
  subject do
503
475
  on_supported_os(
504
476
  {
505
- :supported_os => [
477
+ supported_os: [
506
478
  {
507
- 'operatingsystem' => 'Windows',
479
+ 'operatingsystem' => 'Windows',
508
480
  'operatingsystemrelease' => release,
509
481
  },
510
482
  ],
511
- :facterversion => facterversion,
483
+ facterversion: facterversion,
512
484
  },
513
485
  )
514
486
  end
515
487
 
516
- let(:facterversion) { '3.8.0' }
488
+ let(:facterversion) { '4.2' }
517
489
 
518
490
  context 'with a standard release' do
519
- let(:release) { ['7'] }
491
+ let(:release) { ['10'] }
520
492
 
521
493
  it { is_expected.to be_a(Hash) }
522
- it { is_expected.to have_attributes(:size => 1) }
523
- it { is_expected.to include('windows-7-x86_64' => an_instance_of(Hash)) }
494
+ it { is_expected.to match('windows-10-x86_64' => an_instance_of(Hash)) }
524
495
  end
525
496
 
526
497
  context 'with a revision release' do
527
498
  let(:release) { ['2012 R2'] }
528
499
 
529
500
  it { is_expected.to be_a(Hash) }
530
- it { is_expected.to have_attributes(:size => 1) }
531
- it { is_expected.to include('windows-2012 R2-x86_64' => an_instance_of(Hash)) }
501
+ it { is_expected.to match('windows-2012 R2-x86_64' => an_instance_of(Hash)) }
532
502
  end
533
503
 
534
504
  context 'with a Server prefixed release' do
535
505
  let(:release) { ['Server 2012'] }
536
506
 
537
507
  it { is_expected.to be_a(Hash) }
538
- it { is_expected.to have_attributes(:size => 1) }
539
- it { is_expected.to include('windows-2012-x86_64' => an_instance_of(Hash)) }
508
+ it { is_expected.to match('windows-2012-x86_64' => an_instance_of(Hash)) }
540
509
  end
541
510
 
542
511
  context 'with a 2016 release' do
543
512
  let(:release) { ['2016'] }
544
513
 
545
514
  it { is_expected.to be_a(Hash) }
546
- it { is_expected.to have_attributes(:size => 1) }
547
- it { is_expected.to include('windows-2016-x86_64' => an_instance_of(Hash)) }
548
- end
549
-
550
- context 'with a 2016 release and Facter < 3.4' do
551
- let(:release) { ['2016'] }
552
- let(:facterversion) { '3.3.0' }
553
-
554
- it { is_expected.to be_a(Hash) }
555
- it { is_expected.to have_attributes(:size => 1) }
556
-
557
- it 'munges the operatingsystemmajrelease to 2016' do
558
- is_expected.to include('windows-2016-x86_64' => an_instance_of(Hash))
559
- end
515
+ it { is_expected.to match('windows-2016-x86_64' => an_instance_of(Hash)) }
560
516
  end
561
517
  end
562
518
 
563
519
  context 'When operatingsystemrelease has space' do
564
- subject {
520
+ subject do
565
521
  on_supported_os(
566
522
  {
567
- :supported_os => [
523
+ supported_os: [
568
524
  {
569
- "operatingsystem" => "SLES",
570
- "operatingsystemrelease" => [
571
- "11 SP1",
525
+ 'operatingsystem' => 'SLES',
526
+ 'operatingsystemrelease' => [
527
+ '11 SP1',
572
528
  ],
573
529
  },
574
530
  ],
575
531
  },
576
532
  )
577
- }
578
-
579
- it 'returns a hash' do
580
- expect(subject.class).to eq Hash
581
533
  end
582
534
 
583
- it 'has 1 elements' do
584
- expect(subject.size).to eq 1
535
+ it 'returns a hash' do
536
+ expect(subject).to be_a Hash
585
537
  end
586
538
 
587
539
  it 'returns supported OS' do
588
- expect(subject.keys.sort).to eq [
589
- 'sles-11-x86_64',
590
- ]
540
+ pending('2024-06-7: facterdb has no factset with space in the system release')
541
+ expect(subject.keys).to contain_exactly('sles-11-x86_64')
591
542
  end
592
543
  end
593
544
 
594
545
  context 'When specifying wrong supported_os' do
595
- subject {
546
+ subject do
596
547
  on_supported_os(
597
548
  {
598
- :supported_os => [
549
+ supported_os: [
599
550
  {
600
- "operatingsystem" => "Debian",
601
- "operatingsystemrelease" => [
602
- "4",
551
+ 'operatingsystem' => 'Debian',
552
+ 'operatingsystemrelease' => [
553
+ '4',
603
554
  ],
604
555
  },
605
556
  ],
606
557
  },
607
558
  )
608
- }
559
+ end
609
560
 
610
561
  it 'outputs warning message' do
611
562
  expect(described_class).to receive(:warning).with(/No facts were found in the FacterDB/)
@@ -614,35 +565,31 @@ describe RspecPuppetFacts do
614
565
  end
615
566
 
616
567
  context 'When specifying rolling release operating system' do
617
- subject {
568
+ subject do
618
569
  on_supported_os(
619
570
  {
620
- :supported_os => [
571
+ supported_os: [
621
572
  {
622
- "operatingsystem" => "Debian",
623
- "operatingsystemrelease" => [
624
- "8",
573
+ 'operatingsystem' => 'Debian',
574
+ 'operatingsystemrelease' => [
575
+ '12',
625
576
  ],
626
577
  },
627
578
  {
628
- "operatingsystem" => "Archlinux",
579
+ 'operatingsystem' => 'Gentoo',
629
580
  },
630
581
  ],
631
- :facterversion => '2.4',
582
+ facterversion: '4.6',
632
583
  },
633
584
  )
634
- }
635
-
636
- it 'returns a hash' do
637
- expect(subject.class).to eq Hash
638
585
  end
639
586
 
640
- it 'has 2 elements' do
641
- expect(subject.size).to eq 2
587
+ it 'returns a hash' do
588
+ expect(subject).to be_a Hash
642
589
  end
643
590
 
644
591
  it 'returns supported OS' do
645
- expect(subject.keys.sort).to include(a_string_matching(/\Aarchlinux-\d+-x86_64/), 'debian-8-x86_64')
592
+ expect(subject.keys).to contain_exactly(a_string_matching(/gentoo-\d+-x86_64/), 'debian-12-x86_64')
646
593
  end
647
594
  end
648
595
 
@@ -650,9 +597,9 @@ describe RspecPuppetFacts do
650
597
  subject do
651
598
  on_supported_os(
652
599
  {
653
- :supported_os => [
600
+ supported_os: [
654
601
  {
655
- 'operatingsystem' => 'IOS',
602
+ 'operatingsystem' => 'IOS',
656
603
  'operatingsystemrelease' => ['12.2(25)EWA9'],
657
604
  },
658
605
  ],
@@ -666,12 +613,12 @@ describe RspecPuppetFacts do
666
613
 
667
614
  it 'escapes the parens in the filter' do
668
615
  filter = {
669
- :operatingsystem => "IOS",
670
- :operatingsystemrelease => "/^12\\.2\\(25\\)EWA9/",
671
- :hardwaremodel => "x86_64",
616
+ 'os.name' => 'IOS',
617
+ 'os.release.full' => '/^12\\.2\\(25\\)EWA9/',
618
+ 'os.hardware' => 'x86_64',
672
619
  }
673
620
 
674
- expect(FacterDB).to receive(:get_facts).with(filter).once
621
+ expect(FacterDB).to receive(:get_facts).with(filter, symbolize_keys: true).once
675
622
  subject
676
623
  end
677
624
 
@@ -684,24 +631,23 @@ describe RspecPuppetFacts do
684
631
  subject do
685
632
  on_supported_os(
686
633
  supported_os: [
687
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
634
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] },
688
635
  ],
689
636
  )
690
637
  end
691
638
 
692
639
  before do
693
- RSpec.configuration.default_facter_version = '3.1.6'
640
+ RSpec.configuration.default_facter_version = '4.6.1'
694
641
  end
695
642
 
696
643
  after do
697
644
  RSpec.configuration.default_facter_version = Facter.version
698
645
  end
699
646
 
700
-
701
647
  it 'returns facts from the specified default Facter version' do
702
648
  is_expected.to match(
703
- 'centos-7-x86_64' => include(
704
- :facterversion => /\A3\.1\./,
649
+ 'centos-9-x86_64' => include(
650
+ facterversion: /\A4\.6\./,
705
651
  ),
706
652
  )
707
653
  end
@@ -711,21 +657,20 @@ describe RspecPuppetFacts do
711
657
  subject do
712
658
  on_supported_os(
713
659
  supported_os: [
714
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
660
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] },
715
661
  ],
716
- facterversion: "2.6",
662
+ facterversion: '4.7.99',
717
663
  )
718
664
  end
719
665
 
720
666
  before do
721
- allow(Facter).to receive(:version).and_return('2.4.5')
667
+ allow(Facter).to receive(:version).and_return('4.6')
722
668
  end
723
669
 
724
-
725
670
  it 'returns facts from a facter version matching version and below' do
726
671
  is_expected.to match(
727
- 'centos-7-x86_64' => include(
728
- :facterversion => /\A2\.[0-6]\./,
672
+ 'centos-9-x86_64' => include(
673
+ facterversion: /\A4\.[0-7]\./,
729
674
  ),
730
675
  )
731
676
  end
@@ -741,88 +686,33 @@ describe RspecPuppetFacts do
741
686
  end
742
687
  end
743
688
 
744
- context 'With a custom facterversion (3.1) in the options hash' do
745
- subject do
746
- on_supported_os(
747
- supported_os: [
748
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
749
- ],
750
- facterversion: '3.1',
751
- )
752
- end
753
-
754
- it 'returns facts from a facter version matching 3.1' do
755
- is_expected.to match(
756
- 'centos-7-x86_64' => include(:facterversion => '3.1.6'),
757
- )
758
- end
759
- end
760
-
761
- context 'With a custom facterversion (3.1.2) in the options hash' do
762
- subject do
763
- on_supported_os(
764
- supported_os: [
765
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
766
- ],
767
- facterversion: '3.1.2',
768
- )
769
- end
770
-
771
- it 'returns facts from a facter version matching 3.1' do
772
- is_expected.to match(
773
- 'centos-7-x86_64' => include(:facterversion => '3.1.6'),
774
- )
775
- end
776
- end
777
-
778
- context 'With a custom facterversion (3.3) in the options hash' do
689
+ context 'With a custom facterversion (4.6) in the options hash' do
779
690
  subject do
780
691
  on_supported_os(
781
692
  supported_os: [
782
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
693
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] },
783
694
  ],
784
- facterversion: '3.3',
695
+ facterversion: '4.6',
785
696
  )
786
697
  end
787
698
 
788
- it 'returns facts from a facter version matching 3.3' do
789
- is_expected.to match(
790
- 'centos-7-x86_64' => include(:facterversion => '3.3.0'),
791
- )
699
+ it 'returns facts from a facter version matching 4.6' do
700
+ is_expected.to match('centos-9-x86_64' => include(facterversion: '4.6.1'))
792
701
  end
793
702
  end
794
703
 
795
- context 'With a custom facterversion (3.3.2) in the options hash' do
704
+ context 'With a custom facterversion (4.6.1) in the options hash' do
796
705
  subject do
797
706
  on_supported_os(
798
707
  supported_os: [
799
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
708
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] },
800
709
  ],
801
- facterversion: '3.3.2',
710
+ facterversion: '4.6.1',
802
711
  )
803
712
  end
804
713
 
805
- it 'returns facts from a facter version matching 3.3' do
806
- is_expected.to match(
807
- 'centos-7-x86_64' => include(:facterversion => '3.3.0'),
808
- )
809
- end
810
- end
811
-
812
- context 'When querying a fact set that does not have an operatingsystemmajrelease fact' do
813
- subject do
814
- on_supported_os(
815
- supported_os: [
816
- { 'operatingsystem' => 'SLES', 'operatingsystemrelease' => ['11'] },
817
- ],
818
- facterversion: '2.1.0',
819
- )
820
- end
821
-
822
- it 'splits the operatingsystemrelease fact value to get the major release' do
823
- is_expected.to match(
824
- 'sles-11-x86_64' => include(:operatingsystemrelease => '11.3'),
825
- )
714
+ it 'returns facts from a facter version matching 4.6.1' do
715
+ is_expected.to match('centos-9-x86_64' => include(facterversion: '4.6.1'))
826
716
  end
827
717
  end
828
718
 
@@ -846,52 +736,48 @@ describe RspecPuppetFacts do
846
736
  subject do
847
737
  on_supported_os(
848
738
  supported_os: [
849
- { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] },
850
- { 'operatingsystem' => 'OpenSuSE', 'operatingsystemrelease' => %w[42] },
739
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[9] },
740
+ { 'operatingsystem' => 'Debian', 'operatingsystemrelease' => %w[12] },
851
741
  ],
852
- facterversion: '3.9.5',
742
+ facterversion: '4.6.1',
853
743
  )
854
744
  end
855
745
 
856
746
  before do
857
747
  allow(FacterDB).to receive(:get_facts).and_call_original
858
748
  allow(FacterDB).to receive(:get_facts).with(
859
- {:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^7/", :hardwaremodel=>"x86_64"},
749
+ { 'os.name' => 'CentOS', 'os.release.full' => '/^9/', 'os.hardware' => 'x86_64' }, symbolize_keys: true
860
750
  ).and_wrap_original do |m, *args|
861
- m.call(*args).reject { |facts| facts[:facterversion].start_with?('3.9.') }
751
+ m.call(*args).reject { |facts| facts[:facterversion].start_with?('4.6.') }
862
752
  end
863
753
  end
864
754
 
865
- it 'returns CentOS facts from a facter version matching 3.8' do
866
- is_expected.to include(
867
- 'centos-7-x86_64' => include(:facterversion => '3.8.0'),
868
- )
755
+ it 'returns CentOS facts from a facter version matching 4.5' do
756
+ is_expected.to include('centos-9-x86_64' => include(facterversion: '4.5.2'))
869
757
  end
870
758
 
871
- it 'returns OpenSuSE facts from a facter version matching 3.9' do
872
- is_expected.to include(
873
- 'opensuse-42-x86_64' => include(:facterversion => '3.9.2'),
874
- )
759
+ it 'returns Debian facts from a facter version matching 4.6.1' do
760
+ is_expected.to include('debian-12-x86_64' => include(facterversion: '4.6.1'))
875
761
  end
876
762
  end
877
763
  end
878
764
 
879
765
  describe '#add_custom_fact' do
880
- subject {
766
+ subject do
881
767
  on_supported_os(
882
768
  {
883
- :supported_os => [
769
+ supported_os: [
884
770
  {
885
- "operatingsystem" => "RedHat",
886
- "operatingsystemrelease" => [
887
- "6",
888
- "7",
771
+ 'operatingsystem' => 'RedHat',
772
+ 'operatingsystemrelease' => %w[
773
+ 8
774
+ 9
889
775
  ],
890
776
  },
891
777
  ],
892
778
  },
893
779
  )
894
- }
780
+ end
895
781
 
896
782
  before do
897
783
  described_class.reset
@@ -899,49 +785,51 @@ describe RspecPuppetFacts do
899
785
 
900
786
  it 'adds a simple fact and value' do
901
787
  add_custom_fact 'root_home', '/root'
902
- expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
788
+ expect(subject['redhat-9-x86_64'][:root_home]).to eq '/root'
903
789
  end
904
790
 
905
791
  it 'merges a fact value into fact when merge_facts passed' do
906
792
  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
- })
793
+ expect(subject['redhat-9-x86_64'][:identity]).to eq(
794
+ {
795
+ 'gid' => 0,
796
+ 'group' => 'root',
797
+ 'privileged' => true,
798
+ 'uid' => 0,
799
+ 'user' => 'test_user',
800
+ },
801
+ )
915
802
  end
916
803
 
917
804
  it 'overwrites fact' do
918
805
  add_custom_fact :identity, { 'user' => 'other_user' }
919
- expect(subject['redhat-7-x86_64'][:identity]).to eq(
920
- {
921
- "user"=>"other_user"
922
- })
806
+ expect(subject['redhat-9-x86_64'][:identity]).to eq(
807
+ {
808
+ 'user' => 'other_user',
809
+ },
810
+ )
923
811
  end
924
812
 
925
813
  it 'confines a fact to a particular operating system' do
926
- add_custom_fact 'root_home', '/root', :confine => 'redhat-7-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
814
+ add_custom_fact 'root_home', '/root', confine: 'redhat-9-x86_64'
815
+ expect(subject['redhat-9-x86_64'][:root_home]).to eq '/root'
816
+ expect(subject['redhat-8-x86_64'][:root_home]).to be_nil
929
817
  end
930
818
 
931
819
  it 'excludes a fact from a particular operating system' do
932
- add_custom_fact 'root_home', '/root', :exclude => 'redhat-7-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'
820
+ add_custom_fact 'root_home', '/root', exclude: 'redhat-9-x86_64'
821
+ expect(subject['redhat-9-x86_64'][:root_home]).to be_nil
822
+ expect(subject['redhat-8-x86_64'][:root_home]).to eq '/root'
935
823
  end
936
824
 
937
825
  it 'takes a proc as a value' do
938
826
  add_custom_fact 'root_home', ->(_os, _facts) { '/root' }
939
- expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
827
+ expect(subject['redhat-9-x86_64'][:root_home]).to eq '/root'
940
828
  end
941
829
 
942
830
  it 'accepts sym fact key and stores fact key as sym' do
943
831
  add_custom_fact :root_home, ->(_os, _facts) { '/root' }
944
- expect(subject['redhat-7-x86_64'][:root_home]).to eq '/root'
832
+ expect(subject['redhat-9-x86_64'][:root_home]).to eq '/root'
945
833
  end
946
834
  end
947
835
 
@@ -964,6 +852,7 @@ describe RspecPuppetFacts do
964
852
  def self.open(*_args)
965
853
  self
966
854
  end
855
+
967
856
  def self.get(*_args)
968
857
  'my_version'
969
858
  end
@@ -987,7 +876,7 @@ describe RspecPuppetFacts do
987
876
  end
988
877
 
989
878
  it 'includes an "mco_version" fact' do
990
- expect(subject.common_facts).to include(:mco_version => 'my_version')
879
+ expect(subject.common_facts).to include(mco_version: 'my_version')
991
880
  end
992
881
  end
993
882