Skip to content

Commit

Permalink
(PDK-789) Add pdk metadata to all generated templatedirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmjen committed Feb 15, 2018
1 parent c6db211 commit 3736937
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/pdk/generate/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ def self.prepare_metadata(opts = {})
metadata = PDK::Module::Metadata.new(defaults)
module_interview(metadata, opts) unless opts[:'skip-interview']

metadata.update!('pdk-version' => PDK::Util::Version.version_string)

metadata
end

Expand Down
6 changes: 5 additions & 1 deletion lib/pdk/module/templatedir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def metadata

ref_result = PDK::Util::Git.git('--git-dir', File.join(@path, '.git'), 'describe', '--all', '--long', '--always')
if ref_result[:exit_code].zero?
{ 'template-url' => @repo, 'template-ref' => ref_result[:stdout].strip }
{
'pdk-version' => PDK::Util::Version.version_string,
'template-url' => @repo,
'template-ref' => ref_result[:stdout].strip,
}
else
{}
end
Expand Down
4 changes: 0 additions & 4 deletions spec/unit/pdk/generate/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,6 @@
'dependencies' => [],
)
end

it 'includes the PDK version number' do
expect(metadata.data).to include('pdk-version' => PDK::Util::Version.version_string)
end
end

context 'when an answer file exists with answers' do
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/pdk/module/template_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,24 @@
end
end
end

describe '.metadata' do
before(:each) do
allow(File).to receive(:directory?).with(anything).and_return(true)
allow(File).to receive(:directory?).with(path_or_url).and_return(false)
allow(PDK::Util).to receive(:default_template_ref).and_return('default-ref')
allow(PDK::Util).to receive(:make_tmpdir_name).with('pdk-templates').and_return('/tmp/path')
allow(PDK::Util::Git).to receive(:git).with('clone', path_or_url, '/tmp/path').and_return(exit_code: 0)
allow(PDK::Util::Git).to receive(:git).with('-C', '/tmp/path', 'reset', '--hard', 'default-ref').and_return(exit_code: 0)
allow(FileUtils).to receive(:remove_dir).with('/tmp/path')
allow(PDK::Util::Git).to receive(:git).with('--git-dir', anything, 'describe', '--all', '--long', '--always').and_return(exit_code: 0, stdout: '1234abcd')
allow(PDK::Util::Version).to receive(:version_string).and_return('0.0.0')
end

context 'pdk data' do
it 'includes the PDK version and template info' do
expect(template_dir.metadata).to include('pdk-version' => '0.0.0', 'template-url' => '/path/to/templates', 'template-ref' => '1234abcd')
end
end
end
end

0 comments on commit 3736937

Please sign in to comment.