rspec-puppet 4.0.2 → 5.0.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
  SHA256:
3
- metadata.gz: 426a4ee05db6fe1e2ca9fea2e6bb5867ee07e9a07026c1b88d7f58d5466883e5
4
- data.tar.gz: dc491e62b7b7228ae76e292ea5b387b279a8791551f81e689a1fc1c96af3cbb5
3
+ metadata.gz: 47a4537abaf6bf6d0c44a12e55802441f69eae576f813424c37da35b622b9f30
4
+ data.tar.gz: 1ad5e7c658add77b60c124ee49e727dccb3c499325e39ef74f2a9e71f684b1d4
5
5
  SHA512:
6
- metadata.gz: 3e0ea7226522dc683e27d1beac2337b4d3ec6ad448d5d95608c5879a5175f6e62ada4ee6ee81c8ab1345cd4265cdaa3cd509a80173218a1998d146546caba7e0
7
- data.tar.gz: cdfdbf4bfb0551b3f4b8465a1278c93cef7707fd2284a5629dc6fe71f7846bbcec5c12396efb755da2a092521cf71a10b9f51794af7a4d650053913905c3897d
6
+ metadata.gz: 98a74e54868b5ac3711334e96d2b1cf757394a124ae468ae8a00b64b3ac8d16988d05c2cb5a085764235e4882bdbbe092f64f050bf129b06ae247cbb1a75b84f
7
+ data.tar.gz: 8911211fa08701f599fd47a9492a8ae4c77a0deaf83daef943a1d596baece421fc816b62f57534cf588603865382108af18af0d0db3eadd0b13ef2f77d32260f
data/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
 
6
6
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
7
7
 
