2016-01-04 07:08:49 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Ci::Build::Artifacts::Metadata do
|
2016-01-20 15:48:22 -05:00
|
|
|
def metadata(path = '', **opts)
|
|
|
|
described_class.new(metadata_file_path, path, **opts)
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:metadata_file_path) do
|
|
|
|
Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'metadata file exists' do
|
2016-01-13 16:31:27 -05:00
|
|
|
describe '#find_entries! empty string' do
|
|
|
|
subject { metadata('').find_entries! }
|
2016-01-04 07:08:49 -05:00
|
|
|
|
|
|
|
it 'matches correct paths' do
|
2016-01-13 17:24:28 -05:00
|
|
|
expect(subject.keys).to contain_exactly 'ci_artifacts.txt',
|
|
|
|
'other_artifacts_0.1.2/',
|
|
|
|
'rails_sample.jpg',
|
|
|
|
'tests_encoding/'
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches metadata for every path' do
|
2016-01-13 17:24:28 -05:00
|
|
|
expect(subject.keys.count).to eq 4
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'return Hashes for each metadata' do
|
2016-01-13 17:24:28 -05:00
|
|
|
expect(subject.values).to all(be_kind_of(Hash))
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 16:31:27 -05:00
|
|
|
describe '#find_entries! other_artifacts_0.1.2/' do
|
|
|
|
subject { metadata('other_artifacts_0.1.2/').find_entries! }
|
2016-01-04 07:08:49 -05:00
|
|
|
|
|
|
|
it 'matches correct paths' do
|
2016-01-13 17:24:28 -05:00
|
|
|
expect(subject.keys).
|
2016-01-04 08:00:49 -05:00
|
|
|
to contain_exactly 'other_artifacts_0.1.2/',
|
|
|
|
'other_artifacts_0.1.2/doc_sample.txt',
|
2016-01-04 07:08:49 -05:00
|
|
|
'other_artifacts_0.1.2/another-subdirectory/'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 16:31:27 -05:00
|
|
|
describe '#find_entries! other_artifacts_0.1.2/another-subdirectory/' do
|
|
|
|
subject { metadata('other_artifacts_0.1.2/another-subdirectory/').find_entries! }
|
2016-01-04 07:08:49 -05:00
|
|
|
|
|
|
|
it 'matches correct paths' do
|
2016-01-13 17:24:28 -05:00
|
|
|
expect(subject.keys).
|
2016-01-04 08:00:49 -05:00
|
|
|
to contain_exactly 'other_artifacts_0.1.2/another-subdirectory/',
|
2016-01-20 15:48:22 -05:00
|
|
|
'other_artifacts_0.1.2/another-subdirectory/empty_directory/',
|
|
|
|
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#find_entries! recursively for other_artifacts_0.1.2/' do
|
|
|
|
subject { metadata('other_artifacts_0.1.2/', recursive: true).find_entries! }
|
|
|
|
|
|
|
|
it 'matches correct paths' do
|
|
|
|
expect(subject.keys).
|
|
|
|
to contain_exactly 'other_artifacts_0.1.2/',
|
|
|
|
'other_artifacts_0.1.2/doc_sample.txt',
|
|
|
|
'other_artifacts_0.1.2/another-subdirectory/',
|
2016-01-04 08:00:49 -05:00
|
|
|
'other_artifacts_0.1.2/another-subdirectory/empty_directory/',
|
2016-01-04 07:08:49 -05:00
|
|
|
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 15:17:28 -05:00
|
|
|
describe '#to_entry' do
|
|
|
|
subject { metadata('').to_entry }
|
|
|
|
it { is_expected.to be_an_instance_of(Gitlab::Ci::Build::Artifacts::Metadata::Entry) }
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
2016-01-08 06:35:49 -05:00
|
|
|
|
|
|
|
describe '#full_version' do
|
|
|
|
subject { metadata('').full_version }
|
|
|
|
it { is_expected.to eq 'GitLab Build Artifacts Metadata 0.0.1' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#version' do
|
|
|
|
subject { metadata('').version }
|
|
|
|
it { is_expected.to eq '0.0.1' }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
subject { metadata('').errors }
|
|
|
|
it { is_expected.to eq({}) }
|
|
|
|
end
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'metadata file does not exist' do
|
|
|
|
let(:metadata_file_path) { '' }
|
|
|
|
|
2016-01-13 16:31:27 -05:00
|
|
|
describe '#find_entries!' do
|
2016-01-04 07:08:49 -05:00
|
|
|
it 'raises error' do
|
2016-01-13 16:31:27 -05:00
|
|
|
expect { metadata.find_entries! }.to raise_error(Errno::ENOENT)
|
2016-01-04 07:08:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|