Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CONT-935) Fix issues with PDK package and tests #1248

Merged
merged 6 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion docs/pdk_converting_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ changes.
|`Rakefile`|File containing configuration for the Ruby infrastructure. Used in CI and for backwards compatibility.|
|`.rspec`|File containing the default configuration for RSpec.|
|`.rubocop.yml`|File containing recommended settings for Ruby style checking.|
|`.travis.yml`|File containing configuration for cloud-based testing on Linux and Mac OS X. See [travis-ci](http://travis-ci.org/) for more information.|
|`.yardopts`|File containing configuration for [YARD](https://yardoc.org/) for source files, extra files, and formatting options that you want to use to generate your documentation.|

## Convert a module
Expand Down
1 change: 0 additions & 1 deletion docs/pdk_creating_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ writing, validating, and testing Puppet code. 
|`.sync.yml`|File to customize the PDK template in use.|
|`./tasks`|Directory containing task files and task metadata files for any tasks you create with the `pdk new task`command.|
|`./templates`|Directory containing any ERB or EPP templates. Required when building a module to upload to the Forge.|
|`.travis.yml`|File containing configuration for cloud-based testing on Linux and Mac OS X. See the [travis-ci](http://travis-ci.org/) docs for more information.|
|`.vscode`|Directory containing configuration for Visual Studio code.|
|`.yardopts`|File containing the default configuration for Puppet Strings.|

Expand Down
1 change: 0 additions & 1 deletion lib/pdk/analytics/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def self.fetch_os_async
require 'concurrent/future'

Concurrent::Future.execute(executor: :io) do
require 'facter'
os = Facter.value('os')

os.nil? ? 'unknown' : "#{os['name']} #{os.fetch('release', {}).fetch('major', '')}".strip
Expand Down
10 changes: 9 additions & 1 deletion lib/pdk/cli/exec/interactive_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ module PDK
module CLI
module Exec
class InteractiveCommand < Command
# rubocop :disable Lint/MissingSuper
def initialize(*argv)
super(*argv)
@argv = argv

# Default to running things in the system context.
@context = :system

# Extra environment vars to add to base set.
@environment = {}
end
# rubocop :enable Lint/MissingSuper

def register_spinner(_spinner, _opts = {})
raise 'This method is not implemented for PDK::CLI::Exec::InteractiveCommand'
Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/config/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def to_h
new_hash = {}
settings.each_pair { |k, v| new_hash[k] = v.value }
@mounts.each_pair { |k, mount_point| new_hash[k] = mount_point.to_h if mount_point.include_in_parent? }
new_hash.delete_if { |_, v| v.nil? }
new_hash.delete_if { |_k, v| v.nil? } # rubocop :disable Style/CollectionCompact
new_hash
end

Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -119,7 +119,7 @@ def update!(data)
def to_json(*_args)
require 'json'

JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? })
JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? }) # rubocop:disable Style/CollectionCompact
end

def write!(path)
Expand Down
28 changes: 0 additions & 28 deletions spec/acceptance/convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,6 @@
end
end

context 'when deleting a file' do
include_context 'in a new module', 'deleted_file', template: template_repo

before(:all) do
File.open('.sync.yml', 'w') do |f|
f.puts <<~EOS
---
.travis.yml:
delete: true
EOS
end
end

describe command("#{pdk_convert_base} --force --skip-interview") do
its(:exit_status) { is_expected.to eq(0) }
its(:stderr) { is_expected.to have_no_output }
its(:stdout) { is_expected.to match(%r{-+files to be removed-+\n.*/\.travis.yml}mi) }
end

describe file('.travis.yml') do
it { is_expected.not_to be_file }
end

describe file('convert_report.txt') do
it { is_expected.not_to be_file }
end
end

context 'when an init-only templated file is missing' do
include_context 'in a new module', 'init_missing', template: template_repo

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
4 changes: 2 additions & 2 deletions spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
describe command('pdk test unit') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(/expected: true.*got: false/im) }
its(:stdout) { is_expected.to match(/1 examples?.*1 failures?/im) }
its(:stdout) { is_expected.to match(/2 examples?.*1 failures?/im) }
end
end

Expand All @@ -107,7 +107,7 @@

describe command('pdk test unit') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(/1 examples?.*0 failures.*1 pending/im) }
its(:stdout) { is_expected.to match(/2 examples?.*0 failures.*1 pending/im) }
end
end

Expand Down
11 changes: 0 additions & 11 deletions spec/acceptance/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,26 @@
File.open('metadata.json', 'w') do |f|
f.puts metadata.to_json
end
FileUtils.rm('.travis.yml')
end

describe command('pdk update --noop') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(%r{-+files to be added-+\n.*/\.travis\.yml}mi) }
its(:stdout) { is_expected.to match(%r{-+files to be modified-+\n.*/metadata\.json}mi) }
its(:stderr) { is_expected.to match(/updating \w+?-update using the default template/i) }

describe file('update_report.txt') do
it { is_expected.to be_file }
end

describe file('.travis.yml') do
it { is_expected.not_to be_file }
end
end

describe command('pdk update --force') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(%r{-+files to be added-+\n.*/\.travis\.yml}mi) }
its(:stdout) { is_expected.to match(%r{-+files to be modified-+\n.*/metadata\.json}mi) }
its(:stderr) { is_expected.to match(/updating \w+?-update using the default template/i) }

describe file('update_report.txt') do
it { is_expected.to be_file }
end

describe file('.travis.yml') do
it { is_expected.to be_file }
end
end
end

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