puppetlabs_spec_helper 7.3.1 → 8.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: 139276e5721239e25b613a18b8c96ea93235f9717dfea2522f3c597ca4f98996
4
- data.tar.gz: 8c8c252953c527d1da8add48267246261c27bbe30c7186e7ab4d960e0840665e
3
+ metadata.gz: f6e4f387a2e5ca2ffdaf54834dba59bddbc793d099a32844e406d6bcf1906345
4
+ data.tar.gz: a5d37de14da8a64547e4dd3a40a649b0eac66d7c73d7d2aff561dafc569c3299
5
5
  SHA512:
6
- metadata.gz: 2fd1740c635a65b214e9fa83f639d519ba4569b45862ab0a6f7cd5b60fa3de9c1fb0f099ad45b2fe91b85eee1116359e02cb6dbc5ce4e8477fc6f1e3c280a3df
7
- data.tar.gz: cc1162520fb1db194506d43502f7b6cd395577c4312bc5c737c2272ac8aefbaf5767cfd7eb414d465036be79eb2ac2bd30a49e108f677aee254bbcdac30dd161
6
+ metadata.gz: 0c5d1c7bc0f185b696570c75bccab95349681e09bc213e91f5ffeb855d462a4e98c30cc3049ccb44cb083936438ccc386bcee6096a92f2ff8e8eb48c1fc8478e
7
+ data.tar.gz: 7da07d5ea2f8c277944bb803765fe2a39695c38ee3342bf0da34fdefce301e20edce6d9a201337db7cbbb14536ac2f9894cb50925f439a6214f9aa1a35669b97
data/.rubocop.yml CHANGED
@@ -1,18 +1,8 @@
1
+ ---
1
2
  inherit_from: .rubocop_todo.yml
2
3
 
3
- require:
4
- - rubocop-performance
5
- - rubocop-rspec
6
-
7
- AllCops:
8
- Exclude:
9
- - Gemfile
10
- - Rakefile
11
- - spec/fixtures/**/*
12
- - vendor/bundle/**/*
13
- NewCops: enable
14
- SuggestExtensions: false
15
- TargetRubyVersion: '2.7'
4
+ inherit_gem:
5
+ voxpupuli-rubocop: rubocop.yml
16
6
 
17
7
  # Disabled
18
8
  Style/ClassAndModuleChildren:
data/README.md CHANGED
@@ -216,6 +216,17 @@ When specifying the repo source of the fixture you have a few options as to whic
216
216
  * `ref` and `branch` can be used together to get a specific revision on a specific branch
217
217
  * Top level `defaults` option could be used to set global options
218
218
 
219
+ Using Forge Authorization
220
+ -----------------
221
+
222
+ In order to perform forge operations which require authorization, such as installing premium modules, you can export your forge api key as an environment variable in your terminal.
223
+
224
+ ```bash
225
+ FORGE_API_KEY='your_api_key'
226
+ ```
227
+
228
+ puppetlabs_spec_helper will then automatically append this key to all `puppet module install` requests when running `rake spec_prep`.
229
+
219
230
  Fixtures Examples
220
231
  -----------------
221
232
  Basic fixtures that will symlink `spec/fixtures/modules/my_modules` to the
@@ -31,7 +31,7 @@ if ENV['SIMPLECOV'] == 'yes'
31
31
 
32
32
  SimpleCov.formatters = [
33
33
  SimpleCov::Formatter::HTMLFormatter,
34
- SimpleCov::Formatter::Console
34
+ SimpleCov::Formatter::Console,
35
35
  ]
36
36
 
37
37
  begin
@@ -39,7 +39,7 @@ module PuppetlabsSpec
39
39
  # exposed hack.
40
40
  return nil unless Puppet::Parser::Functions.function(name)
41
41
 
42
- scope.method("function_#{name}".to_sym)
42
+ scope.method(:"function_#{name}")
43
43
  end
44
44
  module_function :function_method
45
45
  end
@@ -121,35 +121,6 @@ task :parallel_spec_standalone do |_t, args|
121
121
  end
122
122
  end
123
123
 
