Skip to content
Snippets Groups Projects
Commit baa00d54 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Refactor container registry repository tag stubs

parent 0af4cbc5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -24,10 +24,11 @@ describe Projects::Registry::RepositoriesController do
end
end
 
context 'when root container repository does not exist' do
context 'when root container repository is not created' do
context 'when there are tags for this repository' do
before do
stub_container_registry_tags(%w[rc1 latest])
stub_container_registry_tags(repository: project.full_path,
tags: %w[rc1 latest])
end
 
it 'successfully renders container repositories' do
Loading
Loading
@@ -44,7 +45,7 @@ describe Projects::Registry::RepositoriesController do
 
context 'when there are no tags for this repository' do
before do
stub_container_registry_tags(*[])
stub_container_registry_tags(repository: :any, tags: [])
end
 
it 'successfully renders container repositories' do
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe "Container Registry" do
login_as(user)
project.add_developer(user)
stub_container_registry_config(enabled: true)
stub_container_registry_tags(%w[latest])
stub_container_registry_tags(repository: :any, tags: [])
end
 
context 'when there are no image repositories' do
Loading
Loading
@@ -25,6 +25,7 @@ describe "Container Registry" do
 
context 'when there are image repositories' do
before do
stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest])
project.container_repositories << container_repository
end
 
Loading
Loading
Loading
Loading
@@ -446,7 +446,7 @@ describe "Internal Project Access", feature: true do
let(:container_repository) { create(:container_repository) }
 
before do
stub_container_registry_tags('latest')
stub_container_registry_tags(repository: :any, tags: ['latest'])
stub_container_registry_config(enabled: true)
project.container_repositories << container_repository
end
Loading
Loading
Loading
Loading
@@ -435,7 +435,7 @@ describe "Private Project Access", feature: true do
let(:container_repository) { create(:container_repository) }
 
before do
stub_container_registry_tags('latest')
stub_container_registry_tags(repository: :any, tags: ['latest'])
stub_container_registry_config(enabled: true)
project.container_repositories << container_repository
end
Loading
Loading
Loading
Loading
@@ -446,7 +446,7 @@ describe "Public Project Access", feature: true do
let(:container_repository) { create(:container_repository) }
 
before do
stub_container_registry_tags('latest')
stub_container_registry_tags(repository: :any, tags:['latest'])
stub_container_registry_config(enabled: true)
project.container_repositories << container_repository
end
Loading
Loading
Loading
Loading
@@ -153,7 +153,7 @@ describe Namespace, models: true do
 
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
stub_container_registry_tags(repository: :any, tags: ['tag'])
 
create(:empty_project, namespace: @namespace, container_repositories: [container_repository])
 
Loading
Loading
Loading
Loading
@@ -1190,7 +1190,7 @@ describe Project, models: true do
 
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository
end
 
Loading
Loading
Loading
Loading
@@ -94,7 +94,7 @@ describe Projects::DestroyService, services: true do
 
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository
end
 
Loading
Loading
Loading
Loading
@@ -33,7 +33,7 @@ describe Projects::TransferService, services: true do
 
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag')
stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository
end
 
Loading
Loading
Loading
Loading
@@ -31,20 +31,36 @@ module StubGitlabCalls
.to receive(:full_access_token).and_return('token')
end
 
def stub_container_registry_tags(*tags)
def stub_container_registry_tags(repository: :any, tags:)
repository = any_args if repository == :any
allow_any_instance_of(ContainerRegistry::Client)
.to receive(:repository_tags).and_return({ 'tags' => tags })
.to receive(:repository_tags).with(repository)
.and_return({ 'tags' => tags })
 
allow_any_instance_of(ContainerRegistry::Client)
.to receive(:repository_manifest).and_return(
JSON.parse(File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json')))
.to receive(:repository_manifest).with(repository)
.and_return(stub_container_registry_tag_manifest)
 
allow_any_instance_of(ContainerRegistry::Client).to receive(:blob).and_return(
File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json'))
allow_any_instance_of(ContainerRegistry::Client)
.to receive(:blob).with(repository)
.and_return(stub_container_registry_blob)
end
 
private
 
def stub_container_registry_tag_manifest
fixture_path = 'spec/fixtures/container_registry/tag_manifest.json'
JSON.parse(File.read(Rails.root + fixture_path))
end
def stub_container_registry_blob
fixture_path = 'spec/fixtures/container_registry/config_blob.json'
File.read(Rails.root + fixture_path)
end
def gitlab_url
Gitlab.config.gitlab.url
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment