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

(#764) Ensure --puppet-dev checkout is always updated #792

Merged
merged 1 commit into from
Oct 29, 2019
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 lib/pdk/cli/new/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module PDK::CLI
end

puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])

Expand Down
1 change: 0 additions & 1 deletion lib/pdk/cli/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module PDK::CLI

# Ensure that the bundled gems are up to date and correct Ruby is activated before running or listing tests.
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])

opts.merge!(puppet_env[:gemset])
Expand Down
1 change: 1 addition & 0 deletions lib/pdk/cli/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def puppet_from_opts_or_env(opts, logging_disabled = false)
begin
puppet_env =
if use_puppet_dev
PDK::Util::PuppetVersion.fetch_puppet_dev(run: :once)
PDK::Util::PuppetVersion.puppet_dev_env
elsif desired_puppet_version
PDK::Util::PuppetVersion.find_gem_for(desired_puppet_version)
Expand Down
1 change: 0 additions & 1 deletion lib/pdk/cli/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ module PDK::CLI

# Ensure that the bundled gems are up to date and correct Ruby is activated before running any validations.
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])

options.merge!(puppet_env[:gemset])
Expand Down
10 changes: 9 additions & 1 deletion lib/pdk/util/puppet_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ def latest_available
latest
end

def fetch_puppet_dev
def puppet_dev_fetched?
!@puppet_dev_fetched.nil?
end

def fetch_puppet_dev(options = {})
return if options[:run] == :once && puppet_dev_fetched?

require 'pdk/util/git'
require 'fileutils'

Expand Down Expand Up @@ -76,6 +82,8 @@ def fetch_puppet_dev

# Reset local repo to latest
reset_result = PDK::Util::Git.git('-C', puppet_dev_path, 'reset', '--hard', 'origin/master')

@puppet_dev_fetched = true
return if reset_result[:exit_code].zero?

PDK.logger.error reset_result[:stdout]
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/pdk/cli/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
before(:each) do
allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_path).and_return(puppet_version)
allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_env).and_return(version_result)
allow(PDK::Util::PuppetVersion).to receive(:fetch_puppet_dev)
end

it_behaves_like 'it returns a puppet environment'
Expand All @@ -222,6 +223,7 @@
allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_path).and_return(puppet_version)
allow(PDK::Util::PuppetVersion).to receive(:puppet_dev_env).and_return(version_result)
allow(PDK::Util::Env).to receive(:[]).with('PDK_PUPPET_DEV').and_return('true')
allow(PDK::Util::PuppetVersion).to receive(:fetch_puppet_dev)
end

it_behaves_like 'it returns a puppet environment'
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/pdk/util/puppet_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@
end

describe '.fetch_puppet_dev' do
context 'if puppet source has already been fetched' do
before(:each) do
allow(described_class.instance).to receive(:puppet_dev_fetched?).and_return(true)
end

context 'when run with :run => :once' do
it 'does not perform any git operations' do
expect(PDK::Util::Git).not_to receive(:git)

described_class.fetch_puppet_dev(run: :once)
end
end

context 'when not run with :run => :once' do
it 'performs the git operations' do
allow(PDK::Util::Git).to receive(:remote_repo?).with(anything).and_return(true)
allow(PDK::Util).to receive(:cachedir).and_return(File.join('path', 'to'))

expect(PDK::Util::Git).to receive(:git).with(any_args).and_return(exit_code: 0).twice

described_class.fetch_puppet_dev
end
end
end

context 'if puppet source is not cloned yet' do
before(:each) do
allow(PDK::Util::Git).to receive(:remote_repo?).with(anything).and_return(false)
Expand Down