rspec-puppet-facts 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 785242ffa008d8289d585447477c09447bda5d8b
4
- data.tar.gz: 0f112311ebf40c1b3272e6276d1341eb1aa51eec
3
+ metadata.gz: 601e63e42c9bd47dcfa7a4595770e4b2f75638f1
4
+ data.tar.gz: 86c454040c79b8dc060e197fa0ca2a810edafaa7
5
5
  SHA512:
6
- metadata.gz: 017a8282b68844be3988ec6b514bff9311c0fe953474ba8db434a5f83481f6adcf981c1a15b2a87f9bb2855655de9f0eaed03f5cac839dd10808c990682bd644
7
- data.tar.gz: e4f609545cfefa58d7b8779c1741f4db8ce8294a08bff965fc0a767895fa715d57f09b61ccb664bd5b78e2697aadc126772350b79a70202e3ac6ed1ab42a72eb
6
+ metadata.gz: fba02b4a1a05373922f6686bd606e328918f443e528934fd0b056c128d51f01c60a3fdb70c2db309f697cdcbe7a0a538eb8e3e0dee3558940311955977bc01d0
7
+ data.tar.gz: 62e87c175fd6280657886628b371b457cde4a6452f9558f931db0f83be3ceaecba05340e728f39003246a57e191c927b612ad64e6ad9be5384a86a62dbc7a67c
@@ -1,140 +1,158 @@
1
- ##2017-06-23 - Release 1.8.0
1
+ ## 2018-01-31 - Release 1.9.0
2
+ - Bumps facterdb requirement to 0.5.0
3
+ - Adds docs for using custom external facts
4
+ - hardwaremodel output changed on Windows with Facter 3.x
5
+ - Add additional rqspec tests
6
+ - Correctly select windows releases that contain spaces
7
+ - Facter < 3.4 does not return a proper release name for Windows 2016
8
+ - Strip 'Server' prefix from windows release name if present
9
+ - Downcase windows to match facter output
10
+ - Fix specs for current facterdb release
11
+ - Make version fallback testing independent of installed facter gem
12
+ - Add SPEC_FACTS_STRICT setting
13
+ - Cleanup README
14
+ - Add specific test to test minor version ahead of current facter version
15
+ - Update test to check for range in case facter version is not currently in FacterDB
16
+ - Step down through versions if the current version is not available
17
+ - Fix wrong example in README
18
+
19
+ ## 2017-06-23 - Release 1.8.0
2
20
  - Support specifying facter version
3
21
 
4
- ##2017-01-04 - Release 1.7.1
22
+ ## 2017-01-04 - Release 1.7.1
5
23
  - Ignore case when choosing H/W models
6
24
 
7
- ##2016-09-16 - Release 1.7.0
25
+ ## 2016-09-16 - Release 1.7.0
8
26
  - Support custom facts defined by spec_helper
9
27
 
10
- ##2016-05-19 - Release 1.6.1
28
+ ## 2016-05-19 - Release 1.6.1
11
29
  - Fix a bug where not all specified Ubuntu or OpenBSD were captured
12
30
 
13
- ##2016-05-17 - Release 1.6.0
31
+ ## 2016-05-17 - Release 1.6.0
14
32
  - Cleanup and refactor methods
15
33
  - Add YARD documentation
16
34
  - Refactor and fix rspec
17
35
  - Add the OS filter support
18
36
 
19
- ##2016-03-29 - Release 1.5.0
37
+ ## 2016-03-29 - Release 1.5.0
20
38
  - Add some Microsft Windows support
21
39
 
22
- ##2016-02-04 - Release 1.4.1
40
+ ## 2016-02-04 - Release 1.4.1
23
41
  - Add missing mcollective-client dependency
24
42
 
25
- ##2016-02-04 - Release 1.4.0
43
+ ## 2016-02-04 - Release 1.4.0
26
44
  - Dynamically set mco_version
27
45
 
28
- ##2015-11-12 - Release 1.3.0
46
+ ## 2015-11-12 - Release 1.3.0
29
47
  - Dynamically set rubysitedir
30
48
 
31
- ##2015-11-05 - Release 1.2.0
49
+ ## 2015-11-05 - Release 1.2.0
32
50
  - Requires facterdb 0.3.0
33
51
 
34
- ##2015-09-15 - Release 1.1.1
52
+ ## 2015-09-15 - Release 1.1.1
35
53
  - Fix OpenBSD support
36
54
 
37
- ##2015-09-09 - Release 1.1.0
55
+ ## 2015-09-09 - Release 1.1.0
38
56
  - Populate augeasversion, puppetversion and rubyversion
39
57
 
40
- ##2015-09-03 - Release 1.0.3
58
+ ## 2015-09-03 - Release 1.0.3
41
59
  - Fix FreeBSD support
42
60
 
43
- ##2015-08-31 - Release 1.0.2
61
+ ## 2015-08-31 - Release 1.0.2
44
62
  - Keys where not symbolized anymore since v1.0.0
45
63
 
46
- ##2015-08-29 - Release 1.0.1
64
+ ## 2015-08-29 - Release 1.0.1
47
65
  - Fix for old versions of Facter that does not provide operatingsystemmajrelease for some OSes
48
66
 
49
- ##2015-08-27 - Release 1.0.0
67
+ ## 2015-08-27 - Release 1.0.0
50
68
  - Use facterdb
51
69
 
52
- ##2015-08-10 - Release 0.12.0
70
+ ## 2015-08-10 - Release 0.12.0
53
71
  - Add Facter3 support
54
72
 
55
- ##2015-06-16 - Release 0.11.0
73
+ ## 2015-06-16 - Release 0.11.0
56
74
  - Add facts for OpenBSD 5.7
57
75
 
58
- ##2015-05-27 - Release 0.10.0
76
+ ## 2015-05-27 - Release 0.10.0
59
77
  - Add facts for Solaris 11
60
78
 
61
- ##2015-05-26 - Release 0.9.0
79
+ ## 2015-05-26 - Release 0.9.0
62
80
  - Add facts for Ubuntu 14.10
63
81
  - Add facts for Ubuntu 15.04
64
82
 
65
- ##2015-04-27 - Release 0.8.0
83
+ ## 2015-04-27 - Release 0.8.0
66
84
  - Remove support for Operating System minor release (causes problems with Ubuntu naming)
67
85
  - Add Gentoo support
68
86
 
69
- ##2015-04-26 - Release 0.7.0
87
+ ## 2015-04-26 - Release 0.7.0
70
88
  - Add support for Operating System minor release
71
89
  - Update README.md
72
90
 
73
- ##2015-03-06 - Release 0.6.0
91
+ ## 2015-03-06 - Release 0.6.0
74
92
  - Add facts for FreeBSD 9
75
93
 
76
- ##2015-03-06 - Release 0.5.0
94
+ ## 2015-03-06 - Release 0.5.0
77
95
  - Add facts for FreeBSD 10
78
96
 
79
- ##2015-02-22 - Release 0.4.1
97
+ ## 2015-02-22 - Release 0.4.1
80
98
  - Really useless release :-)
81
99
 
82
- ##2015-01-23 - Release 0.4.0
100
+ ## 2015-01-23 - Release 0.4.0
83
101
  - Add facts for facter 2.4
84
102
  - Format json with python's json.tool
85
103
  - Improve code coverage in unit tests
86
104
  - Test on more version of facter in travis matrix
87
105
 
88
- ##2015-01-05 - Release 0.3.3
106
+ ## 2015-01-05 - Release 0.3.3
89
107
  - Add facts for OpenSuse 12
90
108
  - Add facts for OpenSuse 13
91
109
 
92
- ##2015-01-04 - Release 0.3.2
110
+ ## 2015-01-04 - Release 0.3.2
93
111
  * Symbolize hash keys
94
112
 
95
- ##2015-01-03 - Release 0.3.1
113
+ ## 2015-01-03 - Release 0.3.1
96
114
  - Set fqdn to foo.example.com
97
115
  - Add json as runtime dependency
98
116
 
99
- ##2015-01-02 - Release 0.3.0
117
+ ## 2015-01-02 - Release 0.3.0
100
118
  - Use json output for facter
101
119
 
102
- ##2014-12-20 - Release 0.2.5
120
+ ## 2014-12-20 - Release 0.2.5
103
121
  - Don't fail if facts not found
104
122
 
105
- ##2014-12-20 - Release 0.2.4
123
+ ## 2014-12-20 - Release 0.2.4
106
124
  - Add facts for SLES 11
107
125
  - Add facts for Ubuntu 10.04
