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-1180) Cleanly handle a null pdk-version in metadata.json #599

Merged
merged 1 commit into from
Nov 26, 2018
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
6 changes: 3 additions & 3 deletions lib/pdk/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ def module_pdk_compatible?
def module_pdk_version
metadata = module_metadata

if !metadata.nil? && metadata.include?('pdk-version')
metadata['pdk-version'].split.first
else
if metadata.nil? || metadata.fetch('pdk-version', nil).nil?
nil
else
metadata['pdk-version'].split.first
end
rescue ArgumentError => e
PDK.logger.error(e)
Expand Down
26 changes: 19 additions & 7 deletions spec/unit/pdk/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,31 @@
describe 'module_pdk_version' do
subject(:result) { described_class.module_pdk_version }

let(:module_metadata) { {} }

before(:each) do
allow(described_class).to receive(:module_metadata).and_return(module_metadata)
end

context 'is nil' do
let(:module_metadata) { { 'pdk-version' => nil } }

it { is_expected.to be_nil }
end

context 'is an empty string' do
let(:module_metadata) { { 'pdk-version' => '' } }

it { is_expected.to be_nil }
end

context 'is in metadata' do
before(:each) do
allow(described_class).to receive(:module_metadata).and_return(mock_metadata.data)
end
let(:module_metadata) { mock_metadata.data }

it { is_expected.to match(pdk_version) }
end

context 'is not in metadata' do
before(:each) do
allow(described_class).to receive(:module_metadata).and_return({})
end

it { is_expected.to be nil }
end

Expand Down