8
+ ## [v5.0.0](https://github.com/puppetlabs/rspec-puppet/tree/v5.0.0) - 2024-09-06
9
+
10
+ [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v4.0.2...v5.0.0)
11
+
12
+ ### Changed
13
+
14
+ - Unwrap sensitive values in error messages [#42](https://github.com/puppetlabs/rspec-puppet/pull/42) ([smortex](https://github.com/smortex))
15
+
16
+ ### Fixed
17
+
18
+ - server_facts: Switch from legacy to structured facts [#127](https://github.com/puppetlabs/rspec-puppet/pull/127) ([bastelfreak](https://github.com/bastelfreak))
19
+ - (bug) - Add license file to built gem [#108](https://github.com/puppetlabs/rspec-puppet/pull/108) ([jordanbreen28](https://github.com/jordanbreen28))
20
+
8
21
  ## [v4.0.2](https://github.com/puppetlabs/rspec-puppet/tree/v4.0.2) - 2023-12-05
9
22
 
10
23
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v4.0.1...v4.0.2)
@@ -27,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
27
40
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v3.0.0...v4.0.0)
28
41
 
29
42
  ### Changed
43
+
30
44
  - (CAT-1226) - Remove Compatibility for Puppet 7.10 and below [#73](https://github.com/puppetlabs/rspec-puppet/pull/73) ([jordanbreen28](https://github.com/jordanbreen28))
31
45
  - Drop RSpec 2 & Ruby 1 compatiblity [#67](https://github.com/puppetlabs/rspec-puppet/pull/67) ([ekohl](https://github.com/ekohl))
32
46
  - Remove puppet applications support [#54](https://github.com/puppetlabs/rspec-puppet/pull/54) ([nabertrand](https://github.com/nabertrand))
@@ -44,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
44
58
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.12.0...v3.0.0.rc.1)
45
59
 
46
60
  ### Changed
61
+
47
62
  - (CONT-808) Ruby 3 / Puppet 8 Support [#48](https://github.com/puppetlabs/rspec-puppet/pull/48) ([chelnak](https://github.com/chelnak))
48
63
 
49
64
  ### Added
@@ -97,7 +112,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
97
112
 
98
113
  ## [v2.8.0](https://github.com/puppetlabs/rspec-puppet/tree/v2.8.0) - 2020-11-05
99
114
 
100
- [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.7.9...v2.8.0)
115
+ [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.7.10...v2.8.0)
116
+
117
+ ## [v2.7.10](https://github.com/puppetlabs/rspec-puppet/tree/v2.7.10) - 2020-07-15
118
+
119
+ [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.7.9...v2.7.10)
101
120
 
102
121
  ## [v2.7.9](https://github.com/puppetlabs/rspec-puppet/tree/v2.7.9) - 2020-07-14
103
122
 
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tim Sharpe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -888,66 +888,92 @@ end
888
888
 
889
889
  ## Hiera integration
890
890
 
891
+ At some point, you might want to make use of Hiera to bring in custom parameters for your class tests. In this section, we will
892
+ provide you with basic guidance to setup Hiera implementation within rspec testing. For more information on Hiera, you should
893
+ check our official [documentation](https://www.puppet.com/docs/puppet/latest/hiera.html).
894
+
891
895
  ### Configuration
892
896
 
893
- Set the hiera config symbol properly in your spec files:
897
+ The first step is to create the general hiera configuration file. Since we want this to be exclusive for testing, we recommend creating
898
+ it inside your spec folder. Something along the lines of `spec/fixtures/hiera/hiera-rspec.yaml`. It should look something like this:
894
899
 
895
- ```ruby
896
- let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
897
- hiera = Hiera.new(:config => 'spec/fixtures/hiera/hiera.yaml')
900
+ ```yaml
901
+ ---
902
+ version: 5
903
+ defaults: # Used for any hierarchy level that omits these keys.
904
+ datadir: data # This path is relative to hiera.yaml's directory.
905
+ data_hash: yaml_data # Use the built-in YAML backend.
906
+
907
+ hierarchy:
908
+ - name: 'rspec'
909
+ path: 'rspec-data.yaml'
898
910
  ```
899
911
 
900
- Create your spec hiera files
912
+ It is often recommended to use dummy data during testing to avoid real values from being entangled. In order to create
913
+ these values, we will need a new file containing this data exclusively, normally existing within a subfolder called `data`, ending up with
914
+ `spec/fixtures/hiera/data/rspec-data.yaml`. Here is an example of its contents:
901
915
 
902
- spec/fixtures/hiera/hiera.yaml
903
- ```ruby
916
+ ```yaml
904
917
  ---
905
- :backends:
906
- - yaml
907
- :hierarchy:
908
- - test
909
- :yaml:
910
- :datadir: 'spec/fixtures/hiera'
918
+ # We will be using this data in later examples
919
+ message: 'Hello world!'
920
+ dummy:message2: 'foobar' # autoloaded parameter
911
921
  ```
912
922
 
913
- spec/fixtures/hiera/test.yaml
923
+ Finally, we make the target class spec file load the Hiera config, at which point we will be able to freely access it:
924
+
914
925
  ```ruby
915
- ---
916
- ntpserver: ['ntp1.domain.com','ntpXX.domain.com']
917
- user:
918
- oneuser:
919
- shell: '/bin/bash'
920
- twouser:
921
- shell: '/sbin/nologin'
926
+ let(:hiera_config) { 'spec/fixtures/hiera/hiera-rspec.yaml' }
922
927
  ```
923
928
 
924
- ### Use hiera in your tests
929
+ Or alternatively, you could load the hiera configuration in the spec_helper to ensure it is available through all test files:
925
930
 
926
931
  ```ruby
927
- ntpserver = hiera.lookup('ntpserver', nil, nil)
928
- let(:params) { 'ntpserver' => ntpserver }
932
+ RSpec.configure do |c|
933
+ c.hiera_config = 'spec/fixtures/hiera/hiera-rspec.yaml'
934
+ end
929
935
  ```
930
936
 
931
- ### Enabling hiera lookups
932
- If you just want to fetch values from hiera (e.g. because
933
- you're testing code that uses explicit hiera lookups) just specify
934
- the path to the hiera config in your `spec_helper.rb`
937
+ #### Test usage examples
938
+
939
+ Unlike with Hiera 3, Hiera 5 comes packaged with our Puppet agent and runs during Puppet runtime. This means that it is not really possible to
940
+ call the lookup function in the same way it previously worked. However, you can still test its functionality via dummy class instantiation:
941
+
942
+ The following test creates a dummny class that uses the lookup function within it. This should allow you to confirm that the lookup() function
943
+ works correctly (remember that this test uses your custom hiera parameters, and not your real ones).
935
944
 
936
945
  ```ruby
937
- RSpec.configure do |c|
938
- c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
939
- end
946
+ context 'dummy hiera test is implemented' do
947
+ let(:pre_condition) do
948
+ "class dummy($message) { }
949
+ class { 'dummy': message => lookup('message') }"
950
+ end
951
+ let(:hiera_config) { 'spec/fixtures/hiera/hiera-rspec.yaml' } # Only needed if the config has not been established in spec_helper
952
+
953
+ it { is_expected.to compile }
954
+
955
+ it 'loads ntpserver from Hiera' do
956
+ is_expected.to contain_class('dummy').with_message('Hello world!')
957
+ end
958
+ end
940
959
  ```
941
960
 
942
- spec/fixtures/hiera/hiera.yaml
943
- ```yaml
944
- ---
945
- :backends:
946
- - yaml
947
- :yaml:
948
- :datadir: spec/fixtures/hieradata
949
- :hierarchy:
950
- - common
961
+ The next test ensures that autoloaded parameters work correctly within your classes:
962
+
963
+ ```ruby
964
+ context 'dummy hiera test is implemented a second time' do
965
+ let(:pre_condition) do
966
+ "class dummy($message2) { }
967
+ include dummy"
968
+ end
969
+ let(:hiera_config) { 'spec/fixtures/hiera/hiera-rspec.yaml' } # Only needed if the config has not been established in spec_helper
970
+
971
+ it { is_expected.to compile }
972
+
973
+ it 'loads ntpserver from Hiera' do
974
+ is_expected.to contain_class('dummy').with_message2('foobar')
975
+ end
976
+ end
951
977
  ```
952
978
 
953
979
  **Please note:** In-module hiera data depends on having a correct metadata.json file. It is
@@ -28,6 +28,8 @@ module RSpec::Puppet
28
28
  actual = resource[@parameter]
29
29
  expected = @value
30
30
 
31
+ actual = RSpec::Puppet::Sensitive.new(actual.unwrap) if actual.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
32
+
31
33
  # Puppet flattens an array with a single value into just the value and
32
34
  # this can cause confusion when testing as people expect when you put
33
35
  # an array in, you'll get an array out.
@@ -24,6 +24,11 @@ module RSpec::Puppet
24
24
  "Sensitive(#{@value.inspect})"
25
25
  end
26
26
 
27
+ # @return the unwrapped value (needed to show diff)
28
+ def to_s
29
+ inspect
30
+ end
31
+
27
32
  # Check for equality with another value.
28
33
  # If compared to Puppet Sensitive type, it compares the wrapped values.
29
34
 
@@ -301,8 +301,7 @@ module RSpec::Puppet
301
301
  server_facts['serverversion'] = Puppet.version.to_s
302
302
 
303
303
  # And then add the server name and IP
304
- { 'servername' => 'fqdn',
305
- 'serverip' => 'ipaddress' }.each do |var, fact|
304
+ { 'servername' => 'networking.fqdn', 'serverip' => 'networking.ip' }.each do |var, fact|
306
305
  if (value = Puppet.runtime[:facter].value(fact))
307
306
  server_facts[var] = value
308
307
  else
@@ -311,8 +310,8 @@ module RSpec::Puppet
311
310
  end
312
311
 
313
312
  if server_facts['servername'].nil?
314
- host = Puppet.runtime[:facter].value(:hostname)
315
- server_facts['servername'] = if (domain = Puppet.runtime[:facter].value(:domain))
313
+ host = Puppet.runtime[:facter].value('networking.hostname')
314
+ server_facts['servername'] = if (domain = Puppet.runtime[:facter].value('networking.domain'))
316
315
  [host, domain].join('.')
317
316
  else
318
317
  host
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecPuppet
4
- VERSION = '4.0.2'
4
+ VERSION = '5.0.0'
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
8
8
  - Puppet, Inc.
9
9
  - Community Contributors
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-12-05 00:00:00.000000000 Z
13
+ date: 2024-09-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -36,6 +36,7 @@ extensions: []
36
36
  extra_rdoc_files: []
37
37
  files:
38
38
  - CHANGELOG.md
39
+ - LICENSE
39
40
  - README.md
40
41
  - bin/rspec-puppet-init
41
42
  - lib/rspec-puppet.rb
@@ -80,9 +81,8 @@ files:
80
81
  homepage: https://github.com/puppetlabs/rspec-puppet/
81
82
  licenses:
82
83
  - MIT
83
- metadata:
84
- rubygems_mfa_required: 'true'
85
- post_install_message:
84
+ metadata: {}
85
+ post_install_message:
86
86
  rdoc_options: []
87
87
  require_paths:
88
88
  - lib
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubygems_version: 3.1.6
101
- signing_key:
101
+ signing_key:
102
102
  specification_version: 4
103
103
  summary: RSpec tests for your Puppet manifests
104
104
  test_files: []