108
126
  - Fix for SLES 11 SP1
109
127
 
110
- ##2014-12-20 - Release 0.2.3
128
+ ## 2014-12-20 - Release 0.2.3
111
129
  - Add facts for ArchLinux
112
130
 
113
- ##2014-12-19 - Release 0.2.2
131
+ ## 2014-12-19 - Release 0.2.2
114
132
  - Fix some bugs
115
133
  - Add unit tests
116
134
 
117
- ##2014-12-19 - Release 0.2.1
135
+ ## 2014-12-19 - Release 0.2.1
118
136
  - Add facts for Debian 8
119
137
 
120
- ##2014-12-15 - Release 0.2.0
138
+ ## 2014-12-15 - Release 0.2.0
121
139
  - Add opts hash parameter
122
140
  - Tests only with x86_64 by default
123
141
 
124
- ##2014-12-12 - Release 0.1.4
142
+ ## 2014-12-12 - Release 0.1.4
125
143
  - Fix for Ubuntu
126
144
 
127
- ##2014-12-12 - Release 0.1.4
145
+ ## 2014-12-12 - Release 0.1.4
128
146
  - Fix for Fedora
129
147
 
130
- ##2014-12-12 - Release 0.1.3
148
+ ## 2014-12-12 - Release 0.1.3
131
149
  - Add facts for Fedora 19
132
150
 
133
- ##2014-12-12 - Release 0.1.2
151
+ ## 2014-12-12 - Release 0.1.2
134
152
  - Add facts for Scientific Linux
135
153
 
136
- ##2014-12-12 - Release 0.1.1
154
+ ## 2014-12-12 - Release 0.1.1
137
155
  - Add more facts
138
156
 
139
- ##2014-12-12 - First Release 0.1.0
157
+ ## 2014-12-12 - First Release 0.1.0
140
158
  - Initial release
data/README.md CHANGED
@@ -65,6 +65,7 @@ describe 'myclass::debian' do
65
65
  }
66
66
 
67
67
  on_supported_os(test_on).each do |os, facts|
68
+ let (:facts) { facts }
68
69
  it { is_expected.to compile.with_all_deps }
69
70
  end
70
71
  end
@@ -218,7 +219,7 @@ end
218
219
 
219
220
  ### Testing a function
220
221
 
221
- As with testing manifests, types, or providers, `on_supported_os` iteration simplifies your function unit tests.
222
+ As with testing manifests, types, or providers, `on_supported_os` iteration simplifies your function unit tests.
222
223
 
223
224
  **Specifying each operating system**:
224
225
 
@@ -274,7 +275,7 @@ describe 'myfunction' do
274
275
  end
275
276
  ```
276
277
 
277
- ### Adding custom fact values
278
+ ### Adding custom fact values
278
279
 
279
280
  By adding custom fact values, you can:
280
281
 
@@ -351,11 +352,75 @@ In addition to the static fact values shown in the previous examples, you can cr
351
352
  To do this, pass a lambda as the value for the custom fact. The lambda is passed the same values for operating system name and fact values that your tests are provided by `on_supported_os`.
352
353
 
353
354
  ```ruby
