rspec-puppet 4.0.1 → 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: 9cd03a236a8ecccba9131563b0eb1cba1acbf1527fc3fa3a26f73aa0ed71b8bf
4
- data.tar.gz: 26e3dd952e69e4481ab11ea9adc03a9df5b7a5a6b1dd968cac08e1cd02665f30
3
+ metadata.gz: 47a4537abaf6bf6d0c44a12e55802441f69eae576f813424c37da35b622b9f30
4
+ data.tar.gz: 1ad5e7c658add77b60c124ee49e727dccb3c499325e39ef74f2a9e71f684b1d4
5
5
  SHA512:
6
- metadata.gz: 9e4e98146c015657bf6507b08aed32d4f3dc24f44e9b04539054465df4025c5dc737d7b42e261553cdcbf0a75b84812c739243a41514689395d7505571f23ea5
7
- data.tar.gz: de6e30c989030a40a781fdadefcb88b3b70a7bcb3372ec869f1ddc03d7b00ec50fd4f9cbfc1450c00e96ef5d9eb061244938d1ff629df654f9aeb595e004573c
6
+ metadata.gz: 98a74e54868b5ac3711334e96d2b1cf757394a124ae468ae8a00b64b3ac8d16988d05c2cb5a085764235e4882bdbbe092f64f050bf129b06ae247cbb1a75b84f
7
+ data.tar.gz: 8911211fa08701f599fd47a9492a8ae4c77a0deaf83daef943a1d596baece421fc816b62f57534cf588603865382108af18af0d0db3eadd0b13ef2f77d32260f
data/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ 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
+
8
30
  ## [v4.0.1](https://github.com/puppetlabs/rspec-puppet/tree/v4.0.1) - 2023-11-22
9
31
 
10
32
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v4.0.0...v4.0.1)
@@ -18,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
18
40
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v3.0.0...v4.0.0)
19
41
 
20
42
  ### Changed
43
+
21
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))
22
45
  - Drop RSpec 2 & Ruby 1 compatiblity [#67](https://github.com/puppetlabs/rspec-puppet/pull/67) ([ekohl](https://github.com/ekohl))
23
46
  - Remove puppet applications support [#54](https://github.com/puppetlabs/rspec-puppet/pull/54) ([nabertrand](https://github.com/nabertrand))
@@ -35,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
35
58
  [Full Changelog](https://github.com/puppetlabs/rspec-puppet/compare/v2.12.0...v3.0.0.rc.1)
36
59
 
37
60
  ### Changed
61
+
38
62
  - (CONT-808) Ruby 3 / Puppet 8 Support [#48](https://github.com/puppetlabs/rspec-puppet/pull/48) ([chelnak](https://github.com/chelnak))
39
63
 
40
64
  ### Added
@@ -88,7 +112,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88
112
 
89
113
  ## [v2.8.0](https://github.com/puppetlabs/rspec-puppet/tree/v2.8.0) - 2020-11-05
90
114
 
91
- [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)
92
120
 
93
121
  ## [v2.7.9](https://github.com/puppetlabs/rspec-puppet/tree/v2.7.9) - 2020-07-14
94
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
@@ -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.1'
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.1
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-11-22 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,8 +81,7 @@ files:
80
81
  homepage: https://github.com/puppetlabs/rspec-puppet/
81
82
  licenses:
82
83
  - MIT
83
- metadata:
84
- rubygems_mfa_required: 'true'
84
+ metadata: {}
85
85
  post_install_message:
86
86
  rdoc_options: []
87
87
  require_paths: