rspec-puppet-facts 1.9.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 601e63e42c9bd47dcfa7a4595770e4b2f75638f1
4
- data.tar.gz: 86c454040c79b8dc060e197fa0ca2a810edafaa7
2
+ SHA256:
3
+ metadata.gz: c6f2c4f366097ef9da38344e40bbc75661a8b7ea00ca6e58e03acaa8c3683ea3
4
+ data.tar.gz: 8e29a1c06d530ee7e435444a76a8e91db43b3b98701926077385cbb87e2dfb38
5
5
  SHA512:
6
- metadata.gz: fba02b4a1a05373922f6686bd606e328918f443e528934fd0b056c128d51f01c60a3fdb70c2db309f697cdcbe7a0a538eb8e3e0dee3558940311955977bc01d0
7
- data.tar.gz: 62e87c175fd6280657886628b371b457cde4a6452f9558f931db0f83be3ceaecba05340e728f39003246a57e191c927b612ad64e6ad9be5384a86a62dbc7a67c
6
+ metadata.gz: 7b79b495755111113ace37d28d88e6c570527fb35c05b944c77cb8dc5853c2dc49dd96d79a703ff08059c33f5eea18bece24a4d6f855bacdb3def82825582758
7
+ data.tar.gz: 0fd818ffa5c6ffaec24505ca5d97bce55815e943e78ff91441e6ddd8c3632fff61d5dc310a9f676db27132a47bbf7164635cb6c3a1563c54659ced0ce43ba871
data/.travis.yml CHANGED
@@ -1,27 +1,28 @@
1
- ---
2
1
  language: ruby
3
2
  sudo: false
4
3
  cache: bundler
5
4
  script:
6
- - bundle exec rake spec
5
+ - bundle exec rake spec
6
+ - bundle exec rake puppet_versions:test
7
+ - bundle exec rake build
7
8
  rvm:
8
- - 1.8.7
9
- - 1.9.3
10
- - 2.0.0
11
- - 2.1.5
12
- env:
13
- - FACTER_GEM_VERSION="~> 1.6.0"
14
- - FACTER_GEM_VERSION="~> 1.7.0"
15
- - FACTER_GEM_VERSION="~> 2.0.0"
16
- - FACTER_GEM_VERSION="~> 2.1.0"
17
- - FACTER_GEM_VERSION="~> 2.2.0"
18
- - FACTER_GEM_VERSION="~> 2.3.0"
19
- - FACTER_GEM_VERSION="~> 2.4.0"
20
- - FACTER_GEM_VERSION="~> 2.0"
9
+ - 2.4
10
+ - 2.5
11
+ - 2.7
21
12
  matrix:
22
13
  fast_finish: true
23
- allow_failures:
24
- - rvm: 1.8.7
25
- - rvm: 1.9.3
14
+ include:
15
+ - rvm: 2.6
16
+ env: COVERAGE=true
26
17
  notifications:
27
18
  email: false
