voxpupuli-test 2.1.2 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f51041bfbc4a413f50f904b36e0e68e92143dcf36e9a983937dd65d0f709869
4
- data.tar.gz: aa0f3fc47a960a5ec0934b9241fdf376ddc6e884bf6a3da8fc6315f27d1c1ec6
3
+ metadata.gz: 5c7da6bd0c182ed7ca73d10787b1b25fe1efcda71f1a2fad94f9e978699194fc
4
+ data.tar.gz: dbe2534a132bdddb6cca76012c7f3d066fc285c28aba98c7516035e658818c74
5
5
  SHA512:
6
- metadata.gz: d786d510b6a96cf663d374f310860eb230d0ad4d71f6b6a890164a08cc964d0f2ce5499fa021b52fa162ff8c63aeeb162da26e9fe5ea4df005e349f37cce5682
7
- data.tar.gz: 670524ea7f695442cba226beb453224dec3fca7826adf8b211e906bfa76716d4db2a1174bfc99eb00d62430f5ce77df1d1f4c94d137145d34d700222741acd86
6
+ metadata.gz: 7ded37c0fdd619b12575b7d7b8374896b4788b3927bed7592105b2917c961585a55786344f708db4db1fc7b470dc84f9e9ca1e6b8c5bd2ef82b1f0943cabc17a
7
+ data.tar.gz: 34a67d9d9835868e4ac4c7c68da131def85703a05a273aef0d5ac516cb14291f87b24d498d0df68c723bb2edd621a2267aa5567a4dc608b0c17c92b2e2d22b7f
@@ -1,3 +1,6 @@
1
+ require 'rspec-puppet-facts'
2
+ include RspecPuppetFacts
3
+
1
4
  # Override facts
2
5
  #
3
6
  # This doesn't use deep_merge because that's highly unpredictable. It can merge
@@ -32,3 +35,63 @@ def apply_overrides!(facts, overrides, enforce_strings)
32
35
  end
33
36
  end
34
37
  end
38
+
39
+ # Add mocked facts based on the metadata present in the module
40
+ #
41
+ # This means that for some module there are hardcoded mocks, such as stdlib.
42
+ # When stdlib is present in metadata.json, facts like service_provider are
43
+ # mocked and return the correct value according to the OS facts.
44
+ def add_mocked_facts!
45
+ add_facts_for_metadata(RspecPuppetFacts.metadata)
46
+ end
47
+
48
+ def add_facts_for_metadata(metadata)
49
+ return unless metadata && metadata['dependencies']
50
+
51
+ metadata['dependencies'].each do |dependency|
52
+ case normalize_module_name(dependency['name'])
53
+ when 'camptocamp/systemd'
54
+ add_custom_fact :systemd, ->(os, facts) { facts[:service_provider] == 'systemd' }
55
+ when 'puppetlabs/stdlib'
56
+ add_stdlib_facts
57
+ end
58
+ end
59
+ end
60
+
61
+ def normalize_module_name(name)
62
+ return unless name
63
+ name.sub('-', '/')
64
+ end
65
+
66
+ def add_stdlib_facts
67
+ add_custom_fact :puppet_environmentpath, '/etc/puppetlabs/code/environments'
68
+ add_custom_fact :puppet_vardir, '/opt/puppetlabs/puppet/cache'
69
+ add_custom_fact :root_home, '/root'
70
+
71
+ # Rough conversion of grepping in the puppet source:
72
+ # grep defaultfor lib/puppet/provider/service/*.rb
73
+ add_custom_fact :service_provider, ->(os, facts) do
74
+ case facts[:osfamily].downcase
75
+ when 'archlinux'
76
+ 'systemd'
77
+ when 'darwin'
78
+ 'launchd'
79
+ when 'debian'
80
+ 'systemd'
81
+ when 'freebsd'
82
+ 'freebsd'
83
+ when 'gentoo'
84
+ 'openrc'
85
+ when 'openbsd'
86
+ 'openbsd'
87
+ when 'redhat'
88
+ facts[:operatingsystemrelease].to_i >= 7 ? 'systemd' : 'redhat'
89
+ when 'suse'
90
+ facts[:operatingsystemmajrelease].to_i >= 12 ? 'systemd' : 'redhat'
91
+ when 'windows'
92
+ 'windows'
93
+ else
94
+ 'init'
95
+ end
96
+ end
97
+ end
@@ -26,8 +26,6 @@ end
26
26
 
27
27
  require 'voxpupuli/test/facts'
28
28
  require 'puppetlabs_spec_helper/module_spec_helper'
29
- require 'rspec-puppet-facts'
30
- include RspecPuppetFacts
31
29
 
32
30
  # Generating facts is slow - this memoizes the facts between multiple classes.
33
31
  # Marshalling is used to get unique instances which helps when tests overrides
@@ -161,6 +161,9 @@ Style/BracesAroundHashParameters:
161
161
  Style/CaseEquality:
162
162
  Enabled: True
163
163
 
164
+ Style/TrailingCommaInArguments:
165
+ Enabled: False
166
+
164
167
  Layout/CaseIndentation:
165
168
  Enabled: True
166
169
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voxpupuli-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -378,7 +378,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
378
378
  - !ruby/object:Gem::Version
379
379
  version: '0'
380
380
  requirements: []
381
- rubygems_version: 3.0.6
381
+ rubygems_version: 3.1.4
382
382
  signing_key:
383
383
  specification_version: 4
384
384
  summary: Helpers for testing Vox Pupuli modules