rspec-puppet 4.0.0 → 5.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
2
  SHA256:
3
- metadata.gz: 291e38ca7a66506f0137223f196936d5f2f96122edd1f5769d055a98c2370229
4
- data.tar.gz: cf627b9874f3aef7ae15b92d5f21283dfe4ceede9d0f6221be73f72d19c6803f
3
+ metadata.gz: 47a4537abaf6bf6d0c44a12e55802441f69eae576f813424c37da35b622b9f30
4
+ data.tar.gz: 1ad5e7c658add77b60c124ee49e727dccb3c499325e39ef74f2a9e71f684b1d4
5
5
  SHA512:
6
- metadata.gz: 7bbdc55d506fec8fdb26d206af5c56ad19a3a50dd4b0438853466513cbd0338087c3ca1dfff99146c530afa5194ac392fc121f2ee1aaccbb9d82b5cf6edf8e53
7
- data.tar.gz: 2d7ee94fb1fe726e8a326413bab9b8b08a200023be91693a7a208ade86de1e848e7c443fb2b6c8847ac75fe32cfd99ca2ff27601552543204ce5b4a802dfb86e
6
+ metadata.gz: 98a74e54868b5ac3711334e96d2b1cf757394a124ae468ae8a00b64b3ac8d16988d05c2cb5a085764235e4882bdbbe092f64f050bf129b06ae247cbb1a75b84f
7
+ data.tar.gz: 8911211fa08701f599fd47a9492a8ae4c77a0deaf83daef943a1d596baece421fc816b62f57534cf588603865382108af18af0d0db3eadd0b13ef2f77d32260f
data/CHANGELOG.md CHANGED
@@ -5,11 +5,42 @@ 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
+
21
+ ## [v4.0.2](https://github.com/puppetlabs/rspec-puppet/tree/v4.0.2) - 2023-12-05
22
+
23
+ [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v4.0.1...v4.0.2)
24
+
25
+ ### Fixed
26
+
27
+ - Revert "(maint) - fix rubocop" - Leading argument with delegation syntax not supported with ruby 2.7.0 [#94](https://github.com/puppetlabs/rspec-puppet/pull/94) ([jordanbreen28](https://github.com/jordanbreen28))
28
+ - Revert "(CAT-1235) - Rename to puppetlabs-rspec-puppet" [#92](https://github.com/puppetlabs/rspec-puppet/pull/92) ([jordanbreen28](https://github.com/jordanbreen28))
29
+
30
+ ## [v4.0.1](https://github.com/puppetlabs/rspec-puppet/tree/v4.0.1) - 2023-11-22
31
+
32
+ [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v4.0.0...v4.0.1)
33
+
34
+ ### Fixed
35
+
36
+ - (maint) - Add original owners [#90](https://github.com/puppetlabs/rspec-puppet/pull/90) ([jordanbreen28](https://github.com/jordanbreen28))
37
+
8
38
  ## [v4.0.0](https://github.com/puppetlabs/rspec-puppet/tree/v4.0.0) - 2023-10-09
9
39
 
10
40
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v3.0.0...v4.0.0)
11
41
 
12
42
  ### Changed
43
+
13
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))
14
45
  - Drop RSpec 2 & Ruby 1 compatiblity [#67](https://github.com/puppetlabs/rspec-puppet/pull/67) ([ekohl](https://github.com/ekohl))
15
46
  - Remove puppet applications support [#54](https://github.com/puppetlabs/rspec-puppet/pull/54) ([nabertrand](https://github.com/nabertrand))
@@ -27,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
27
58
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.12.0...v3.0.0.rc.1)
28
59
 
29
60
  ### Changed
61
+
30
62
  - (CONT-808) Ruby 3 / Puppet 8 Support [#48](https://github.com/puppetlabs/rspec-puppet/pull/48) ([chelnak](https://github.com/chelnak))
31
63
 
32
64
  ### Added
@@ -80,7 +112,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
80
112
 
81
113
  ## [v2.8.0](https://github.com/puppetlabs/rspec-puppet/tree/v2.8.0) - 2020-11-05
82
114
 
83
- [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)
84
120
 
85
121
  ## [v2.7.9](https://github.com/puppetlabs/rspec-puppet/tree/v2.7.9) - 2020-07-14
86
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
@@ -16,6 +16,8 @@
16
16
  * [Hiera integration](#hiera-integration)
17
17
  * [Producing coverage reports](#producing-coverage-reports)
18
18
  * [Related projects](#related-projects)
19
+ * [Development](#development)
20
+ * [License](#license)
19
21
 
20
22
  ## Installation
21
23
 
@@ -93,22 +95,6 @@ Hash | `{}` | any
93
95
  A hash of default trusted facts that should be used for all the tests
94
96
  (available in the manifests as the `$trusted` hash).
95
97
 
96
- #### trusted\_node\_data
97
- Type | Default | Puppet Version(s)
98
- ------- | ------- | -----------------
99
- Boolean | `false` | any
100
-
101
- Configures rspec-puppet to use the `$trusted` hash when compiling the
102
- catalogues.
103
-
104
- #### trusted\_server\_facts
105
- Type | Default | Puppet Version(s)
106
- ------- | ------- | -----------------
107
- Boolean | `false` | any
108
-
109
- Configures rspec-puppet to use the `$server_facts` hash when compiling the
110
- catalogues.
111
-
112
98
  #### confdir
113
99
  Type | Default | Puppet Version(s)
114
100
  ------ | --------------- | ------------------
@@ -902,66 +888,92 @@ end
902
888
 
903
889
  ## Hiera integration
904
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
+
905
895
  ### Configuration
906
896
 
907
- 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:
908
899
 
909
- ```ruby
910
- let(:hiera_config) { 'spec/fixtures/hiera/hiera.yaml' }
911
- 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'
912
910
  ```
913
911
 
914
- 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:
915
915
 
916
- spec/fixtures/hiera/hiera.yaml
917
- ```ruby
916
+ ```yaml
918
917
  ---
919
- :backends:
920
- - yaml
921
- :hierarchy:
922
- - test
923
- :yaml:
924
- :datadir: 'spec/fixtures/hiera'
918
+ # We will be using this data in later examples
919
+ message: 'Hello world!'
920
+ dummy:message2: 'foobar' # autoloaded parameter
925
921
  ```
926
922
 
927
- 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
+
928
925
  ```ruby
929
- ---
930
- ntpserver: ['ntp1.domain.com','ntpXX.domain.com']
931
- user:
932
- oneuser:
933
- shell: '/bin/bash'
934
- twouser:
935
- shell: '/sbin/nologin'
926
+ let(:hiera_config) { 'spec/fixtures/hiera/hiera-rspec.yaml' }
936
927
  ```
937
928
 
938
- ### 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:
939
930
 
940
931
  ```ruby
941
- ntpserver = hiera.lookup('ntpserver', nil, nil)
942
- let(:params) { 'ntpserver' => ntpserver }
932
+ RSpec.configure do |c|
933
+ c.hiera_config = 'spec/fixtures/hiera/hiera-rspec.yaml'
934
+ end
943
935
  ```
944
936
 
945
- ### Enabling hiera lookups
946
- If you just want to fetch values from hiera (e.g. because
947
- you're testing code that uses explicit hiera lookups) just specify
948
- 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).
949
944
 
950
945
  ```ruby
951
- RSpec.configure do |c|
952
- c.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
953
- 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
954
959
  ```
955
960
 
956
- spec/fixtures/hiera/hiera.yaml
957
- ```yaml
958
- ---
959
- :backends:
960
- - yaml
961
- :yaml:
962
- :datadir: spec/fixtures/hieradata
963
- :hierarchy:
964
- - 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
965
977
  ```
966
978
 
967
979
  **Please note:** In-module hiera data depends on having a correct metadata.json file. It is
@@ -1016,6 +1028,10 @@ If you run into an issue with this tool or would like to request a feature you c
1016
1028
 
1017
1029
  If you have problems getting this tool up and running, please contact Support.
1018
1030
 
1031
+ ## License
1032
+
1033
+ This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
1034
+
1019
1035
  ## Thank you
1020
1036
 
1021
1037
  Many thanks to the original author of rspec-puppet Tim Sharpe (@rodjek).
@@ -100,7 +100,7 @@ module RSpec::Puppet
100
100
  return func if func.func
101
101
 
102
102
  if Puppet::Parser::Functions.function(function_name)
103
- V3FunctionWrapper.new(function_name, scope.method("function_#{function_name}".intern))
103
+ V3FunctionWrapper.new(function_name, scope.method(:"function_#{function_name}"))
104
104
  end
105
105
  end
106
106
  end
@@ -303,7 +303,7 @@ module RSpec::Puppet
303
303
 
304
304
  # Add auto* (autorequire etc) if any
305
305
  if %i[before notify require subscribe].include?(type)
306
- func = "eachauto#{type}".to_sym
306
+ func = :"eachauto#{type}"
307
307
  if resource.resource_type.respond_to?(func)
308
308
  resource.resource_type.send(func) do |t, b|
309
309
  Array(resource.to_ral.instance_eval(&b)).each do |dep|
@@ -26,8 +26,8 @@ module RSpec::Puppet
26
26
  end
27
27
 
28
28
  module TypeMatchers
29
- def method_missing(method, ...)
30
- return RSpec::Puppet::TypeMatchers::CreateGeneric.new(method, ...) if method == :be_valid_type
29
+ def method_missing(method, *args, &block)
30
+ return RSpec::Puppet::TypeMatchers::CreateGeneric.new(method, *args, &block) if method == :be_valid_type
31
31
 
32
32
  super
33
33
  end
@@ -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.
@@ -123,7 +123,7 @@ module RSpec::Puppet
123
123
  param = param.to_sym
124
124
  if attr_type == :feature
125
125
  baddies.push(param) unless type.provider_feature(param)
126
- elsif !type.send("valid#{attr_type}?".to_sym, param)
126
+ elsif !type.send(:"valid#{attr_type}?", param)
127
127
  baddies.push(param)
128
128
  end
129
129
  end
@@ -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.0'
4
+ VERSION = '5.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-09 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
@@ -26,10 +26,7 @@ dependencies:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.0'
29
- description: |2
30
- RSpec tests for your Puppet manifests.
31
- Note: Support for this gem has been moved under a new namespace and as such any future updates from
32
- the Puppet team will be released as `puppetlabs-rspec-puppet`.
29
+ description: " RSpec tests for your Puppet manifests.\n"
33
30
  email:
34
31
  - tim@sharpe.id.au
35
32
  - modules-team@puppet.com
@@ -39,6 +36,7 @@ extensions: []
39
36
  extra_rdoc_files: []
40
37
  files:
41
38
  - CHANGELOG.md
39
+ - LICENSE
42
40
  - README.md
43
41
  - bin/rspec-puppet-init
44
42
  - lib/rspec-puppet.rb
@@ -83,8 +81,7 @@ files:
83
81
  homepage: https://github.com/puppetlabs/rspec-puppet/
84
82
  licenses:
85
83
  - MIT
86
- metadata:
87
- rubygems_mfa_required: 'true'
84
+ metadata: {}
88
85
  post_install_message:
89
86
  rdoc_options: []
90
87
  require_paths: