summaryrefslogtreecommitdiff
path: root/spec/initializers/direct_upload_support_spec.rb
blob: 68dd12fdb6e6d5adcfb9a3da7fbdc167359d0ac2 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Direct upload support' do
  subject do
    load Rails.root.join('config/initializers/direct_upload_support.rb')
  end

  where(:config_name) do
    %w(artifacts lfs uploads)
  end

  with_them do
    let(:connection) do
      { provider: provider }
    end

    let(:object_store) do
      {
        enabled: enabled,
        direct_upload: direct_upload,
        connection: connection
      }
    end

    before do
      allow(Gitlab.config).to receive_messages(to_settings(config_name => {
        object_store: object_store
      }))
    end

    context 'when object storage is enabled' do
      let(:enabled) { true }

      context 'when direct upload is enabled' do
        let(:direct_upload) { true }

        context 'when provider is AWS' do
          let(:provider) { 'AWS' }

          it 'succeeds' do
            expect { subject }.not_to raise_error
          end
        end

        context 'when provider is Google' do
          let(:provider) { 'Google' }

          it 'succeeds' do
            expect { subject }.not_to raise_error
          end
        end

        context 'when provider is AzureRM' do
          let(:provider) { 'AzureRM' }

          it 'succeeds' do
            expect { subject }.not_to raise_error
          end
        end

        context 'when connection is empty' do
          let(:connection) { nil }

          it 'raises an error' do
            expect { subject }.to raise_error "No provider configured for '#{config_name}'. Only Google, AWS, and AzureRM are supported."
          end
        end

        context 'when other provider is used' do
          let(:provider) { 'Aliyun' }

          it 'raises an error' do
            expect { subject }.to raise_error /Object storage provider '#{provider}' is not supported when 'direct_upload' is used for '#{config_name}'/
          end
        end

        context 'when connection is omitted' do
          let(:object_store) do
            {
              enabled: enabled,
              direct_upload: direct_upload
            }
          end

          it 'raises an error' do
            expect { subject }.to raise_error /the 'connection' section is missing/
          end
        end
      end

      context 'when direct upload is disabled' do
        let(:direct_upload) { false }
        let(:provider) { 'AWS' }

        it 'succeeds' do
          expect { subject }.not_to raise_error
        end
      end
    end

    context 'when object storage is disabled' do
      let(:enabled) { false }
      let(:direct_upload) { false }
      let(:provider) { 'Aliyun' }

      it 'succeeds' do
        expect { subject }.not_to raise_error
      end
    end
  end
end