354
- add_custom_fact :root_home, lambda { |os,facts| "/tmp/#{facts['hostname']" }
355
+ add_custom_fact :root_home, lambda { |os,facts| "/tmp/#{facts['hostname']}" }
355
356
  ```
356
357
 
357
- Running your tests
358
- ------------------
358
+ ### Suppling Custom External Facts through FacterDB
359
+ 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.
361
+
362
+ The default facts are great for many things but there will be times when you need to have custom
363
+ fact sets that only make sense in your environment or might contain sensitive information.
364
+
365
+ To supply external facts to facterdb just set the `FACTERDB_SEARCH_PATHS` environment variable with one or more
366
+ paths to your facts.
367
+
368
+ When separating paths please use the default path separator character supported by your OS.
369
+ * Unix/Linux/OSX = `:`
370
+ * Windows = `;`
371
+
372
+ This means you will need to supply your own fact sets in addition to the ones contained in facterdb.
373
+ So each fact set you create must meet the following requirements:
374
+
375
+ 1. A JSON serialized file containing a single Hash of all the facts.
376
+ 2. The facts file must end in `.facts`
377
+ 3. Must be placed inside some directory. You can organize this directory however you like.
378
+
379
+ [Example file](https://github.com/camptocamp/facterdb/blob/master/facts/3.5/oraclelinux-5-i386.facts)
380
+
381
+ Facterdb is smart enough the search your supplied directories for files ending with '.facts'. You can even supply
382
+ multiple directories.
383
+
384
+ Example:
385
+
386
+ `FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts"`
387
+
388
+ or
389
+
390
+ `FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts:/tmp/custom_facts:/home/user1/custom_facts"`
391
+
392
+
393
+ You can create these files via many methods.
394
+
395
+ * `puppet facts | jq '.values' > /tmp/custom_facts/datacenter_a/2.4/os_x.facts` # must have jq command
396
+ * Via puppetdb queries
397
+ * hand crafted
398
+
399
+
400
+ Additionally you can skip the default FacterDB facts completely by setting the environment variable `FACTERDB_SKIP_DEFAULTDB`.
401
+ This will instruct facterdb to not look at its built-in facts which can be useful should you need to completely replace which facts are used.
402
+
403
+
404
+ Setting the variable `FACTERDB_SKIP_DEFAULTDB` to anything will disable the internal facts used by facterdb. You would most likely use this in combination
405
+ with the `FACTERDB_SEARCH_PATHS` environment variable.
406
+
407
+ Example:
408
+
409
+ ```
410
+ FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts:/tmp/custom_facts:/home/user1/custom_facts"
411
+ FACTERDB_SKIP_DEFAULTDB='yes'
412
+ ```
413
+
414
+ We recommend placing custom external facts under spec/fixtures/facts directory.
415
+
416
+ Additionally, if you plan on using these custom facts everytime you should set the following in your spec helper.
417
+
418
+ ```ruby
419
+ module_spec_dir = File.dirname(__FILE__)
420
+ custom_facts = File.join(module_spec_dir, 'fixtures', 'facts')
421
+ ENV['FACTERDB_SEARCH_PATHS'] = custom_facts
422
+ ```
423
+ ## Running your tests
359
424
 
360
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.
361
426
 
@@ -364,3 +429,5 @@ If you want to run the tests against the facts for specific operating systems, y
364
429
  ```bash
365
430
  SPEC_FACTS_OS='ubuntu-14' rake spec
366
431
  ```
432
+
433
+ When no facts are available for the specific facter/operating system combination, the library will fall back to facts from earlier versions of the requested operating system, to allow testing to continue when new versions of facter are released. Set `SPEC_FACTS_STRICT=yes` to instead trigger a failure.
data/Rakefile CHANGED
@@ -5,3 +5,10 @@ begin
5
5
  YARD::Rake::YardocTask.new
6
6
  rescue LoadError
7
7
  end
8
+
9
+ desc 'Produce Commit history since last tag'
10
+ task :dump_commit do
11
+ last_tag = `git describe --tags $(git rev-list --tags --max-count=1)`.chomp
12
+ puts "############ Commits since #{last_tag} ######"
13
+ puts `git log --pretty=format:"- %s" #{last_tag}..HEAD`
14
+ end
@@ -39,6 +39,15 @@ module RspecPuppetFacts
39
39
  end
40
40
 
41
41
  facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
42
+ db = FacterDB.get_facts({ :facterversion => facter_version_filter })
43
+
44
+ version = facterversion
45
+ while db.empty? && version !~ /\d+\.0\.\d+/
46
+ version = RspecPuppetFacts.down_facter_version(version)
47
+ facter_version_filter = RspecPuppetFacts.facter_version_to_filter(version)
48
+ db = FacterDB.get_facts({ :facterversion => facter_version_filter})
49
+ end
50
+
42
51
 
43
52
  filter = []
44
53
  opts[:supported_os].map do |os_sup|
@@ -46,18 +55,28 @@ module RspecPuppetFacts
46
55
  os_sup['operatingsystemrelease'].map do |operatingsystemmajrelease|
47
56
  opts[:hardwaremodels].each do |hardwaremodel|
48
57
 
58
+ os_release_filter = "/^#{operatingsystemmajrelease.split(' ')[0]}/"
49
59
  if os_sup['operatingsystem'] =~ /BSD/i
50
60
  hardwaremodel = 'amd64'
51
61
  elsif os_sup['operatingsystem'] =~ /Solaris/i
52
62
  hardwaremodel = 'i86pc'
