Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Jen committed Aug 9, 2018
1 parent d101403 commit 5cccaa1
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
31 changes: 31 additions & 0 deletions spec/unit/pdk/cli/test/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,35 @@
}.to exit_zero
end
end

context 'with --puppet-dev' do
let(:puppet_env) do
{
ruby_version: '2.4.3',
gemset: { puppet: 'file://path/to/puppet' },
}
end

before(:each) do
allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).with(hash_including(:'puppet-dev' => true)).and_return(puppet_env)
allow(PDK::Test::Unit).to receive(:invoke).and_return(0)
allow(PDK::CLI::Util).to receive(:module_version_check)
end

it 'activates puppet github source' do
expect(PDK::Util::Bundler).to receive(:ensure_bundle!).with(puppet_env[:gemset])

expect {
test_unit_cmd.run_this(['--puppet-dev'])
}.to exit_zero
end

it 'activates resolved ruby version' do
expect(PDK::Util::RubyVersion).to receive(:use).with(puppet_env[:ruby_version])

expect {
test_unit_cmd.run_this(['--puppet-dev'])
}.to exit_zero
end
end
end
23 changes: 22 additions & 1 deletion spec/unit/pdk/cli/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,28 @@
end

context 'with --puppet-dev' do
it 'activates resolved puppet version' do
let(:puppet_env) do
{
ruby_version: '2.4.3',
gemset: { puppet: 'file://path/to/puppet' },
}
end

before(:each) do
allow(PDK::CLI::Util).to receive(:puppet_from_opts_or_env).with(hash_including(:'puppet-dev' => true)).and_return(puppet_env)
end

it 'activates puppet github source' do
expect(PDK::Util::Bundler).to receive(:ensure_bundle!).with(puppet_env[:gemset])

expect {
PDK::CLI.run(['validate', '--puppet-dev'])
}.to exit_zero
end

it 'activates resolved ruby version' do
expect(PDK::Util::RubyVersion).to receive(:use).with(puppet_env[:ruby_version])

expect {
PDK::CLI.run(['validate', '--puppet-dev'])
}.to exit_zero
Expand Down
98 changes: 98 additions & 0 deletions spec/unit/pdk/util/puppet_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,104 @@
end
end

describe '.fetch_puppet_dev' do
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)
end

context 'and fails to connect to github' do
let(:clone_results) do
{
stdout: 'foo',
stderr: 'bar',
exit_code: 1,
}
end

before(:each) do
allow(PDK::Util).to receive(:cachedir).and_return(File.join('path', 'to'))
allow(PDK::Util::Git).to receive(:git).with('clone', anything, anything).and_return(clone_results)
end

it 'raises an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{foo}))
expect(logger).to receive(:error).with(a_string_matching(%r{bar}))
expect {
described_class.fetch_puppet_dev
}.to raise_error(PDK::CLI::FatalError, a_string_matching(%r{Unable to clone git repository}i))
end
end

context 'and successfully connects to github' do
let(:clone_results) do
{
stdout: 'foo',
stderr: 'bar',
exit_code: 0,
}
end

before(:each) do
allow(PDK::Util).to receive(:cachedir).and_return(File.join('path', 'to'))
allow(PDK::Util::Git).to receive(:git).with('clone', anything, anything).and_return(clone_results)
end

it 'exits cleanly' do
expect(described_class.fetch_puppet_dev).to eq(nil)
end
end
end

context 'if puppet source is already cloned' do
before(:each) do
allow(PDK::Util::Git).to receive(:remote_repo?).with(anything).and_return(true)
end

context 'and fails to connect to github' do
let(:fetch_results) do
{
stdout: 'foo',
stderr: 'bar',
exit_code: 1,
}
end

before(:each) do
allow(PDK::Util).to receive(:cachedir).and_return('/path/to/')
allow(PDK::Util::Git).to receive(:git).with('fetch', anything, anything).and_return(fetch_results)
end

it 'raises an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{foo}))
expect(logger).to receive(:error).with(a_string_matching(%r{bar}))
expect {
described_class.fetch_puppet_dev
}.to raise_error(PDK::CLI::FatalError, a_string_matching(%r{Unable to fetch updates for git repository}i))
end
end

context 'and successfully connects to github' do
let(:clone_results) do
{
stdout: 'foo',
stderr: 'bar',
exit_code: 0,
}
end

before(:each) do
allow(PDK::Util).to receive(:cachedir).and_return('/path/to/')
allow(PDK::Util::Git).to receive(:git).with('fetch', anything, anything).and_return(clone_results)
end

it 'exits cleanly' do
expect(described_class.fetch_puppet_dev).to eq(nil)
end
end
end
end

describe '.find_gem_for' do
context 'when running from a package install' do
include_context 'is a package install'
Expand Down

0 comments on commit 5cccaa1

Please sign in to comment.