summaryrefslogtreecommitdiff
path: root/spec/lib/container_registry/client_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/container_registry/client_spec.rb')
-rw-r--r--spec/lib/container_registry/client_spec.rb94
1 files changed, 54 insertions, 40 deletions
diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb
index 9d6f4db537d..47a8fcf5dd0 100644
--- a/spec/lib/container_registry/client_spec.rb
+++ b/spec/lib/container_registry/client_spec.rb
@@ -111,6 +111,49 @@ RSpec.describe ContainerRegistry::Client do
it_behaves_like 'handling timeouts'
end
+ shared_examples 'handling repository info' do
+ context 'when the check is successful' do
+ context 'when using the GitLab container registry' do
+ before do
+ stub_registry_info(headers: {
+ 'GitLab-Container-Registry-Version' => '2.9.1-gitlab',
+ 'GitLab-Container-Registry-Features' => 'a,b,c'
+ })
+ end
+
+ it 'identifies the vendor as "gitlab"' do
+ expect(subject).to include(vendor: 'gitlab')
+ end
+
+ it 'identifies version and features' do
+ expect(subject).to include(version: '2.9.1-gitlab', features: %w[a b c])
+ end
+ end
+
+ context 'when using a third-party container registry' do
+ before do
+ stub_registry_info
+ end
+
+ it 'identifies the vendor as "other"' do
+ expect(subject).to include(vendor: 'other')
+ end
+
+ it 'does not identify version or features' do
+ expect(subject).to include(version: nil, features: [])
+ end
+ end
+ end
+
+ context 'when the check is not successful' do
+ it 'does not identify vendor, version or features' do
+ stub_registry_info(status: 500)
+
+ expect(subject).to eq({})
+ end
+ end
+ end
+
describe '#repository_manifest' do
subject { client.repository_manifest('group/test', 'mytag') }
@@ -316,46 +359,7 @@ RSpec.describe ContainerRegistry::Client do
describe '#registry_info' do
subject { client.registry_info }
- context 'when the check is successful' do
- context 'when using the GitLab container registry' do
- before do
- stub_registry_info(headers: {
- 'GitLab-Container-Registry-Version' => '2.9.1-gitlab',
- 'GitLab-Container-Registry-Features' => 'a,b,c'
- })
- end
-
- it 'identifies the vendor as "gitlab"' do
- expect(subject).to include(vendor: 'gitlab')
- end
-
- it 'identifies version and features' do
- expect(subject).to include(version: '2.9.1-gitlab', features: %w[a b c])
- end
- end
-
- context 'when using a third-party container registry' do
- before do
- stub_registry_info
- end
-
- it 'identifies the vendor as "other"' do
- expect(subject).to include(vendor: 'other')
- end
-
- it 'does not identify version or features' do
- expect(subject).to include(version: nil, features: [])
- end
- end
- end
-
- context 'when the check is not successful' do
- it 'does not identify vendor, version or features' do
- stub_registry_info(status: 500)
-
- expect(subject).to eq({})
- end
- end
+ it_behaves_like 'handling repository info'
end
describe '.supports_tag_delete?' do
@@ -418,6 +422,16 @@ RSpec.describe ContainerRegistry::Client do
end
end
+ describe '.registry_info' do
+ subject { described_class.registry_info }
+
+ before do
+ stub_container_registry_config(enabled: true, api_url: registry_api_url, key: 'spec/fixtures/x509_certificate_pk.key')
+ end
+
+ it_behaves_like 'handling repository info'
+ end
+
def stub_upload(path, content, digest, status = 200)
stub_request(:post, "#{registry_api_url}/v2/#{path}/blobs/uploads/")
.with(headers: headers_with_accept_types)