Commit 662d2e68 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor feature specs for container registry

parent fc550b39
...@@ -29,6 +29,6 @@ ...@@ -29,6 +29,6 @@
= link_to namespace_project_registry_repository_tag_path(@project.namespace, @project, tag.repository, tag.name), = link_to namespace_project_registry_repository_tag_path(@project.namespace, @project, tag.repository, tag.name),
method: :delete, method: :delete,
class: 'btn btn-remove has-tooltip', class: 'btn btn-remove has-tooltip',
title: 'Remove image tag', title: 'Remove tag',
data: { confirm: notice } do data: { confirm: notice } do
= icon('trash cred') = icon('trash cred')
require 'spec_helper' require 'spec_helper'
describe "Container Registry" do describe "Container Registry" do
let(:user) { create(:user) }
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:registry) { project.container_registry }
let(:tag_name) { 'latest' }
let(:tags) { [tag_name] }
let(:container_repository) { create(:container_repository) }
let(:image_name) { container_repository.name }
before do let(:container_repository) do
login_as(:user) create(:container_repository, name: 'my/image')
project.team << [@user, :developer]
stub_container_registry_config(enabled: true)
stub_container_registry_tags(*tags)
project.container_repositories << container_repository unless container_repository.nil?
end end
describe 'GET /:project/container_registry' do
before do before do
visit namespace_project_container_registry_index_path(project.namespace, project) login_as(user)
project.add_developer(user)
stub_container_registry_config(enabled: true)
stub_container_registry_tags(%w[latest])
end end
context 'when no images' do context 'when there are no image repositories' do
let(:container_repository) { } scenario 'user visits container registry main page' do
visit_container_registry
it { expect(page).to have_content('No container images in Container Registry for this project') } expect(page).to have_content 'No container images'
end
context 'when there are images' do
it { expect(page).to have_content(image_name) }
end end
end end
describe 'DELETE /:project/container_registry/:image_id' do context 'when there are image repositories' do
before do before do
visit namespace_project_container_registry_index_path(project.namespace, project) project.container_repositories << container_repository
end
scenario 'user wants to see multi-level container repository' do
visit_container_registry
expect(page).to have_content('my/image')
end end
it do scenario 'user removes entire container repository' do
visit_container_registry
expect_any_instance_of(ContainerRepository) expect_any_instance_of(ContainerRepository)
.to receive(:delete_tags!).and_return(true) .to receive(:delete_tags!).and_return(true)
click_on 'Remove image' click_on 'Remove repository'
end
end end
describe 'DELETE /:project/container_registry/tag' do scenario 'user removes a specific tag from container repository' do
before do visit_container_registry
visit namespace_project_container_registry_index_path(project.namespace, project)
end
it do expect_any_instance_of(ContainerRegistry::Tag)
expect_any_instance_of(::ContainerRegistry::Tag).to receive(:delete).and_return(true) .to receive(:delete).and_return(true)
click_on 'Remove tag' click_on 'Remove tag'
end end
end end
def visit_container_registry
visit namespace_project_container_registry_index_path(
project.namespace, project)
end
end end
...@@ -32,15 +32,15 @@ module StubGitlabCalls ...@@ -32,15 +32,15 @@ module StubGitlabCalls
end end
def stub_container_registry_tags(*tags) def stub_container_registry_tags(*tags)
allow_any_instance_of(ContainerRegistry::Client).to receive(:repository_tags).and_return( allow_any_instance_of(ContainerRegistry::Client)
{ "tags" => tags } .to receive(:repository_tags).and_return({ 'tags' => tags })
)
allow_any_instance_of(ContainerRegistry::Client).to receive(:repository_manifest).and_return( allow_any_instance_of(ContainerRegistry::Client)
JSON.parse(File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json')) .to receive(:repository_manifest).and_return(
) JSON.parse(File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest.json')))
allow_any_instance_of(ContainerRegistry::Client).to receive(:blob).and_return( allow_any_instance_of(ContainerRegistry::Client).to receive(:blob).and_return(
File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json') File.read(Rails.root + 'spec/fixtures/container_registry/config_blob.json'))
)
end end
private private
......
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