Welcome to mirror list, hosted at ThFree Co, Russian Federation.

options_spec.rb « backup « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 970eea134ddab6e74b2c3ffe1c96b9c585cc12bc (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Backup::Options, feature_category: :backup_restore do
  include StubENV

  subject(:options) { described_class.new }

  context 'with accessors' do
    describe 'backup_id' do
      it { is_expected.to respond_to :backup_id }
      it { is_expected.to respond_to :backup_id= }
    end

    describe 'previous_backup' do
      it { is_expected.to respond_to :previous_backup }
      it { is_expected.to respond_to :previous_backup= }
    end

    describe 'incremental' do
      it { is_expected.to respond_to :incremental }
      it { is_expected.to respond_to :incremental= }
    end

    describe 'force' do
      it { is_expected.to respond_to :force }
      it { is_expected.to respond_to :force= }
    end

    describe 'skippable_tasks' do
      it { is_expected.to respond_to :skippable_tasks }
      it { is_expected.to respond_to :skippable_tasks= }
    end

    describe 'skippable_operations' do
      it { is_expected.to respond_to :skippable_operations }
      it { is_expected.to respond_to :skippable_operations= }
    end

    describe 'max_parallelism' do
      it { is_expected.to respond_to :max_parallelism }
      it { is_expected.to respond_to :max_parallelism= }
    end

    describe 'max_storage_parallelism' do
      it { is_expected.to respond_to :max_storage_parallelism }
      it { is_expected.to respond_to :max_storage_parallelism= }
    end

    describe 'repositories_storages' do
      it { is_expected.to respond_to :repositories_storages }
      it { is_expected.to respond_to :repositories_storages= }
    end

    describe 'repositories_paths' do
      it { is_expected.to respond_to :repositories_paths }
      it { is_expected.to respond_to :repositories_paths= }
    end

    describe 'skip_repositories_paths' do
      it { is_expected.to respond_to :skip_repositories_paths }
      it { is_expected.to respond_to :skip_repositories_paths= }
    end

    describe 'repositories_server_side_backup' do
      it { is_expected.to respond_to :repositories_server_side_backup }
      it { is_expected.to respond_to :repositories_server_side_backup= }
    end

    describe 'remote_directory' do
      it { is_expected.to respond_to :remote_directory }
      it { is_expected.to respond_to :remote_directory= }
    end

    describe 'compression_options' do
      it { is_expected.to respond_to :compression_options }
      it { is_expected.to respond_to :compression_options= }
    end

    describe 'gzip_rsyncable' do
      it { is_expected.to respond_to :gzip_rsyncable }
      it { is_expected.to respond_to :gzip_rsyncable= }
    end
  end

  describe '#initialize' do
    it 'can be initialized without providing any parameter' do
      expect { described_class.new }.not_to raise_exception
    end

    it 'can be initialized with all valid parameters' do
      expect { FactoryBot.build(:backup_options, :all) }.not_to raise_exception
    end
  end

  describe '#extract_from_env!' do
    it 'extracts BACKUP env' do
      env_value = '11493107454_2018_04_25_10.6.4-ce'
      stub_env('BACKUP' => env_value)

      expect { options.extract_from_env! }.to change { options.backup_id }.to(env_value)
    end

    it 'extracts PREVIOUS_BACKUP env' do
      env_value = '11493107454_2018_04_25_10.6.4-ce'
      stub_env('PREVIOUS_BACKUP' => env_value)

      expect { options.extract_from_env! }.to change { options.previous_backup }.to(env_value)
    end

    it 'extracts INCREMENTAL env' do
      stub_env('INCREMENTAL' => 'yes')

      expect { options.extract_from_env! }.to change { options.incremental }.to(true)
    end

    it 'extracts FORCE env' do
      stub_env('FORCE' => 'yes')

      expect { options.extract_from_env! }.to change { options.force }.to(true)
    end

    it 'extracts GITLAB_BACKUP_MAX_CONCURRENCY env' do
      stub_env('GITLAB_BACKUP_MAX_CONCURRENCY' => '8')

      expect { options.extract_from_env! }.to change { options.max_parallelism }.to(8)
    end

    it 'extracts GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY env' do
      stub_env('GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY' => '3')

      expect { options.extract_from_env! }.to change { options.max_storage_parallelism }.to(3)
    end

    it 'extracts DIRECTORY env' do
      directory = 'daily'
      stub_env('DIRECTORY' => directory)

      expect { options.extract_from_env! }.to change { options.remote_directory }.to(directory)
    end

    it 'extracts REPOSITORIES_SERVER_SIDE env' do
      stub_env('REPOSITORIES_SERVER_SIDE' => 'yes')

      expect { options.extract_from_env! }.to change { options.repositories_server_side_backup }.to(true)
    end

    it 'extracts REPOSITORIES_STORAGES env' do
      stub_env('REPOSITORIES_STORAGES' => 'storage1,storage2')

      expect { options.extract_from_env! }.to change { options.repositories_storages }.to(%w[storage1 storage2])
    end

    it 'extracts REPOSITORIES_PATHS env' do
      stub_env('REPOSITORIES_PATHS' => 'group-a,group-b/project-c')

      expect { options.extract_from_env! }.to change { options.repositories_paths }.to(%w[group-a group-b/project-c])
    end

    it 'extracts SKIP_REPOSITORIES_PATHS env' do
      stub_env('SKIP_REPOSITORIES_PATHS' => 'group-a/project-d,group-a/project-e')

      expect { options.extract_from_env! }.to change {
                                                options.skip_repositories_paths
                                              }.to(%w[group-a/project-d group-a/project-e])
    end

    it 'extracts COMPRESS_CMD env' do
      cmd = 'pigz --compress --stdout --fast --processes=4'
      stub_env('COMPRESS_CMD' => cmd)

      expect { options.extract_from_env! }.to change { options.compression_options.compression_cmd }.to(cmd)
    end

    it 'extracts DECOMPRESS_CMD env' do
      cmd = 'pigz --decompress --stdout"'
      stub_env('DECOMPRESS_CMD' => cmd)

      expect { options.extract_from_env! }.to change { options.compression_options.decompression_cmd }.to(cmd)
    end

    it 'extracts GZIP_RSYNCABLE env' do
      stub_env('GZIP_RSYNCABLE' => 'yes')

      expect { options.extract_from_env! }.to change { options.gzip_rsyncable }.to(true)
    end

    it 'delegates to extract_skippables! when SKIP env is present' do
      stub_env('SKIP' => 'db')
      expect(options).to receive(:extract_skippables!)

      options.extract_from_env!
    end

    it 'does not call extract_skippables! when SKIP env is missing' do
      stub_env('SKIP' => nil)
      expect(options).not_to receive(:extract_skippables!)

      options.extract_from_env!
    end
  end

  describe '#extract_skippables!' do
    let(:skippable_field) do
      'tar,remote,db,uploads,builds,artifacts,lfs,terraform_state,registry,pages,repositories,packages,ci_secure_files'
    end

    context 'for skippable operations' do
      it 'parses skippable tar input' do
        expect do
          options.extract_skippables!(skippable_field)
        end.to change { options.skippable_operations.archive }.to(true)
      end

      it 'parses skippable remote input' do
        expect do
          options.extract_skippables!(skippable_field)
        end.to change { options.skippable_operations.remote_storage }.to(true)
      end
    end

    context 'for skippable tasks' do
      it 'parses skippable db input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.db }.to(true)
      end

      it 'parses skippable uploads input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.uploads }.to(true)
      end

      it 'parses skippable builds input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.builds }.to(true)
      end

      it 'parses skippable artifacts input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.artifacts }.to(true)
      end

      it 'parses skippable lfs input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.lfs }.to(true)
      end

      it 'parses skippable terraform_state input' do
        expect do
          options.extract_skippables!(skippable_field)
        end.to change { options.skippable_tasks.terraform_state }.to(true)
      end

      it 'parses skippable registry input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.registry }.to(true)
      end

      it 'parses skippable pages input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.pages }.to(true)
      end

      it 'parses skippable repositories input' do
        expect do
          options.extract_skippables!(skippable_field)
        end.to change { options.skippable_tasks.repositories }.to(true)
      end

      it 'parses skippable packages input' do
        expect { options.extract_skippables!(skippable_field) }.to change { options.skippable_tasks.packages }.to(true)
      end

      it 'parses skippable ci_secure_files input' do
        expect do
          options.extract_skippables!(skippable_field)
        end.to change { options.skippable_tasks.ci_secure_files }.to(true)
      end
    end
  end
end