summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/container_registry_rake_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/tasks/gitlab/container_registry_rake_spec.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/tasks/gitlab/container_registry_rake_spec.rb')
-rw-r--r--spec/tasks/gitlab/container_registry_rake_spec.rb84
1 files changed, 11 insertions, 73 deletions
diff --git a/spec/tasks/gitlab/container_registry_rake_spec.rb b/spec/tasks/gitlab/container_registry_rake_spec.rb
index 181d5c8b7c8..b83ff567126 100644
--- a/spec/tasks/gitlab/container_registry_rake_spec.rb
+++ b/spec/tasks/gitlab/container_registry_rake_spec.rb
@@ -2,25 +2,19 @@
require 'rake_helper'
-describe 'gitlab:container_registry namespace rake tasks' do
- let_it_be(:application_settings) { Gitlab::CurrentSettings }
+RSpec.describe 'gitlab:container_registry namespace rake tasks' do
let_it_be(:api_url) { 'http://registry.gitlab' }
before :all do
Rake.application.rake_require 'tasks/gitlab/container_registry'
end
- describe 'configure' do
- before do
- stub_access_token
- stub_container_registry_config(enabled: true, api_url: api_url)
- end
-
+ describe '#configure' do
subject { run_rake_task('gitlab:container_registry:configure') }
shared_examples 'invalid config' do
- it 'does not update the application settings' do
- expect(application_settings).not_to receive(:update!)
+ it 'does not call UpdateContainerRegistryInfoService' do
+ expect_any_instance_of(UpdateContainerRegistryInfoService).not_to receive(:execute)
subject
end
@@ -30,7 +24,7 @@ describe 'gitlab:container_registry namespace rake tasks' do
end
it 'prints a warning message' do
- expect { subject }.to output(/Registry is not enabled or registry api url is not present./).to_stdout
+ expect { subject }.to output("Registry is not enabled or registry api url is not present.\n").to_stdout
end
end
@@ -50,74 +44,18 @@ describe 'gitlab:container_registry namespace rake tasks' do
it_behaves_like 'invalid config'
end
- context 'when creating a registry client instance' do
- let(:token) { 'foo' }
- let(:client) { ContainerRegistry::Client.new(api_url, token: token) }
-
+ context 'when container registry is enabled and api_url is not blank' do
before do
- stub_registry_info({})
- end
-
- it 'uses a token with no access permissions' do
- expect(Auth::ContainerRegistryAuthenticationService)
- .to receive(:access_token).with([], []).and_return(token)
- expect(ContainerRegistry::Client)
- .to receive(:new).with(api_url, token: token).and_return(client)
-
- run_rake_task('gitlab:container_registry:configure')
+ stub_container_registry_config(enabled: true, api_url: api_url)
end
- end
-
- context 'when unabled to detect the container registry type' do
- it 'fails and raises an error message' do
- stub_registry_info({})
-
- run_rake_task('gitlab:container_registry:configure')
-
- application_settings.reload
- expect(application_settings.container_registry_vendor).to be_blank
- expect(application_settings.container_registry_version).to be_blank
- expect(application_settings.container_registry_features).to eq([])
- end
- end
- context 'when able to detect the container registry type' do
- context 'when using the GitLab container registry' do
- it 'updates application settings accordingly' do
- stub_registry_info(vendor: 'gitlab', version: '2.9.1-gitlab', features: %w[a,b,c])
-
- run_rake_task('gitlab:container_registry:configure')
-
- application_settings.reload
- expect(application_settings.container_registry_vendor).to eq('gitlab')
- expect(application_settings.container_registry_version).to eq('2.9.1-gitlab')
- expect(application_settings.container_registry_features).to eq(%w[a,b,c])
+ it 'calls UpdateContainerRegistryInfoService' do
+ expect_next_instance_of(UpdateContainerRegistryInfoService) do |service|
+ expect(service).to receive(:execute)
end
- end
- context 'when using a third-party container registry' do
- it 'updates application settings accordingly' do
- stub_registry_info(vendor: 'other', version: nil, features: nil)
-
- run_rake_task('gitlab:container_registry:configure')
-
- application_settings.reload
- expect(application_settings.container_registry_vendor).to eq('other')
- expect(application_settings.container_registry_version).to be_blank
- expect(application_settings.container_registry_features).to eq([])
- end
+ subject
end
end
end
-
- def stub_access_token
- allow(Auth::ContainerRegistryAuthenticationService)
- .to receive(:access_token).with([], []).and_return('foo')
- end
-
- def stub_registry_info(output)
- allow_next_instance_of(ContainerRegistry::Client) do |client|
- allow(client).to receive(:registry_info).and_return(output)
- end
- end
end