53
63
  elsif os_sup['operatingsystem'] =~ /Windows/i
54
- hardwaremodel = 'x64'
64
+ hardwaremodel = version =~ /^[12]\./ ? 'x64' : 'x86_64'
65
+ os_sup['operatingsystem'] = os_sup['operatingsystem'].downcase
66
+ operatingsystemmajrelease = operatingsystemmajrelease[/\A(?:Server )?(.+)/i, 1]
67
+
68
+ # force quoting because windows releases can contain spaces
69
+ os_release_filter = "\"#{operatingsystemmajrelease}\""
70
+
71
+ if operatingsystemmajrelease == '2016' && Puppet::Util::Package.versioncmp(version, '3.4') < 0
72
+ os_release_filter = '/^10\\.0\\./'
73
+ end
55
74
  end
56
75
 
57
76
  filter << {
58
77
  :facterversion => facter_version_filter,
59
78
  :operatingsystem => os_sup['operatingsystem'],
60
- :operatingsystemrelease => "/^#{operatingsystemmajrelease.split(' ')[0]}/",
79
+ :operatingsystemrelease => os_release_filter,
61
80
  :hardwaremodel => hardwaremodel,
62
81
  }
63
82
  end
@@ -79,6 +98,14 @@ module RspecPuppetFacts
79
98
  return {}
80
99
  end
81
100
 
101
+ unless version == facterversion
102
+ if RspecPuppetFacts.spec_facts_strict?
103
+ raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion}, aborting"
104
+ else
105
+ RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion}, using v#{version} instead"
106
+ end
107
+ end
108
+
82
109
  os_facts_hash = {}
83
110
  received_facts.map do |facts|
84
111
  # Fix facter bug
@@ -86,6 +113,8 @@ module RspecPuppetFacts
86
113
  operatingsystemmajrelease = facts[:operatingsystemrelease].split('.')[0..1].join('.')
87
114
  elsif facts[:operatingsystem] == 'OpenBSD'
88
115
  operatingsystemmajrelease = facts[:operatingsystemrelease]
116
+ elsif facts[:operatingsystem] == 'windows' && facts[:operatingsystemrelease].start_with?('10.0.')
117
+ operatingsystemmajrelease = '2016'
89
118
  else
90
119
  if facts[:operatingsystemmajrelease].nil?
91
120
  operatingsystemmajrelease = facts[:operatingsystemrelease].split('.')[0]
@@ -161,6 +190,13 @@ module RspecPuppetFacts
161
190
  ENV['SPEC_FACTS_OS']
162
191
  end
163
192
 
193
+ # If SPEC_FACTS_STRICT is set to `yes`, RspecPuppetFacts will error on missing FacterDB entries, instead of warning & skipping the tests, or using an older facter version.
194
+ # @return [Boolean]
195
+ # @api private
196
+ def self.spec_facts_strict?
197
+ ENV['SPEC_FACTS_STRICT'] == 'yes'
198
+ end
199
+
164
200
  # These facts are common for all OS'es and will be
165
201
  # added to the facts retrieved from the FacterDB
166
202
  # @api private
@@ -238,4 +274,15 @@ module RspecPuppetFacts
238
274
  major, minor = version.split('.')
239
275
  "/\\A#{major}\\.#{minor}\\./"
240
276
  end
277
+ # Subtracts from the minor version passed and returns a string representing
278
+ # the next minor version down
279
+ # @return [String] next version below
280
+ # @param version [String] the Facter version
281
+ # @param minor_subtractor [int] the value which to subtract by
282
+ # @api private
283
+ def self.down_facter_version(version, minor_subtractor = 1)
284
+ major, minor, z = version.split('.')
285
+ minor = (minor.to_i - minor_subtractor).to_s
286
+ "#{major}.#{minor}.#{z}"
287
+ end
241
288
  end
@@ -2,6 +2,6 @@ module RspecPuppetFacts
2
2
  # This module contains the current version constant
3
3
  module Version
4
4
  # The current version of this gem
5
- STRING = '1.8.0'
5
+ STRING = '1.9.0'
6
6
  end
7
7
  end
@@ -28,6 +28,6 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency 'puppet'
29
29
  s.add_runtime_dependency 'json'
30
30
  s.add_runtime_dependency 'facter'
31
- s.add_runtime_dependency 'facterdb', '>= 0.3.0'
31
+ s.add_runtime_dependency 'facterdb', '>= 0.5.0'
32
32
  s.add_runtime_dependency 'mcollective-client'
33
33
  end
@@ -15,8 +15,8 @@
15
15
  {
16
16
  "operatingsystem": "Debian",
17
17
  "operatingsystemrelease": [
18
- "6",
19
- "7"
18
+ "7",
19
+ "8"
20
20
  ]
21
21
  },
22
22
  {
@@ -47,8 +47,8 @@ describe RspecPuppetFacts do
47
47
 
48
48
  it 'should return supported OS' do
49
49
  expect(subject.keys.sort).to eq %w(
50
- debian-6-x86_64
51
50
  debian-7-x86_64
51
+ debian-8-x86_64
52
52
  redhat-5-x86_64
53
53
  redhat-6-x86_64
54
54
  redhat-7-x86_64
@@ -100,8 +100,8 @@ describe RspecPuppetFacts do
100
100
  {
101
101
  "operatingsystem" => "Debian",
102
102
  "operatingsystemrelease" => [
103
- "6",
104
- "7"
103
+ "7",
104
+ "8",
105
105
  ]
106
106
  },
107
107
  {
@@ -126,8 +126,8 @@ describe RspecPuppetFacts do
126
126
 
127
127
  it 'should return supported OS' do
128
128
  expect(subject.keys.sort).to eq %w(
129
- debian-6-x86_64
130
129
  debian-7-x86_64
130
+ debian-8-x86_64
131
131
  redhat-5-x86_64
132
132
  redhat-6-x86_64
133
133
  )
@@ -150,29 +150,32 @@ describe RspecPuppetFacts do
150
150
  {
151
151
  "operatingsystem" => "Ubuntu",
152
152
  "operatingsystemrelease" => [
153
+ "12.04",
153
154
  "14.04",
154
- "14.10",
155
- "15.04",
156
- "15.10",
155
+ "16.04",
157
156
  ],
158
157
  },
159
158
  ],
160
159
  }
161
160
  )
162
161
  }
162
+
163
+ let(:expected_fact_sets) do
164
+ if Facter.version.to_f < 1.7
165
+ ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64']
166
+ else
167
+ ['ubuntu-12.04-x86_64', 'ubuntu-14.04-x86_64', 'ubuntu-16.04-x86_64']
168
+ end
169
+ end
170
+
163
171
  it 'should return a hash' do
164
172
  expect(subject.class).to eq Hash
165
173
  end
166
174
  it 'should have 4 elements' do
167
- expect(subject.size).to eq 4
175
+ expect(subject.size).to eq(expected_fact_sets.size)
168
176
  end
169
177
  it 'should return supported OS' do
170
- expect(subject.keys.sort).to eq [
171
- 'ubuntu-14.04-x86_64',
172
- 'ubuntu-14.10-x86_64',
173
- 'ubuntu-15.04-x86_64',
174
- 'ubuntu-15.10-x86_64',
175
- ]
178
+ expect(subject.keys.sort).to eq(expected_fact_sets)
176
179
  end
177
180
  end
178
181
 
@@ -188,6 +191,7 @@ describe RspecPuppetFacts do
188
191
  ],
189
192
  },
190
193
  ],
194
+ :facterversion => '2.4',
191
195
  }
192
196
  )
193
197
  }
@@ -216,6 +220,7 @@ describe RspecPuppetFacts do
216
220
  ],
217
221
  },
218
222
  ],
223
+ :facterversion => '2.4',
219
224
  }
220
225
  )
221
226
  }
@@ -260,31 +265,50 @@ describe RspecPuppetFacts do
260
265
  end
261
266
  end
262
267
 
263
- context 'When testing Windows 7', :if => Facter.version.to_f >= 2.4 do
264
- subject {
268
+ context 'When testing Windows', :if => Facter.version.to_f >= 2.4 do
269
+ subject do
265
270
  on_supported_os(
266
271
  {
267
272
  :supported_os => [
268
273
  {
269
- "operatingsystem" => "windows",
270
- "operatingsystemrelease" => [
271
- "7",
272
- ],
273
- },
274
+ 'operatingsystem' => 'Windows',
275
+ 'operatingsystemrelease' => release,
276
+ }
274
277
  ],
275
278
  }
276
279
  )
277
- }
278
- it 'should return a hash' do
279
- expect(subject.class).to eq Hash
280
280
  end