124
- desc 'Build puppet module package'
125
- task :build do
126
- Rake::Task['build:pdk'].invoke
127
- end
128
-
129
- namespace :build do
130
- desc 'Build Puppet module with PDK'
131
- task :pdk do
132
- require 'pdk/util'
133
- require 'pdk/module/build'
134
-
135
- path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
136
- puts "Module built: #{path}"
137
- rescue LoadError
138
- _ = `pdk --version`
139
- unless $CHILD_STATUS.success?
140
- warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
141
- abort
142
- end
143
-
144
- system('pdk build --force')
145
- end
146
- end
147
-
148
- desc 'Clean a built module package'
149
- task :clean do
150
- FileUtils.rm_rf('pkg/')
151
- end
152
-
153
124
  require 'puppet-lint/tasks/puppet-lint'
154
125
  # Must clear as it will not override the existing puppet-lint rake task since we require to import for
155
126
  # the PuppetLint::RakeTask
@@ -170,7 +141,6 @@ puppet_lint_disable_checks = %w[
170
141
  80chars
171
142
  140chars
172
143
  class_inherits_from_params_class
173
- class_parameter_defaults
174
144
  disable_autoloader_layout
175
145
  documentation
176
146
  single_quote_string_with_variables
@@ -381,16 +351,16 @@ def create_gch_task(changelog_user = nil, changelog_project = nil, changelog_sin
381
351
  config.configure_sections = {
382
352
  'Changed' => {
383
353
  'prefix' => '### Changed',
384
- 'labels' => ['backwards-incompatible']
354
+ 'labels' => ['backwards-incompatible'],
385
355
  },
386
356
  'Added' => {
387
357
  'prefix' => '### Added',
388
- 'labels' => %w[feature enhancement]
358
+ 'labels' => %w[feature enhancement],
389
359
  },
390
360
  'Fixed' => {
391
361
  'prefix' => '### Fixed',
392
- 'labels' => ['bugfix']
393
- }
362
+ 'labels' => ['bugfix'],
363
+ },
394
364
  }
395
365
  end
396
366
  else
@@ -9,12 +9,12 @@ module PuppetlabsSpecHelper
9
9
  DEFAULT_IGNORED = [
10
10
  '/.git/',
11
11
  '/.bundle/',
12
- '/vendor/'
12
+ '/vendor/',
13
13
  ].freeze
14
14
 
15
15
  IGNORE_LIST_FILES = [
16
16
  '.pdkignore',
17
- '.gitignore'
17
+ '.gitignore',
18
18
  ].freeze
19
19
 
20
20
  def check(dir = Dir.pwd)
@@ -106,7 +106,7 @@ module PuppetlabsSpecHelper
106
106
  end
107
107
 
108
108
  fixtures = fixtures['fixtures']
109
- fixtures['symlinks'] = fixtures['symlinks'].nil? || fixtures['symlinks'].empty? ? auto_symlink : auto_symlink.merge!(fixtures['symlinks'])
109
+ fixtures['symlinks'] = (fixtures['symlinks'].nil? || fixtures['symlinks'].empty?) ? auto_symlink : auto_symlink.merge!(fixtures['symlinks'])
110
110
 
111
111
  result = {}
112
112
  if fixtures.include?(category) && !fixtures[category].nil?
@@ -317,7 +317,7 @@ module PuppetlabsSpecHelper
317
317
  end
318
318
  end
319
319
  # wait for all the threads to finish
320
- items.each { |_remote, opts| opts[:thread].join }
320
+ items.each_value { |opts| opts[:thread].join }
321
321
  end
322
322
 
323
323
  # @param target [String] - the target directory
@@ -379,6 +379,9 @@ module PuppetlabsSpecHelper
379
379
  flags = " #{opts['flags']}" if opts['flags']
380
380
  end
381
381
 
382
+ forge_token = ENV.fetch('FORGE_API_KEY', nil)
383
+ flags += " --forge_authorization \"Bearer #{forge_token}\"" if forge_token
384
+
382
385
  return false if File.directory?(target) && (ref.empty? || opts['ref'] == module_version(target))
383
386
 
384
387
  # The PMT cannot handle multi threaded runs due to cache directory collisons
@@ -427,12 +430,12 @@ end
427
430
 
428
431
  desc 'Clean up the fixtures directory'
429
432
  task :spec_clean do
430
- repositories.each do |_remote, opts|
433
+ repositories.each_value do |opts|
431
434
  target = opts['target']
432
435
  FileUtils.rm_rf(target)
433
436
  end
434
437
 
435
- forge_modules.each do |_remote, opts|
438
+ forge_modules.each_value do |opts|
436
439
  target = opts['target']
437
440
  FileUtils.rm_rf(target)
438
441
  end
@@ -446,7 +449,7 @@ end
446
449
 
447
450
  desc 'Clean up any fixture symlinks'
448
451
  task :spec_clean_symlinks do
449
- fixtures('symlinks').each do |_source, opts|
452
+ fixtures('symlinks').each_value do |opts|
450
453
  target = opts['target']
451
454
  FileUtils.rm_f(target)
452
455
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PuppetlabsSpecHelper
4
- VERSION = '7.3.1'
4
+ VERSION = '8.0.0'
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,7 @@ if ENV['COVERAGE'] == 'yes'
10
10
 
11
11
  SimpleCov.formatters = [
12
12
  SimpleCov::Formatter::HTMLFormatter,
13
- SimpleCov::Formatter::Console
13
+ SimpleCov::Formatter::Console,
14
14
  ]
15
15
 
16
16
  SimpleCov.start do
@@ -31,7 +31,7 @@ describe 'rake check:symlinks', type: :task do
31
31
  let(:test_files) do
32
32
  [
33
33
  File.join(Dir.pwd, 'files', 'a_file.pp'),
34
- File.join(Dir.pwd, 'files', 'another_file.pp')
34
+ File.join(Dir.pwd, 'files', 'another_file.pp'),
35
35
  ]
36
36
  end
37
37
 
@@ -43,13 +43,13 @@ describe 'rake check:symlinks', type: :task do
43
43
  context 'when there is a symlink present' do
44
44
  let(:test_files) do
45
45
  [
46
- File.join(Dir.pwd, 'files', 'a_file.pp')
46
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
47
47
  ]
48
48
  end
49
49
 
50
50
  let(:symlinks) do
51
51
  {
52
- File.join(Dir.pwd, 'files', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
52
+ File.join(Dir.pwd, 'files', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
53
53
  }
54
54
  end
55
55
 
@@ -63,13 +63,13 @@ describe 'rake check:symlinks', type: :task do
63
63
  context 'when there are symlinks under .git/' do
64
64
  let(:test_files) do
65
65
  [
66
- File.join(Dir.pwd, 'files', 'a_file.pp')
66
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
67
67
  ]
68
68
  end
69
69
 
70
70
  let(:symlinks) do
71
71
  {
72
- File.join(Dir.pwd, '.git', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
72
+ File.join(Dir.pwd, '.git', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
73
73
  }
74
74
  end
75
75
 
@@ -81,13 +81,13 @@ describe 'rake check:symlinks', type: :task do
81
81
  context 'when there are symlinks under .bundle/' do
82
82
  let(:test_files) do
83
83
  [
84
- File.join(Dir.pwd, 'files', 'a_file.pp')
84
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
85
85
  ]
86
86
  end
87
87
 
88
88
  let(:symlinks) do
89
89
  {
90
- File.join(Dir.pwd, '.bundle', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
90
+ File.join(Dir.pwd, '.bundle', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
91
91
  }
92
92
  end
93
93
 
@@ -99,13 +99,13 @@ describe 'rake check:symlinks', type: :task do
99
99
  context 'when there are symlinks under vendor/' do
100
100
  let(:test_files) do
101
101
  [
102
- File.join(Dir.pwd, 'files', 'a_file.pp')
102
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
103
103
  ]
104
104
  end
105
105
 
106
106
  let(:symlinks) do
107
107
  {
108
- File.join(Dir.pwd, 'vendor', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
108
+ File.join(Dir.pwd, 'vendor', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
109
109
  }
110
110
  end
111
111
 
@@ -121,13 +121,13 @@ describe 'rake check:symlinks', type: :task do
121
121
 
122
122
  let(:test_files) do
123
123
  [
124
- File.join(Dir.pwd, 'files', 'a_file.pp')
124
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
125
125
  ]
126
126
  end
127
127
 
128
128
  let(:symlinks) do
129
129
  {
130
- File.join(Dir.pwd, 'a_directory', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
130
+ File.join(Dir.pwd, 'a_directory', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
131
131
  }
132
132
  end
133
133
 
@@ -145,13 +145,13 @@ describe 'rake check:symlinks', type: :task do
145
145
 
146
146
  let(:test_files) do
147
147
  [
148
- File.join(Dir.pwd, 'files', 'a_file.pp')
148
+ File.join(Dir.pwd, 'files', 'a_file.pp'),
149
149
  ]
150
150
  end
151
151
 
152
152
  let(:symlinks) do
153
153
  {
154
- File.join(Dir.pwd, 'another_directory', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp')
154
+ File.join(Dir.pwd, 'another_directory', 'a_symlink.pp') => File.join(Dir.pwd, 'files', 'a_file.pp'),
155
155
  }
156
156
  end
157
157
 
@@ -14,7 +14,7 @@ describe 'rake check:test_file', type: :task do
14
14
  let(:test_files) do
15
15
  [
16
16
  File.join(Dir.pwd, 'tests', 'an_example.pp'),
17
- File.join(Dir.pwd, 'tests', 'deep', 'directory', 'structure', 'another_example.pp')
17
+ File.join(Dir.pwd, 'tests', 'deep', 'directory', 'structure', 'another_example.pp'),
18
18
  ]
19
19
  end
20
20
 
@@ -141,7 +141,7 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
141
141
  'branch' => nil,
142
142
  'scm' => nil,
143
143
  'flags' => nil,
144
- 'subdir' => nil
144
+ 'subdir' => nil,
145
145
  },
146
146
  )
147
147
  end
@@ -159,18 +159,41 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
159
159
  'branch' => nil,
160
160
  'scm' => nil,
161
161
  'flags' => '--module_repository=https://myforge.example.com/',
162
- 'subdir' => nil
162
+ 'subdir' => nil,
163
163
  },
164
164
  )
165
165
  end
166
166
  end
167
167
 
168
+ context 'when forge_api_key env variable is set' do
169
+ before do
170
+ # required to prevent unwanted output on stub of $CHILD_STATUS
171
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
172
+ end
173
+
174
+ after do
175
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = false
176
+ end
177
+
178
+ it 'correctly sets --forge_authorization' do
179
+ allow(ENV).to receive(:fetch).with('FORGE_API_KEY', nil).and_return('myforgeapikey')
180
+ # Mock the system call to prevent actual execution
181
+ allow_any_instance_of(Kernel).to receive(:system) do |command| # rubocop:disable RSpec/AnyInstance
182
+ expect(command).to include('--forge_authorization "Bearer myforgeapikey"')
183
+ # Simulate setting $CHILD_STATUS to a successful status
184
+ allow($CHILD_STATUS).to receive(:success?).and_return(true)
185
+ true
186
+ end
187
+ helper.download_module('puppetlabs-stdlib', 'target' => 'spec/fixtures/modules/stdlib')
188
+ end
189
+ end
190
+
168
191
  context 'when file specifies repository fixtures' do
169
192
  before do
170
193
  allow(File).to receive(:exist?).with('.fixtures.yml').and_return true
171
194
  allow(YAML).to receive(:load_file).with('.fixtures.yml').and_return(
172
195
  'fixtures' => {
173
- 'repositories' => { 'stdlib' => 'https://github.com/puppetlabs/puppetlabs-stdlib.git' }
196
+ 'repositories' => { 'stdlib' => 'https://github.com/puppetlabs/puppetlabs-stdlib.git' },
174
197
  },
175
198
  )
176
199
  end
@@ -183,7 +206,7 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
183
206
  'branch' => nil,
184
207
  'scm' => nil,
185
208
  'flags' => nil,
186
- 'subdir' => nil
209
+ 'subdir' => nil,
187
210
  },
188
211
  )
189
212
  end
@@ -198,9 +221,9 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
198
221
  'stdlib' => {
199
222
  'scm' => 'git',
200
223
  'repo' => 'https://github.com/puppetlabs/puppetlabs-stdlib.git',
201
- 'ref' => 'this/is/a/branch'
202
- }
203
- }
224
+ 'ref' => 'this/is/a/branch',
225
+ },
226
+ },
204
227
  },
205
228
  )
206
229
  end
@@ -222,9 +245,9 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
222
245
  'forge_modules' => {
223
246
  'stdlib' => {
224
247
  'repo' => 'puppetlabs-stdlib',
225
- 'puppet_version' => Puppet::PUPPETVERSION
226
- }
227
- }
248
+ 'puppet_version' => Puppet::PUPPETVERSION,
249
+ },
250
+ },
228
251
  },
229
252
  )
230
253
  expect(helper.fixtures('forge_modules')).to include('puppetlabs-stdlib')
@@ -236,9 +259,9 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
236
259
  'forge_modules' => {
237
260
  'stdlib' => {
238
261
  'repo' => 'puppetlabs-stdlib',
239
- 'puppet_version' => '>= 999.9.9'
240
- }
241
- }
262
+ 'puppet_version' => '>= 999.9.9',
263
+ },
264
+ },
242
265
  },
243
266
  )
244
267
  expect(helper.fixtures('forge_modules')).to eq({})
@@ -250,9 +273,9 @@ describe PuppetlabsSpecHelper::Tasks::FixtureHelpers do
250
273
  'forge_modules' => {
251
274
  'stdlib' => {
252
275
  'repo' => 'puppetlabs-stdlib',
253
- 'puppet_version' => Puppet::PUPPETVERSION
254
- }
255
- }
276
+ 'puppet_version' => Puppet::PUPPETVERSION,
277
+ },
278
+ },
256
279
  },
257
280
  )
258
281
  expect(helper.fixtures('forge_modules')).to include('puppetlabs-stdlib')
data/spec/watchr.rb CHANGED
@@ -11,7 +11,7 @@ def growl(message)
11
11
  title = 'Watchr Test Results'
