Commit 4f117dc0 authored by Marco Voelz's avatar Marco Voelz Committed by Maria Shaldibina

Check for empty license when compiling release

Signed-off-by: default avatarMaria Shaldibina <mshaldibina@pivotal.io>
parent f36d5a1a
......@@ -37,9 +37,9 @@ module Bosh::Cli
@name = @manifest["name"]
@version = @manifest["version"]
@packages = @manifest["packages"].map { |pkg| OpenStruct.new(pkg) }
@jobs = @manifest["jobs"].map { |job| OpenStruct.new(job) }
@license = OpenStruct.new(@manifest["license"])
@packages = @manifest.fetch("packages", []).map { |pkg| OpenStruct.new(pkg) }
@jobs = @manifest.fetch("jobs", []).map { |job| OpenStruct.new(job) }
@license = @manifest["license"] ? OpenStruct.new(@manifest["license"]) : nil
end
def compile
......@@ -78,10 +78,12 @@ module Bosh::Cli
end
header("Copying license")
say("license (#{@license.version})".ljust(30), " ")
nl
license_file_path = find_license(@license)
FileUtils.cp(license_file_path, File.join(@build_dir, 'license.tgz'), preserve: true)
if @license
say("license (#{@license.version})".ljust(30), " ")
nl
license_file_path = find_license(@license)
FileUtils.cp(license_file_path, File.join(@build_dir, 'license.tgz'), preserve: true)
end
header("Building tarball")
Dir.chdir(@build_dir) do
......
......@@ -25,83 +25,106 @@ module Bosh::Cli
let(:release_manifest_file) { File.join(workspace_dir, 'release-1.yml') }
let(:release_index) { Versions::VersionsIndex.new(workspace_dir) }
before do
release_manifest = {
let(:original_release_manifest) do
{
'name' => 'fake-release-name',
'version' => 'fake-release-version',
'packages' => [{
'name' => 'fake-package-name',
'version' => 'fake-package-fingerprint',
'sha1' => Digest::SHA1.file(package_tarball).hexdigest,
'fingerpint' => 'fake-package-fingerprint',
'blobstore_id' => 'fake-package-blobstore_id',
}],
'jobs' => [{
'name' => 'fake-job-name',
'version' => 'fake-job-fingerprint',
'sha1' => Digest::SHA1.file(job_tarball).hexdigest,
'fingerpint' => 'fake-job-fingerprint',
'blobstore_id' => 'fake-job-blobstore_id',
}],
'license' => {
'version' => 'fake-license-version',
'sha1' => Digest::SHA1.file(license_tarball).hexdigest,
'fingerprint' => 'fake-license-fingerprint',
'blobstore_id' => 'fake-license-blobstore_id'
}
'version' => 'fake-release-version'
}
File.write(release_manifest_file, YAML.dump(release_manifest))
end
let(:release_manifest) { original_release_manifest }
before do
release_source.add_version(
'fake-package-fingerprint',
'.final_builds/packages/fake-package-name',
File.read(package_tarball),
{
'version' => 'fake-package-fingerprint',
'blobstore_id' => 'fake-package-blobstore_id',
}
)
release_source.add_version(
'fake-job-fingerprint',
'.final_builds/jobs/fake-job-name',
File.read(job_tarball),
{
'version' => 'fake-job-fingerprint',
'blobstore_id' => 'fake-job-blobstore_id',
}
)
release_source.add_version(
'fake-license-fingerprint',
'.final_builds/license',
File.read(license_tarball),
{
'version' => 'fake-license-fingerprint',
'blobstore_id' => 'fake-license-blobstore_id',
}
)
end
before { File.write(release_manifest_file, YAML.dump(release_manifest)) }
describe '#compile' do
let(:release_tarball_file) { File.join(workspace_dir, 'fake-release-name-fake-release-version.tgz') }
it 'copies packages' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./packages/fake-package-name.tgz')
context 'when packages exist' do
before do
release_source.add_version(
'fake-package-fingerprint',
'.final_builds/packages/fake-package-name',
File.read(package_tarball),
{
'version' => 'fake-package-fingerprint',
'blobstore_id' => 'fake-package-blobstore_id',
}
)
end
let(:release_manifest) do
original_release_manifest.merge(
'packages' => [{
'name' => 'fake-package-name',
'version' => 'fake-package-fingerprint',
'sha1' => Digest::SHA1.file(package_tarball).hexdigest,
'fingerpint' => 'fake-package-fingerprint',
'blobstore_id' => 'fake-package-blobstore_id',
}])
end
it 'copies packages' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./packages/fake-package-name.tgz')
end
end
it 'copies jobs' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./jobs/fake-job-name.tgz')
context 'when jobs exist' do
before do
release_source.add_version(
'fake-job-fingerprint',
'.final_builds/jobs/fake-job-name',
File.read(job_tarball),
{
'version' => 'fake-job-fingerprint',
'blobstore_id' => 'fake-job-blobstore_id',
}
)
end
let(:release_manifest) do
original_release_manifest.merge(
'jobs' => [{
'name' => 'fake-job-name',
'version' => 'fake-job-fingerprint',
'sha1' => Digest::SHA1.file(job_tarball).hexdigest,
'fingerpint' => 'fake-job-fingerprint',
'blobstore_id' => 'fake-job-blobstore_id',
}])
end
it 'copies jobs' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./jobs/fake-job-name.tgz')
end
end
it 'copies license' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./license.tgz')
context 'when license exists' do
before do
release_source.add_version(
'fake-license-fingerprint',
'.final_builds/license',
File.read(license_tarball),
{
'version' => 'fake-license-fingerprint',
'blobstore_id' => 'fake-license-blobstore_id',
}
)
end
let(:release_manifest) do
original_release_manifest.merge(
'license' => {
'version' => 'fake-license-version',
'sha1' => Digest::SHA1.file(license_tarball).hexdigest,
'fingerprint' => 'fake-license-fingerprint',
'blobstore_id' => 'fake-license-blobstore_id'
})
end
it 'copies license' do
release_compiler.compile
expect(list_tar_files(release_tarball_file)).to include('./license.tgz')
end
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment