2020-05-22 00:08:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rake_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe 'gitlab:container_registry namespace rake tasks' do
|
2020-06-02 18:08:32 +00:00
|
|
|
let_it_be(:api_url) { 'http://registry.gitlab' }
|
2020-05-22 00:08:07 +00:00
|
|
|
|
|
|
|
before :all do
|
|
|
|
Rake.application.rake_require 'tasks/gitlab/container_registry'
|
|
|
|
end
|
|
|
|
|
2020-07-08 21:09:09 +00:00
|
|
|
describe '#configure' do
|
2020-06-04 00:08:17 +00:00
|
|
|
subject { run_rake_task('gitlab:container_registry:configure') }
|
|
|
|
|
2020-05-22 00:08:07 +00:00
|
|
|
shared_examples 'invalid config' do
|
2020-07-08 21:09:09 +00:00
|
|
|
it 'does not call UpdateContainerRegistryInfoService' do
|
|
|
|
expect_any_instance_of(UpdateContainerRegistryInfoService).not_to receive(:execute)
|
2020-06-04 00:08:17 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise an error' do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prints a warning message' do
|
2020-07-08 21:09:09 +00:00
|
|
|
expect { subject }.to output("Registry is not enabled or registry api url is not present.\n").to_stdout
|
2020-05-22 00:08:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when container registry is disabled' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'invalid config'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when container registry api_url is blank' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(api_url: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'invalid config'
|
|
|
|
end
|
|
|
|
|
2020-07-08 21:09:09 +00:00
|
|
|
context 'when container registry is enabled and api_url is not blank' do
|
2020-06-02 18:08:32 +00:00
|
|
|
before do
|
2020-07-08 21:09:09 +00:00
|
|
|
stub_container_registry_config(enabled: true, api_url: api_url)
|
2020-06-02 18:08:32 +00:00
|
|
|
end
|
2020-05-22 00:08:07 +00:00
|
|
|
|
2020-07-08 21:09:09 +00:00
|
|
|
it 'calls UpdateContainerRegistryInfoService' do
|
|
|
|
expect_next_instance_of(UpdateContainerRegistryInfoService) do |service|
|
|
|
|
expect(service).to receive(:execute)
|
2020-05-22 00:08:07 +00:00
|
|
|
end
|
|
|
|
|
2020-07-08 21:09:09 +00:00
|
|
|
subject
|
2020-05-22 00:08:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|