-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PDK-773) Implementation of PDK::Module::Update
- Loading branch information
Showing
7 changed files
with
326 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
require 'spec_helper' | ||
require 'pdk/module/update' | ||
|
||
describe PDK::Module::Update do | ||
let(:options) { {} } | ||
let(:mock_metadata) do | ||
instance_double( | ||
PDK::Module::Metadata, | ||
data: { | ||
'template-url' => template_url, | ||
'template-ref' => template_ref, | ||
}, | ||
) | ||
end | ||
let(:template_url) { 'https://github.com/puppetlabs/pdk-templates' } | ||
let(:template_ref) { nil } | ||
|
||
shared_context 'with mock metadata' do | ||
before(:each) do | ||
allow(PDK::Module::Metadata).to receive(:from_file).with('metadata.json').and_return(mock_metadata) | ||
end | ||
end | ||
|
||
describe '#run' do | ||
let(:instance) { described_class.new(options) } | ||
let(:template_ref) { '1.3.2-0-g1234567' } | ||
|
||
include_context 'with mock metadata' | ||
|
||
before(:each) do | ||
allow(instance).to receive(:stage_changes!) | ||
allow(instance).to receive(:print_summary) | ||
allow(instance).to receive(:new_version).and_return('1.4.0') | ||
end | ||
|
||
after(:each) do | ||
instance.run | ||
end | ||
|
||
context 'when running in noop mode' do | ||
let(:options) { { noop: true } } | ||
|
||
it 'does not prompt the user to make the changes' do | ||
expect(PDK::CLI::Util).not_to receive(:prompt_for_yes) | ||
end | ||
|
||
it 'does not sync the pending changes' do | ||
expect(instance.update_manager).not_to receive(:sync_changes!) | ||
end | ||
end | ||
end | ||
|
||
describe '#module_metadata' do | ||
subject(:result) { described_class.new(options).module_metadata } | ||
|
||
context 'when the metadata.json can be read' do | ||
include_context 'with mock metadata' | ||
|
||
it 'returns the metadata object' do | ||
is_expected.to eq(mock_metadata) | ||
end | ||
end | ||
|
||
context 'when the metadata.json can not be read' do | ||
before(:each) do | ||
allow(PDK::Module::Metadata).to receive(:from_file).with('metadata.json').and_raise(ArgumentError, 'some error') | ||
end | ||
|
||
it 'raises an ExitWithError exception' do | ||
expect { -> { result }.call }.to raise_error(PDK::CLI::ExitWithError, %r{some error}i) | ||
end | ||
end | ||
end | ||
|
||
describe '#template_url' do | ||
subject { described_class.new(options).template_url } | ||
|
||
include_context 'with mock metadata' | ||
|
||
it 'returns the template-url value from the module metadata' do | ||
is_expected.to eq('https://github.com/puppetlabs/pdk-templates') | ||
end | ||
end | ||
|
||
describe '#current_version' do | ||
subject { described_class.new(options).current_version } | ||
|
||
include_context 'with mock metadata' | ||
|
||
context 'when the template-ref describes a git tag' do | ||
let(:template_ref) { '1.3.2-0-g07678c8' } | ||
|
||
it 'returns the tag name' do | ||
is_expected.to eq('1.3.2') | ||
end | ||
end | ||
|
||
context 'when the template-ref describes a branch commit' do | ||
let(:template_ref) { 'heads/master-4-g1234abc' } | ||
|
||
it 'returns the branch name and the commit SHA' do | ||
is_expected.to eq('master@1234abc') | ||
end | ||
end | ||
end | ||
|
||
describe '#new_version' do | ||
subject { described_class.new(options).new_version } | ||
|
||
context 'when the default_template_ref specifies a tag' do | ||
before(:each) do | ||
allow(PDK::Util).to receive(:default_template_ref).and_return('1.4.0') | ||
end | ||
|
||
it 'returns the tag name' do | ||
is_expected.to eq('1.4.0') | ||
end | ||
end | ||
|
||
context 'when the default_template_ref specifies a branch head' do | ||
before(:each) do | ||
allow(PDK::Util).to receive(:default_template_ref).and_return('origin/master') | ||
allow(PDK::Util::Git).to receive(:ls_remote) | ||
.with(template_url, 'refs/heads/master') | ||
.and_return('3cdd84e8f0aae30bf40d15556482fc8752899312') | ||
end | ||
|
||
include_context 'with mock metadata' | ||
let(:template_ref) { 'heads/master-0-g07678c8' } | ||
|
||
it 'returns the branch name and the commit SHA' do | ||
is_expected.to eq('master@3cdd84e') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters