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

(PDK-1096, PDK-1097, PDK-1098) Add puppet-dev flag to validate and test unit #559

Merged
merged 7 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def self.puppet_version_options(dsl)
dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
end

def self.puppet_dev_option(dsl)
dsl.option nil,
'puppet-dev',
_('When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.')
end

@base_cmd = Cri::Command.define do
name 'pdk'
usage _('pdk command [options]')
Expand Down
1 change: 1 addition & 0 deletions lib/pdk/cli/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module PDK::CLI
summary _('Run unit tests.')

PDK::CLI.puppet_version_options(self)
PDK::CLI.puppet_dev_option(self)
flag nil, :list, _('List all available unit test files.')
flag nil, :parallel, _('Run unit tests in parallel.')
flag :v, :verbose, _('More verbose --list output. Displays a list of examples in each unit test file.')
Expand Down
25 changes: 24 additions & 1 deletion lib/pdk/cli/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ def validate_puppet_version_opts(opts)
pe_ver_specs << '--pe-version option' if opts[:'pe-version']
pe_ver_specs << 'PDK_PE_VERSION environment variable' if ENV['PDK_PE_VERSION'] && !ENV['PDK_PE_VERSION'].empty?

puppet_dev_specs = []
puppet_dev_specs << '--puppet-dev flag' if opts[:'puppet-dev']
puppet_dev_specs << 'PDK_PUPPET_DEV environment variable' if ENV['PDK_PUPPET_DEV'] && !ENV['PDK_PUPPET_DEV'].empty?

puppet_dev_specs.each do |pup_dev_spec|
[puppet_ver_specs, pe_ver_specs].each do |offending|
next if offending.empty?

raise PDK::CLI::ExitWithError, _('You cannot specify a %{first} and %{second} at the same time') % {
first: pup_dev_spec,
second: offending.first,
}
end
end

puppet_ver_specs.each do |pup_ver_spec|
next if pe_ver_specs.empty?

Expand All @@ -143,7 +158,15 @@ def validate_puppet_version_opts(opts)
}
end

if puppet_ver_specs.size == 2
if puppet_dev_specs.size == 2
warning_str = 'Puppet dev flag from command line: "--puppet-dev" '
warning_str += 'overrides value from environment: "PDK_PUPPET_DEV=true". You should not specify both.'

PDK.logger.warn(_(warning_str) % {
pup_ver_opt: opts[:'puppet-dev'],
pup_ver_env: ENV['PDK_PUPPET_DEV'],
})
elsif puppet_ver_specs.size == 2
warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
warning_str += 'overrides value from environment: "PDK_PUPPET_VERSION=%{pup_ver_env}". You should not specify both.'

Expand Down
1 change: 1 addition & 0 deletions lib/pdk/cli/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module PDK::CLI
)

PDK::CLI.puppet_version_options(self)
PDK::CLI.puppet_dev_option(self)
flag nil, :list, _('List all available validators.')
flag :a, 'auto-correct', _('Automatically correct problems where possible.')
flag nil, :parallel, _('Run validations in parallel.')
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/pdk/cli/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,32 @@
}.to exit_zero
end
end

context 'with --puppet-dev' do
it 'activates resolved puppet version' do
expect {
PDK::CLI.run(['validate', '--puppet-dev'])
}.to exit_zero
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't actually asserting anything about activating the right puppet version yet, I assume this that part hasn't been implemented in this PR. But maybe it would be better to leave this out or mark it as pending so that we don't accidentally leave it this way later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. I was going to address it in the next PR when I do get the puppet-version selection parts tested.

end

context 'with both --puppet-version and --puppet-dev' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--puppet-version}i))

expect {
PDK::CLI.run(%w[validate --puppet-version 4.10.10 --puppet-dev])
}.to exit_nonzero
end
end

context 'with both --pe-version and --puppet-dev' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--pe-version}i))

expect {
PDK::CLI.run(%w[validate --pe-version 2018.1 --puppet-dev])
}.to exit_nonzero
end
end
end