12
12
  image = case message
13
13
  when /(\d+)\s+?(failure|error)/i
14
- Regexp.last_match(1).to_i == 0 ? '~/.watchr_images/passed.png' : '~/.watchr_images/failed.png'
14
+ (Regexp.last_match(1).to_i == 0) ? '~/.watchr_images/passed.png' : '~/.watchr_images/failed.png'
15
15
  else
16
16
  '~/.watchr_images/unknown.png'
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetlabs_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.1
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-06-06 00:00:00.000000000 Z
12
+ date: 2024-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mocha
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '3'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '1.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: pathspec
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +40,7 @@ dependencies:
34
40
  version: '0.2'
35
41
  - - "<"
36
42
  - !ruby/object:Gem::Version
37
- version: 2.0.0
43
+ version: '3'
38
44
  type: :runtime
39
45
  prerelease: false
40
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +50,7 @@ dependencies:
44
50
  version: '0.2'
45
51
  - - "<"
46
52
  - !ruby/object:Gem::Version
47
- version: 2.0.0
53
+ version: '3'
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: puppet-lint
50
56
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +105,28 @@ dependencies:
99
105
  requirements:
100
106
  - - "~>"
101
107
  - !ruby/object:Gem::Version
102
- version: '4.0'
108
+ version: '5.0'
103
109
  type: :runtime
104
110
  prerelease: false
105
111
  version_requirements: !ruby/object:Gem::Requirement
106
112
  requirements:
107
113
  - - "~>"
108
114
  - !ruby/object:Gem::Version
109
- version: '4.0'
115
+ version: '5.0'
116
+ - !ruby/object:Gem::Dependency
117
+ name: voxpupuli-rubocop
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 2.8.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 2.8.0
110
130
  description: Contains rake tasks and a standard spec_helper for running spec tests
111
131
  on puppet modules.
112
132
  email: