Commit baa00d54 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor container registry repository tag stubs

parent 0af4cbc5
...@@ -24,10 +24,11 @@ describe Projects::Registry::RepositoriesController do ...@@ -24,10 +24,11 @@ describe Projects::Registry::RepositoriesController do
end end
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 context 'when there are tags for this repository' do
before do before do
stub_container_registry_tags(%w[rc1 latest]) stub_container_registry_tags(repository: project.full_path,
tags: %w[rc1 latest])
end end
it 'successfully renders container repositories' do it 'successfully renders container repositories' do
...@@ -44,7 +45,7 @@ describe Projects::Registry::RepositoriesController do ...@@ -44,7 +45,7 @@ describe Projects::Registry::RepositoriesController do
context 'when there are no tags for this repository' do context 'when there are no tags for this repository' do
before do before do
stub_container_registry_tags(*[]) stub_container_registry_tags(repository: :any, tags: [])
end end
it 'successfully renders container repositories' do it 'successfully renders container repositories' do
......
...@@ -12,7 +12,7 @@ describe "Container Registry" do ...@@ -12,7 +12,7 @@ describe "Container Registry" do
login_as(user) login_as(user)
project.add_developer(user) project.add_developer(user)
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
stub_container_registry_tags(%w[latest]) stub_container_registry_tags(repository: :any, tags: [])
end end
context 'when there are no image repositories' do context 'when there are no image repositories' do
...@@ -25,6 +25,7 @@ describe "Container Registry" do ...@@ -25,6 +25,7 @@ describe "Container Registry" do
context 'when there are image repositories' do context 'when there are image repositories' do
before do before do
stub_container_registry_tags(repository: %r{my/image}, tags: %w[latest])
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -446,7 +446,7 @@ describe "Internal Project Access", feature: true do ...@@ -446,7 +446,7 @@ describe "Internal Project Access", feature: true do
let(:container_repository) { create(:container_repository) } let(:container_repository) { create(:container_repository) }
before do before do
stub_container_registry_tags('latest') stub_container_registry_tags(repository: :any, tags: ['latest'])
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -435,7 +435,7 @@ describe "Private Project Access", feature: true do ...@@ -435,7 +435,7 @@ describe "Private Project Access", feature: true do
let(:container_repository) { create(:container_repository) } let(:container_repository) { create(:container_repository) }
before do before do
stub_container_registry_tags('latest') stub_container_registry_tags(repository: :any, tags: ['latest'])
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -446,7 +446,7 @@ describe "Public Project Access", feature: true do ...@@ -446,7 +446,7 @@ describe "Public Project Access", feature: true do
let(:container_repository) { create(:container_repository) } let(:container_repository) { create(:container_repository) }
before do before do
stub_container_registry_tags('latest') stub_container_registry_tags(repository: :any, tags:['latest'])
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -153,7 +153,7 @@ describe Namespace, models: true do ...@@ -153,7 +153,7 @@ describe Namespace, models: true do
before do before do
stub_container_registry_config(enabled: true) 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]) create(:empty_project, namespace: @namespace, container_repositories: [container_repository])
......
...@@ -1190,7 +1190,7 @@ describe Project, models: true do ...@@ -1190,7 +1190,7 @@ describe Project, models: true do
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag') stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -94,7 +94,7 @@ describe Projects::DestroyService, services: true do ...@@ -94,7 +94,7 @@ describe Projects::DestroyService, services: true do
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag') stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -33,7 +33,7 @@ describe Projects::TransferService, services: true do ...@@ -33,7 +33,7 @@ describe Projects::TransferService, services: true do
before do before do
stub_container_registry_config(enabled: true) stub_container_registry_config(enabled: true)
stub_container_registry_tags('tag') stub_container_registry_tags(repository: :any, tags: ['tag'])
project.container_repositories << container_repository project.container_repositories << container_repository
end end
......
...@@ -31,20 +31,36 @@ module StubGitlabCalls ...@@ -31,20 +31,36 @@ module StubGitlabCalls
.to receive(:full_access_token).and_return('token') .to receive(:full_access_token).and_return('token')
end 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) 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) allow_any_instance_of(ContainerRegistry::Client)
.to receive(:repository_manifest).and_return( .to receive(:repository_manifest).with(repository)
JSON.parse(File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json'))) .and_return(stub_container_registry_tag_manifest)
allow_any_instance_of(ContainerRegistry::Client).to receive(:blob).and_return( allow_any_instance_of(ContainerRegistry::Client)
File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json')) .to receive(:blob).with(repository)
.and_return(stub_container_registry_blob)
end end
private 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 def gitlab_url
Gitlab.config.gitlab.url Gitlab.config.gitlab.url
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