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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'gitlab:db:lock_writes', :reestablished_active_record_base, feature_category: :cell 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'
end
let(:table_locker) { instance_double(Gitlab::Database::TablesLocker) }
let(:logger) { instance_double(Logger, level: nil) }
let(:dry_run) { false }
let(:verbose) { false }
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|
let(:log_level) { verbose ? Logger::INFO : Logger::WARN }
it "creates TablesLocker with dry run set and calls #{method}" do
expect(logger).to receive(:level=).with(log_level)
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
context 'when environment sets VERBOSE to true' do
let(:verbose) { true }
before do
stub_env('VERBOSE', 'true')
end
include_examples "call table locker", :lock_writes
end
context 'when environment sets VERBOSE to false' do
let(:verbose) { false }
before do
stub_env('VERBOSE', 'false')
end
include_examples "call table locker", :lock_writes
end
context 'when environment does not define VERBOSE' do
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
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
include_examples "call table locker", :unlock_writes
end
context 'when environment sets VERBOSE to true' do
let(:verbose) { true }
before do
stub_env('VERBOSE', 'true')
end
include_examples "call table locker", :lock_writes
end
context 'when environment sets VERBOSE to false' do
let(:verbose) { false }
before do
stub_env('VERBOSE', 'false')
end
include_examples "call table locker", :lock_writes
end
context 'when environment does not define VERBOSE' do
include_examples "call table locker", :lock_writes
end
end
end
|