summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/container_registry_rake_spec.rb
blob: b83ff567126e7845ea0750531073036afb228735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'rake_helper'

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
    subject { run_rake_task('gitlab:container_registry:configure') }

    shared_examples 'invalid config' do
      it 'does not call UpdateContainerRegistryInfoService' do
        expect_any_instance_of(UpdateContainerRegistryInfoService).not_to receive(:execute)

        subject
      end

      it 'does not raise an error' do
        expect { subject }.not_to raise_error
      end

      it 'prints a warning message' do
        expect { subject }.to output("Registry is not enabled or registry api url is not present.\n").to_stdout
      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

    context 'when container registry is enabled and api_url is not blank' do
      before do
        stub_container_registry_config(enabled: true, api_url: api_url)
      end

      it 'calls UpdateContainerRegistryInfoService' do
        expect_next_instance_of(UpdateContainerRegistryInfoService) do |service|
          expect(service).to receive(:execute)
        end

        subject
      end
    end
  end
end