19
+ deploy:
20
+ provider: rubygems
21
+ api_key:
22
+ secure: EGvtHfBYUSjhZjLPGZHHH7Exsu9xyYSNlbI/F9SNRDmY568tBZs1Pw05Pr9dhUXajs3xXPkHQwMEBgNs2Rg2SPc6+dCyvabbNM2U58yj5R5D7+ZdUWC1APgjiDvBhm0N5hihmAnoBKPlmPKMh91OQwKI/8/GOhWAQaIZRnNBzMQ+gwHQ8xIkqt3unxJ/LtRybFDzTF5aMtIHrfE8kV08BLaKUzJptzj7Wt5Ms1zE/2UV1S7DhSvZnxWaWtNZwaQPo9NFhjHr5k3nLIoWi6Ge3khVSukZcAki9cR37Tjeyms5B10hp6jW5c6EgCDQp5VNcD/1LgtTs8fWI6mvTsa3YCyaQdVy2SvhUD88/CohFvLXbGcdkFFzwhPa57aCKazq14fh5epScRzAfGpJojkPcxdc5/fiuZiaPg+jmT/OMFqNjQW1C6m2S+VltlXVCyjT83Ri9J9/AEu708akErhz7XjcspxJL8//KVvS/3o4hjtoef1OXxRN+oh3VGwbEZSiqOmjxr6/AigaYsrWOTdz+OZa4fGYbUb9hMHnq314cjgGUMyzZ9tQN8v4mMZb1ZKZPuqrP6um1Y7WbHQJvwl3sXEUuDN68eyWp103M1nyma6hON4+F+r58kTuoWRmy06ZsaEjz57bFxdnDjB8It8V7pI0bcmfs/q5tMIPw6Gh14w=
23
+ gem: rspec-puppet-facts
24
+ on:
25
+ tags: true
26
+ repo: mcanevet/rspec-puppet-facts
27
+ all_branches: true
28
+ rvm: 2.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,54 @@
1
+ ## 2020-08-04 - Release 2.0.0
2
+
3
+ - Require Ruby >= 2.4
4
+ - Automatically find the latest facter version in the database. Previously a
5
+ very slow and undeterministic approach was taken when an exact match of the
6
+ Facter version wasn't found.. The new approach is to take the closest version
7
+ that is still older than the specified version.
8
+ - Fix Amazon Linux 2 fact lookup
9
+ - Log which facts could not be found
10
+ - Remove json as a dependency
11
+
12
+ ## 2019-12-11 - Release 1.10.0
13
+ - Automatically select the default Facter version based on the Puppet version.
14
+ The available Puppet version is matched against a mapping of Puppet and
15
+ Facter versions included in the `puppet-agent` all-in-one packages to find
16
+ the most suitable Facter version.
17
+
18
+ ## 2019-07-31 - Release 1.9.6
19
+ - Suppress the warning message generated when the Augeas gem is not available.
20
+ - Searching through older Facter releases for a fact set that does not exist no
21
+ longer causes it to hang indefinitely.
22
+ - The `operatingsystemrelease` values are now correctly escaped when building
23
+ the FacterDB filters, allowing the use of `operatingsystemrelease` values
24
+ that contain special regular expression characters like parentheses.
25
+
26
+ ## 2019-07-29 - Release 1.9.5
27
+ - The default version of Facter to search for is now configurable with
28
+ `RSpec.configuration.default_facter_version`.
29
+ - When passing a `:supported_os` hash to `on_supported_os()`, single
30
+ `operatingsystemrelease` values can now be specified as a String rather than
31
+ an Array with a single String.
32
+ - Dependency on the `mcollective-client` gem removed. The `mco_version` fact
33
+ will now optionally be set if the gem is installed.
34
+ - The fact names can now be provided to tests as Strings instead of Symbols by
35
+ setting `RSpec.configuration.facterdb_string_keys` to `true`.
36
+ - Dropped support for Ruby < 2.1.0
37
+
38
+ ## 2019-03-22 - Release 1.9.4
39
+ - Take two on getting rubygems autodeploy going. So much for docs,
40
+ looking at other projects for this one.
41
+ ## 2019-03-22 - Release 1.9.3
42
+ - Various CI updates - [Garrett Honeycutt](https://github.com/ghoneycutt/)
43
+ - Symbolize hash keys in `register_custom_fact`
44
+ [https://github.com/mcanevet/rspec-puppet-facts/pull/77](https://github.com/mcanevet/rspec-puppet-facts/pull/77)
45
+
46
+ ## 2018-10-24 - Release 1.9.2
47
+ - Catch the right `LoadError` on missing augeas gem. Thanks to [baurmatt](https://github.com/baurmatt) for the quick fix, and [rodjek](https://github.com/rodjek) for dealing with the testing
48
+
49
+ ## 2018-10-24 - Release 1.9.1
50
+ - Do not rely on features of Augeas because Puppet 6
51
+
1
52
  ## 2018-01-31 - Release 1.9.0
2
53
  - Bumps facterdb requirement to 0.5.0
3
54
  - Adds docs for using custom external facts
data/Gemfile CHANGED
@@ -7,9 +7,3 @@ if facterversion = ENV['FACTER_GEM_VERSION']
7
7
  else
8
8
  gem 'facter', :require => false
9
9
  end
10
-
11
- platforms :ruby_18, :ruby_19 do
12
- gem 'json', '~> 1.0'
13
- gem 'json_pure', '~> 1.0'
14
- gem 'tins', '~> 1.6.0'
15
- end
data/README.md CHANGED
@@ -7,7 +7,7 @@ rspec-puppet-facts
7
7
  [![Gem Downloads](https://img.shields.io/gem/dt/rspec-puppet-facts.svg)](https://rubygems.org/gems/rspec-puppet-facts)
8
8
  [![Coverage Status](https://img.shields.io/coveralls/mcanevet/rspec-puppet-facts.svg)](https://coveralls.io/r/mcanevet/rspec-puppet-facts?branch=master)
9
9
 
10
- Based on an original idea from [apenney](https://github.com/apenney/puppet_facts/), this gem provides a method of running your [rspec-puppet](https://github.com/rodjek/rspec-puppet) tests against the facts for all your supported operating systems (provided by [facterdb](https://github.com/camptocamp/facterdb). This simplifies unit testing because you don't need to specify the facts yourself.
10
+ Based on an original idea from [apenney](https://github.com/apenney/puppet_facts/), this gem provides a method of running your [rspec-puppet](https://github.com/rodjek/rspec-puppet) tests against the facts for all your supported operating systems (provided by [facterdb](https://github.com/camptocamp/facterdb)). This simplifies unit testing because you don't need to specify the facts yourself.
11
11
 
12
12
  ## Installation
13
13
 
@@ -16,7 +16,7 @@ If you're using Bundler to manage gems in your module repository, install `rspec
16
16
  1. Add the following line to your `Gemfile`:
17
17
 
18
18
  ```ruby
19
- gem 'rspec-puppet-facts', '~> 1.7', :require => false
19
+ gem 'rspec-puppet-facts', :require => false
20
20
  ```
21
21
 
22
22
  2. Run `bundle install`.
@@ -38,7 +38,7 @@ include RspecPuppetFacts
38
38
 
39
39
  ## Specifying the supported operating systems
40
40
 
41
- To determine which facts to run your tests against, `rspec-puppet-facts` checks your module's `metadata.json` to find out what operating systems your module supports. The `metadata.json` file is located in the root of your module. To learn more about this file, see Puppet's [metatdata](https://docs.puppet.com/puppet/latest/modules_metadata.html) documentation.
41
+ To determine which facts to run your tests against, `rspec-puppet-facts` checks your module's `metadata.json` to find out what operating systems your module supports. The `metadata.json` file is located in the root of your module. To learn more about this file, see Puppet's [metadata](https://docs.puppet.com/puppet/latest/modules_metadata.html) documentation.
42
42
 
43
43
  By default, `rspec-puppet-facts` provides the facts only for `x86_64` architecture. However, you can override this default and the supported operating system list by passing a hash to `on_supported_os` in your tests. This hash must contain either or both of the following keys:
44
44
 
@@ -64,12 +64,44 @@ describe 'myclass::debian' do
64
64
  ],
65
65
  }
66
66
 
67
- on_supported_os(test_on).each do |os, facts|
68
- let (:facts) { facts }
67
+ on_supported_os(test_on).each do |os, os_facts|
68
+ let (:facts) { os_facts }
69
69
  it { is_expected.to compile.with_all_deps }
70
70
  end
71
71
  end
72
72
  ```
73
+ Ruby 1.9 and later:
74
+ ```ruby
75
+ require 'spec_helper'
76
+
77
+ describe 'myclass::raspbian' do
78
+ test_on = {
79
+ supported_os: [
80
+ {
81
+ 'operatingsystem' => 'Debian',
82
+ 'operatingsystemrelease' => ['10', '9', '8'],
83
+ },
84
+ ],
85
+ }
86
+ on_supported_os(test_on).each do |os, os_facts|
87
+ let(:facts) { os_facts }
88
+ it { is_expected.to compile.with_all_deps }
89
+ end
90
+ end
91
+ ```
92
+
93
+ ## Specifying a default Facter version
94
+
95
+ By default, `os_supported_os` will return the facts for the version of Facter
96
+ that it has loaded (usually this is Facter 2.5.1). This behaviour can be
97
+ overridden by setting the `default_facter_version` RSpec setting in your
98
+ `spec/spec_helper.rb` file.
99
+
100
+ ```ruby
101
+ RSpec.configure do |c|
102
+ c.default_facter_version = '3.14.0'
103
+ end
104
+ ```
73
105
 
74
106
  ## Usage
75
107
 
@@ -126,17 +158,17 @@ require 'spec_helper'
126
158
 
127
159
  describe 'myclass' do
128
160
 
129
- on_supported_os.each do |os, facts|
161
+ on_supported_os.each do |os, os_facts|
130
162
  context "on #{os}" do
131
163
  let(:facts) do
132
- facts
164
+ os_facts
133
165
  end
134
166
 
135
167
  it { is_expected.to compile.with_all_deps }
136
168
  ...
137
169
 
138
170
  # If you need any to specify any operating system specific tests
139
- case facts[:osfamily]
171
+ case os_facts[:osfamily]
140
172
  when 'Debian'
141
173
  ...
142
174
  else
@@ -147,6 +179,56 @@ describe 'myclass' do
147
179
  end
148
180
  ```
149
181
 
182
+ When using roles and profiles to manage a heterogeneous IT estate, you can test a profile that supports several OSes with many `let(:facts)` as long as each is in its own context:
183
+ ```ruby
184
+ require 'spec_helper'
185
+
186
+ describe 'profiles::packagerepos' do
187
+ context 'Raspbian tests' do # We manage hundreds of desk-mounted Pis
188
+ raspbian = {
189
+ hardwaremodels: ['armv7l'],
190
+ supported_os: [
191
+ {
192
+ 'operatingsystem' => 'Debian',
193
+ 'operatingsystemrelease' => ['10', '9', '8'],
194
+ },
195
+ ],
196
+ }
197
+ on_supported_os(raspbian).each do |os, os_facts|
198
+ let(:facts) do
199
+ os_facts
200
+ end
201
+
202
+ context "#{os} with defaults" do
203
+ it { is_expected.to compile }
204
+ # more tests ...
205
+ end
206
+ end
207
+ end
208
+ context 'Ubuntu tests' do # And also a fleet of Ubuntu desktops
209
+ ubuntu = {
210
+ supported_os: [
211
+ {
212
+ 'operatingsystem' => 'Ubuntu',
213
+ 'operatingsystemrelease' => ['18.04', '16.04'],
214
+ },
215
+ ],
216
+ }
217
+
218
+ on_supported_os(ubuntu).each do |os, os_facts|
219
+ let(:facts) do
220
+ os_facts
221
+ end
222
+
223
+ context "#{os} with defaults" do
224
+ it { is_expected.to compile }
225
+ # more tests ...
226
+ end
227
+ end
228
+ end
229
+ end
230
+ ```
231
+
150
232
  ### Testing a type or provider
151
233
 
152
234
  Use `on_supported_os` in the same way for your type and provider unit tests.
@@ -194,17 +276,17 @@ require 'spec_helper'
194
276
 
195
277
  describe 'mytype' do
196
278
 
197
- on_supported_os.each do |os, facts|
279
+ on_supported_os.each do |os, os_facts|
198
280
  context "on #{os}" do
199
281
  let(:facts) do
200
- facts
282
+ os_facts
201
283
  end
202
284
 
203
285
  it { should be_valid_type }
204
286
  ...
205
287
 
206
288
  # If you need to specify any operating system specific tests
207
- case facts[:osfamily]
289
+ case os_facts[:osfamily]
208
290
  when 'Debian'
209
291
  ...
210
292
  else
@@ -262,10 +344,10 @@ require 'spec_helper'
262
344
 
263
345
  describe 'myfunction' do
264
346
 
265
- on_supported_os.each do |os, facts|
347
+ on_supported_os.each do |os, os_facts|
266
348
  context "on #{os}" do
267
349
  let(:facts) do
268
- facts
350
+ os_facts
269
351
  end
270
352
 
271
353
  it { should run.with_params('something').and_return('a value') }
@@ -294,12 +376,12 @@ To override fact values and include additional facts in your tests, merge values
294
376
  require 'spec_helper'
295
377
 
296
378
  describe 'myclass' do
297
- on_supported_os.each do |os, facts|
379
+ on_supported_os.each do |os, os_facts|
298
380
  context "on #{os}" do
299
381
 
300
382
  # Add the 'foo' fact with the value 'bar' to the tests
301
383
  let(:facts) do
302
- facts.merge({
384
+ os_facts.merge({
303
385
  :foo => 'bar',
304
386
  })
305
387
  end
@@ -355,9 +437,9 @@ To do this, pass a lambda as the value for the custom fact. The lambda is passed
355
437
  add_custom_fact :root_home, lambda { |os,facts| "/tmp/#{facts['hostname']}" }
356
438
  ```
357
439
 
358
- ### Suppling Custom External Facts through FacterDB
440
+ ### Supplying Custom External Facts through FacterDB
359
441
  Rspec-puppet-facts uses a gem called facterdb that contains many fact sets of various combinations that are pre generated. Rspec-puppet-facts queries
360
- facterdb to pull out a specific fact set to use when testing.
442
+ facterdb to pull out a specific fact set to use when testing.
361
443
 
362
444
  The default facts are great for many things but there will be times when you need to have custom
363
445
  fact sets that only make sense in your environment or might contain sensitive information.
@@ -366,7 +448,7 @@ To supply external facts to facterdb just set the `FACTERDB_SEARCH_PATHS` enviro
366
448
  paths to your facts.
367
449
 
368
450
  When separating paths please use the default path separator character supported by your OS.
369
- * Unix/Linux/OSX = `:`
451
+ * Unix/Linux/OSX = `:`
370
452
  * Windows = `;`
371
453
 
372
454
  This means you will need to supply your own fact sets in addition to the ones contained in facterdb.
@@ -422,7 +504,7 @@ ENV['FACTERDB_SEARCH_PATHS'] = custom_facts
422
504
  ```
423
505
  ## Running your tests
424
506
 
425
- For most cases, there is no change to how you run your tests. Running `rake spec` will run all the tests against the facts for all the supported operating systems.
507
+ For most cases, there is no change to how you run your tests. Running `rake spec` will run all the tests against the facts for all the supported operating systems. If you are developing a module using the [Puppet Development Kit](https://puppet.com/docs/pdk/1.x/pdk_install.html), `pdk test unit` will run all your tests against the supported operating systems listed in `metadata.json`.
426
508
 
427
509
  If you want to run the tests against the facts for specific operating systems, you can provide a filter in the `SPEC_FACTS_OS` environment variable and only the supported operating systems whose name starts with the specified filter will be used.
428
510
 
data/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ PUPPET_VERSIONS_PATH = File.join(__dir__, 'ext', 'puppet_agent_components.json')
4
+
1
5
  begin
2
6
  require 'rspec/core/rake_task'
3
7
  require 'yard'
@@ -12,3 +16,34 @@ task :dump_commit do
12
16
  puts "############ Commits since #{last_tag} ######"
13
17
  puts `git log --pretty=format:"- %s" #{last_tag}..HEAD`
14
18
  end
19
+
20
+ namespace :puppet_versions do
21
+ task :update do
22
+ require 'net/http'
23
+ require 'net/https'
24
+ require 'uri'
25
+
26
+ uri = URI.parse('https://forgeapi.puppet.com/private/versions/puppet-agent')
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+ http.use_ssl = uri.scheme == 'https'
29
+
30
+ request = Net::HTTP::Get.new(uri.request_uri)
31
+ response = http.request(request)
32
+ raise unless response.is_a?(Net::HTTPSuccess)
33
+
34
+ File.open(PUPPET_VERSIONS_PATH, 'wb:UTF-8') do |fd|
35
+ fd.write(response.body)
36
+ end
37
+ end
38
+
39
+ task :test do
40
+ Rake::Task['puppet_versions:update'].invoke
41
+
42
+ output = `git status --porcelain #{PUPPET_VERSIONS_PATH}`
43
+ unless output.strip.empty?
44
+ $stderr.puts "#{PUPPET_VERSIONS_PATH} is out of date."
45
+ $stderr.puts 'Run the puppet_versions:update task to update it and commit the changes.'
46
+ raise
47
+ end
48
+ end
49
+ end