281
- it 'should have 1 elements' do
282
- expect(subject.size).to eq 1
281
+
282
+ context 'with a standard release' do
283
+ let(:release) { ['7'] }
284
+
285
+ it { is_expected.to be_a(Hash) }
286
+ it { is_expected.to have_attributes(:size => 1) }
287
+ it { is_expected.to include('windows-7-x64' => an_instance_of(Hash)) }
283
288
  end
284
- it 'should return supported OS' do
285
- expect(subject.keys.sort).to eq [
286
- 'windows-7-x64',
287
- ]
289
+
290
+ context 'with a revision release' do
291
+ let(:release) { ['2012 R2'] }
292
+
293
+ it { is_expected.to be_a(Hash) }
294
+ it { is_expected.to have_attributes(:size => 1) }
295
+ it { is_expected.to include('windows-2012 R2-x64' => an_instance_of(Hash)) }
296
+ end
297
+
298
+ context 'with a Server prefixed release' do
299
+ let(:release) { ['Server 2012'] }
300
+
301
+ it { is_expected.to be_a(Hash) }
302
+ it { is_expected.to have_attributes(:size => 1) }
303
+ it { is_expected.to include('windows-2012-x64' => an_instance_of(Hash)) }
304
+ end
305
+
306
+ context 'with a 2016 release' do
307
+ let(:release) { ['2016'] }
308
+
309
+ it { is_expected.to be_a(Hash) }
310
+ it { is_expected.to have_attributes(:size => 1) }
311
+ it { is_expected.to include('windows-2016-x64' => an_instance_of(Hash)) }
288
312
  end
289
313
  end
290
314
 
@@ -352,7 +376,8 @@ describe RspecPuppetFacts do
352
376
  {
353
377
  "operatingsystem" => "Archlinux",
354
378
  },
355
- ]
379
+ ],
380
+ :facterversion => '2.4',
356
381
  }
357
382
  )
358
383
  }
@@ -372,6 +397,9 @@ describe RspecPuppetFacts do
372
397
  end
373
398
 
374
399
  context 'Without a custom facterversion in the options hash' do
400
+ before(:each) do
401
+ allow(Facter).to receive(:version).and_return('2.4.5')
402
+ end
375
403
  subject do
376
404
  on_supported_os(
377
405
  supported_os: [
@@ -381,13 +409,45 @@ describe RspecPuppetFacts do
381
409
  end
382
410
 
383
411
  it 'returns facts from the loaded facter version' do
412
+ is_expected.to match(
413
+ 'centos-7-x86_64' => include(
414
+ facterversion: /\A2\.4\./
415
+ )
416
+ )
417
+ end
418
+ end
419
+
420
+ context 'With a version that is above the current gem' do
421
+ before(:each) do
422
+ allow(Facter).to receive(:version).and_return('2.4.5')
423
+ end
424
+
425
+ subject do
426
+ on_supported_os(
427
+ supported_os: [
428
+ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => %w[7] }
429
+ ],
430
+ facterversion: "2.6"
431
+ )
432
+ end
433
+
434
+ it 'returns facts from a facter version matching future and below' do
384
435
  major, minor = Facter.version.split('.')
385
436
  is_expected.to match(
386
437
  'centos-7-x86_64' => include(
387
- facterversion: /\A#{major}\.#{minor}\./
438
+ facterversion: /\A#{major}\.[#{minor}#{minor.to_i + 1}]\./
388
439
  )
389
440
  )
390
441
  end
442
+
443
+ context 'With SPEC_FACTS_STRICT set to `yes`' do
444
+ before(:each) do
445
+ allow(RspecPuppetFacts).to receive(:spec_facts_strict?).and_return(true)
446
+ end
447
+ it 'errors' do
448
+ expect { subject }.to raise_error ArgumentError, /No facts were found in the FacterDB.*aborting/
449
+ end
450
+ end
391
451
  end
392
452
 
393
453
  context 'With a custom facterversion (3.1) in the options hash' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet-facts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickaël Canévet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.3.0
131
+ version: 0.5.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.3.0
138
+ version: 0.5.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: mcollective-client
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  requirements: []
194
194
  rubyforge_project:
195
- rubygems_version: 2.5.2
195
+ rubygems_version: 2.5.2.2
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: Standard facts fixtures for Puppet