Skip to content

Commit

Permalink
(CONT-935) Set correct Puppet version for Ruby
Browse files Browse the repository at this point in the history
Prior to this change the tests were unable to recognise when Puppet 8
was a requirement.

This change ensures that when Ruby 3 is being used, Puppet 8 is also
used.
  • Loading branch information
chelnak committed May 26, 2023
1 parent 1bafc32 commit 0602330
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ jobs:
ruby_version: ${{ matrix.ruby_version }}
rake_task: 'acceptance:local'
runs_on: ${{ matrix.os }}

7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ end

namespace :acceptance do
desc 'Run acceptance tests against current code'

task :env do
ENV['PDK_PUPPET_VERSION'] = RUBY_VERSION.split('.')[0].include?('3') ? '8' : '7'
end

RSpec::Core::RakeTask.new(:local) do |t|
t.rspec_opts = '--tag ~package' # Exclude package specific examples
t.pattern = 'spec/acceptance/**/*_spec.rb'
end
task local: [:binstubs]
task local: [:binstubs, :env]

task local_parallel: [:binstubs] do
require 'parallel_tests'
Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/module/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Metadata
OPERATING_SYSTEMS[os_name]
end.flatten,
'requirements' => [
{ 'name' => 'puppet', 'version_requirement' => '>= 6.21.0 < 8.0.0' }
{ 'name' => 'puppet', 'version_requirement' => '>= 7.24 < 9.0.0' }
]
}.freeze

Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/support/in_a_new_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
'--skip-interview',
'--template-url', template
]
env = { 'PDK_ANSWER_FILE' => File.join(Dir.pwd, "#{name}_answers.json") }
env = {
'PDK_ANSWER_FILE' => File.join(Dir.pwd, "#{name}_answers.json"),
'PDK_PUPPET_VERSION' => ENV.fetch('PDK_PUPPET_VERSION', '7')
}

output, status = Open3.capture2e(env, *argv)

raise "Failed to create test module:\n#{output}" unless status.success?
Expand Down
27 changes: 18 additions & 9 deletions spec/acceptance/version_changer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,25 @@ class version_select {
its(:stderr) { is_expected.not_to match(%r{Using Puppet file://}i) }
end

# Note that there is no guarantee that the main branch of puppet is compatible with the PDK under test
# so we can only test that the validate command is using the expected puppet gem location
describe command('pdk validate --puppet-dev') do
its(:stderr) { is_expected.to match(%r{Using Puppet file://}i) }
end
context 'when PDK_PUPPET_VERSION is set' do
around do |example|
pdk_puppet_version = ENV.fetch('PDK_PUPPET_VERSION', nil)
ENV['PDK_PUPPET_VERSION'] = nil
example.run
ENV['PDK_PUPPET_VERSION'] = pdk_puppet_version
end

# Note that there is no guarantee that the main branch of puppet is compatible with the PDK under test
# so we can only test that the test command is using the expected puppet gem location
describe command('pdk test unit --puppet-dev') do
its(:stderr) { is_expected.to match(%r{Using Puppet file://}i) }
# Note that there is no guarantee that the main branch of puppet is compatible with the PDK under test
# so we can only test that the validate command is using the expected puppet gem location
describe command('pdk validate --puppet-dev') do
its(:stderr) { is_expected.to match(%r{Using Puppet file://}i) }
end

# Note that there is no guarantee that the main branch of puppet is compatible with the PDK under test
# so we can only test that the test command is using the expected puppet gem location
describe command('pdk test unit --puppet-dev') do
its(:stderr) { is_expected.to match(%r{Using Puppet file://}i) }
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pdk/cli/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

let(:pretty_validator_names) { PDK::Validate.validator_names.join(', ') }
let(:report) { instance_double(PDK::Report).as_null_object }
let(:ruby_version) { '2.4.3' }
let(:puppet_version) { '5.4.0' }
let(:ruby_version) { '3.2.2' }
let(:puppet_version) { '8.0.1' }
let(:module_path) { '/path/to/testmodule' }
let(:context) { PDK::Context::Module.new(module_path, module_path) }

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pdk/util/puppet_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ def result(pe_version)
let(:metadata) { PDK::Module::Metadata.new }

context 'with default metadata' do
it 'searches for a Puppet gem >= 6.21.0 < 8.0.0' do
requirement = Gem::Requirement.create(['>= 6.21.0', '< 8.0.0'])
it 'searches for a Puppet gem >= 7.24.0 < 9.0.0' do
requirement = Gem::Requirement.create(['>= 7.24.0', '< 9.0.0'])
expect(described_class.instance).to receive(:find_gem).with(requirement)

described_class.from_module_metadata(metadata)
Expand Down

0 comments on commit 0602330

Please sign in to comment.