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
|
# frozen_string_literal: true
require 'rake_helper'
RSpec.describe 'gitlab:db:lock_writes', :reestablished_active_record_base, feature_category: :pods do
before :all do
Rake.application.rake_require 'active_record/railties/databases'
Rake.application.rake_require 'tasks/seed_fu'
Rake.application.rake_require 'tasks/gitlab/db/validate_config'
Rake.application.rake_require 'tasks/gitlab/db/lock_writes'
# empty task as env is already loaded
Rake::Task.define_task :environment
end
let(:table_locker) { instance_double(Gitlab::Database::TablesLocker) }
let(:logger) { instance_double(Logger) }
before do
allow(Logger).to receive(:new).with($stdout).and_return(logger)
allow(Gitlab::Database::TablesLocker).to receive(:new).with(
logger: logger, dry_run: dry_run
).and_return(table_locker)
end
shared_examples "call table locker" do |method|
it "creates TablesLocker with dry run set and calls #{method}" do
expect(table_locker).to receive(method)
run_rake_task("gitlab:db:#{method}")
end
end
describe 'lock_writes' do
context 'when environment sets DRY_RUN to true' do
let(:dry_run) { true }
before do
stub_env('DRY_RUN', 'true')
end
include_examples "call table locker", :lock_writes
end
context 'when environment sets DRY_RUN to false' do
let(:dry_run) { false }
before do
stub_env('DRY_RUN', 'false')
end
include_examples "call table locker", :lock_writes
end
context 'when environment does not define DRY_RUN' do
let(:dry_run) { false }
include_examples "call table locker", :lock_writes
end
end
describe 'unlock_writes' do
context 'when environment sets DRY_RUN to true' do
let(:dry_run) { true }
before do
stub_env('DRY_RUN', 'true')
end
include_examples "call table locker", :unlock_writes
end
context 'when environment sets DRY_RUN to false' do
let(:dry_run) { false }
before do
stub_env('DRY_RUN', 'false')
end
include_examples "call table locker", :unlock_writes
end
context 'when environment does not define DRY_RUN' do
let(:dry_run) { false }
include_examples "call table locker", :unlock_writes
end
end
end
|