2016-05-17 18:20:11 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ContainerRegistry::Tag do
|
2016-12-16 03:24:05 +00:00
|
|
|
let(:group) { create(:group, name: 'group') }
|
2017-08-22 23:19:35 +00:00
|
|
|
let(:project) { create(:project, path: 'test', group: group) }
|
2017-03-24 11:31:34 +00:00
|
|
|
|
|
|
|
let(:repository) do
|
2017-04-03 08:53:16 +00:00
|
|
|
create(:container_repository, name: '', project: project)
|
2017-03-24 11:31:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:headers) do
|
|
|
|
{ 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json' }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:tag) { described_class.new(repository, 'tag') }
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-12-16 03:24:05 +00:00
|
|
|
before do
|
2017-03-24 11:31:34 +00:00
|
|
|
stub_container_registry_config(enabled: true,
|
|
|
|
api_url: 'http://registry.gitlab',
|
|
|
|
host_port: 'registry.gitlab')
|
2016-12-16 03:24:05 +00:00
|
|
|
end
|
|
|
|
|
2016-05-17 18:20:11 +00:00
|
|
|
it { expect(tag).to respond_to(:repository) }
|
|
|
|
it { expect(tag).to delegate_method(:registry).to(:repository) }
|
|
|
|
it { expect(tag).to delegate_method(:client).to(:repository) }
|
|
|
|
|
2017-03-24 11:31:34 +00:00
|
|
|
describe '#path' do
|
|
|
|
context 'when tag belongs to zero-level repository' do
|
|
|
|
let(:repository) do
|
|
|
|
create(:container_repository, name: '',
|
|
|
|
tags: %w[rc1],
|
|
|
|
project: project)
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2017-03-24 11:31:34 +00:00
|
|
|
it 'returns path to the image' do
|
|
|
|
expect(tag.path).to eq('group/test:tag')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when tag belongs to first-level repository' do
|
|
|
|
let(:repository) do
|
|
|
|
create(:container_repository, name: 'my_image',
|
2017-04-03 08:53:16 +00:00
|
|
|
tags: %w[tag],
|
2017-03-24 11:31:34 +00:00
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns path to the image' do
|
|
|
|
expect(tag.path).to eq('group/test/my_image:tag')
|
|
|
|
end
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2017-04-10 11:07:36 +00:00
|
|
|
describe '#location' do
|
|
|
|
it 'returns a full location of the tag' do
|
|
|
|
expect(tag.location)
|
|
|
|
.to eq 'registry.gitlab/group/test:tag'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-17 18:20:11 +00:00
|
|
|
context 'manifest processing' do
|
2016-06-15 10:53:10 +00:00
|
|
|
context 'schema v1' do
|
|
|
|
before do
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
|
|
|
|
.with(headers: headers)
|
|
|
|
.to_return(
|
2016-06-15 10:53:10 +00:00
|
|
|
status: 200,
|
|
|
|
body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest_1.json'),
|
|
|
|
headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v1+prettyjws' })
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
context '#layers' do
|
|
|
|
subject { tag.layers }
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
it { expect(subject.length).to eq(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context '#total_size' do
|
|
|
|
subject { tag.total_size }
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
context 'config processing' do
|
|
|
|
context '#config' do
|
|
|
|
subject { tag.config }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context '#created_at' do
|
|
|
|
subject { tag.created_at }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
context 'schema v2' do
|
2016-05-17 18:20:11 +00:00
|
|
|
before do
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
|
|
|
|
.with(headers: headers)
|
|
|
|
.to_return(
|
2016-05-17 18:20:11 +00:00
|
|
|
status: 200,
|
2016-06-15 10:53:10 +00:00
|
|
|
body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json'),
|
|
|
|
headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' })
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
context '#layers' do
|
|
|
|
subject { tag.layers }
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
it { expect(subject.length).to eq(1) }
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2016-06-15 10:53:10 +00:00
|
|
|
context '#total_size' do
|
|
|
|
subject { tag.total_size }
|
|
|
|
|
|
|
|
it { is_expected.to eq(2319870) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'config processing' do
|
2016-06-30 12:49:58 +00:00
|
|
|
shared_examples 'a processable' do
|
|
|
|
context '#config' do
|
|
|
|
subject { tag.config }
|
2016-06-15 10:53:10 +00:00
|
|
|
|
2016-06-30 12:49:58 +00:00
|
|
|
it { is_expected.not_to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context '#created_at' do
|
|
|
|
subject { tag.created_at }
|
2016-06-15 10:53:10 +00:00
|
|
|
|
2016-06-30 12:49:58 +00:00
|
|
|
it { is_expected.not_to be_nil }
|
|
|
|
end
|
2016-06-15 10:53:10 +00:00
|
|
|
end
|
|
|
|
|
2016-06-30 12:49:58 +00:00
|
|
|
context 'when locally stored' do
|
|
|
|
before do
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac')
|
|
|
|
.with(headers: { 'Accept' => 'application/octet-stream' })
|
|
|
|
.to_return(
|
2016-06-30 12:49:58 +00:00
|
|
|
status: 200,
|
|
|
|
body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a processable'
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
|
2016-06-30 12:49:58 +00:00
|
|
|
context 'when externally stored' do
|
|
|
|
before do
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:d7a513a663c1a6dcdba9ed832ca53c02ac2af0c333322cd6ca92936d1d9917ac')
|
|
|
|
.with(headers: { 'Accept' => 'application/octet-stream' })
|
|
|
|
.to_return(
|
2016-06-30 12:49:58 +00:00
|
|
|
status: 307,
|
|
|
|
headers: { 'Location' => 'http://external.com/blob/file' })
|
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, 'http://external.com/blob/file')
|
|
|
|
.to_return(
|
2016-06-30 12:49:58 +00:00
|
|
|
status: 200,
|
|
|
|
body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a processable'
|
2016-06-15 10:53:10 +00:00
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-03 08:53:16 +00:00
|
|
|
context 'with stubbed digest' do
|
2016-05-17 18:20:11 +00:00
|
|
|
before do
|
2017-04-03 08:53:16 +00:00
|
|
|
stub_request(:head, 'http://registry.gitlab/v2/group/test/manifests/tag')
|
|
|
|
.with(headers: headers)
|
|
|
|
.to_return(status: 200, headers: { 'Docker-Content-Digest' => 'sha256:digest' })
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2017-04-03 08:53:16 +00:00
|
|
|
describe '#digest' do
|
|
|
|
it 'returns a correct tag digest' do
|
|
|
|
expect(tag.digest).to eq 'sha256:digest'
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2017-04-03 08:53:16 +00:00
|
|
|
describe '#delete' do
|
2016-05-17 18:20:11 +00:00
|
|
|
before do
|
2017-04-03 08:53:16 +00:00
|
|
|
stub_request(:delete, 'http://registry.gitlab/v2/group/test/manifests/sha256:digest')
|
|
|
|
.with(headers: headers)
|
|
|
|
.to_return(status: 200)
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
|
2017-04-03 08:53:16 +00:00
|
|
|
it 'correctly deletes the tag' do
|
|
|
|
expect(tag.delete).to be_truthy
|
|
|
|
end
|
2016-05-17 18:20:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|