nginx_utils 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/nginx_utils +6 -0
- data/lib/nginx_utils/cli.rb +36 -0
- data/lib/nginx_utils/logreader.rb +2 -2
- data/lib/nginx_utils/logrotate.rb +67 -115
- data/lib/nginx_utils/version.rb +1 -1
- data/lib/nginx_utils.rb +2 -0
- data/nginx_utils.gemspec +1 -1
- data/spec/nginx_utils/cli_spec.rb +114 -0
- data/spec/nginx_utils/logreader_spec.rb +112 -107
- data/spec/nginx_utils/logrotate_spec.rb +272 -306
- data/spec/nginx_utils/status_spec.rb +13 -15
- data/spec/spec_helper.rb +0 -1
- metadata +23 -22
- data/bin/nginx_logrotate +0 -29
- data/bin/nginx_status +0 -35
@@ -2,380 +2,346 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe NginxUtils do
|
6
|
-
|
7
|
-
|
8
|
-
def create_files
|
9
|
-
root_dir = "/usr/local/nginx/logs"
|
10
|
-
FileUtils.mkdir_p root_dir
|
11
|
-
FileUtils.mkdir_p "/tmp"
|
12
|
-
not_del = Time.now - (89 * 3600 * 24)
|
13
|
-
do_del = Time.now - (91 * 3600 * 24)
|
14
|
-
not_del_file = "access.log.#{not_del.strftime('%Y%m%d%H%M%S')}"
|
15
|
-
do_del_file = "access.log.#{do_del.strftime('%Y%m%d%H%M%S')}"
|
16
|
-
[
|
17
|
-
"access.log",
|
18
|
-
"error.log",
|
19
|
-
"nginx.pid",
|
20
|
-
not_del_file,
|
21
|
-
do_del_file
|
22
|
-
].each{|f| File.open(File.join(root_dir, f), "w").close}
|
23
|
-
File.utime(not_del, not_del, File.join(root_dir, not_del_file))
|
24
|
-
File.utime(do_del, do_del, File.join(root_dir, do_del_file))
|
25
|
-
{
|
26
|
-
not_del_file: File.join(root_dir, not_del_file),
|
27
|
-
do_del_file: File.join(root_dir, do_del_file)
|
28
|
-
}
|
29
|
-
end
|
5
|
+
describe "NginxUtils::Logrotate" do
|
6
|
+
let(:rotate) {NginxUtils::Logrotate.new}
|
30
7
|
|
31
|
-
|
32
|
-
|
8
|
+
let!(:logger_mock) do
|
9
|
+
logger = double("logger mock").as_null_object
|
10
|
+
Logger.stub(:new).and_return(logger)
|
11
|
+
logger
|
33
12
|
end
|
34
13
|
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
let!(:files) {["access.log", "error.log"]}
|
15
|
+
let!(:time_now) {Time.now}
|
16
|
+
let!(:default) do
|
17
|
+
{
|
18
|
+
debug: false,
|
19
|
+
script_log: "/tmp/nginx_rotate.log",
|
20
|
+
log_level: :debug,
|
21
|
+
root_dir: "/usr/local/nginx",
|
22
|
+
target_logs: "*.log",
|
23
|
+
retention: 90,
|
24
|
+
prefix: time_now.strftime("%Y%m%d%H%M%S"),
|
25
|
+
pid_file: "/usr/local/nginx/logs/nginx.pid"
|
26
|
+
}
|
38
27
|
end
|
39
28
|
|
40
|
-
describe "
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Time.stub(:now).and_return(@time_now)
|
45
|
-
@rotate = NginxUtils::Logrotate.new(script_log: @script_log)
|
46
|
-
end
|
29
|
+
describe "#initialize" do
|
30
|
+
context "with default params" do
|
31
|
+
let(:params) {rotate.instance_eval{@params}}
|
32
|
+
let(:execute) {rotate.instance_eval{@execute}}
|
47
33
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
it "@logger should be a instance of Logger class" do
|
54
|
-
expect(@rotate.instance_eval{@logger}.is_a? Logger).to eq(true)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "@logger.level should be debug(0)" do
|
58
|
-
expect(@rotate.instance_eval{@logger}.level).to eq(Logger::DEBUG)
|
59
|
-
end
|
34
|
+
it "@execute should be true" do
|
35
|
+
expect(execute).to eq(true)
|
36
|
+
end
|
60
37
|
|
61
|
-
|
62
|
-
|
63
|
-
|
38
|
+
it "@logger should be created" do
|
39
|
+
Logger.should_receive(:new).with(default[:script_log])
|
40
|
+
rotate
|
41
|
+
end
|
64
42
|
|
65
|
-
|
66
|
-
|
67
|
-
|
43
|
+
it "@logger.level should be debug" do
|
44
|
+
logger_mock.should_receive(:level=).with(Logger::DEBUG)
|
45
|
+
rotate
|
46
|
+
end
|
68
47
|
|
69
|
-
|
70
|
-
|
71
|
-
|
48
|
+
it "@params[:root_dir] should be default install prefix of Nginx" do
|
49
|
+
expect(params[:root_dir]).to eq(default[:root_dir])
|
50
|
+
end
|
72
51
|
|
73
|
-
|
74
|
-
|
75
|
-
|
52
|
+
it "@params[:target_logs] should be *.log" do
|
53
|
+
expect(params[:target_logs]).to eq(default[:target_logs])
|
54
|
+
end
|
76
55
|
|
77
|
-
|
78
|
-
|
79
|
-
|
56
|
+
it "@rename_logs size should be number of target log files" do
|
57
|
+
Dir.should_receive(:glob).exactly(2).times.and_return(files)
|
58
|
+
expect(rotate.rename_logs).to eq(files)
|
59
|
+
end
|
80
60
|
|
81
|
-
|
82
|
-
|
83
|
-
|
61
|
+
it "@delete_logs size should be number of target log files" do
|
62
|
+
Dir.should_receive(:glob).exactly(2).times.and_return(files)
|
63
|
+
expect(rotate.delete_logs).to eq(files)
|
64
|
+
end
|
84
65
|
|
85
|
-
|
86
|
-
|
87
|
-
|
66
|
+
it "@params[:prefix] should be a some as time_now" do
|
67
|
+
Time.stub(:now).and_return(time_now)
|
68
|
+
expect(params[:prefix]).to eq(default[:prefix])
|
69
|
+
end
|
88
70
|
|
89
|
-
|
90
|
-
|
91
|
-
|
71
|
+
it "@params[:retention] should be 90 days" do
|
72
|
+
expect(params[:retention]).to eq(default[:retention])
|
73
|
+
end
|
92
74
|
|
93
|
-
|
94
|
-
|
95
|
-
end
|
75
|
+
it "@params[:pid_file] should be /usr/local/nginx/logs/nginx.pid" do
|
76
|
+
expect(params[:pid_file]).to eq(default[:pid_file])
|
96
77
|
end
|
97
78
|
|
98
|
-
|
99
|
-
|
100
|
-
@rotate = NginxUtils::Logrotate.new(debug: true, script_log: @script_log)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "@execute should be false" do
|
104
|
-
expect(@rotate.instance_eval{@execute}).to eq(false)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "@logger should be a instance of Logger class" do
|
108
|
-
expect(@rotate.instance_eval{@logger}.is_a? Logger).to eq(true)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "other parameters should be default" do
|
112
|
-
expect(@rotate.instance_eval{@logger}.level).to eq(Logger::DEBUG)
|
113
|
-
expect(@rotate.instance_eval{@root_dir}).to eq("/usr/local/nginx")
|
114
|
-
expect(@rotate.instance_eval{@target_logs}).to eq("*.log")
|
115
|
-
expect(@rotate.instance_eval{@prefix}).to eq(@time_now.strftime("%Y%m%d%H%M%S"))
|
116
|
-
expect(@rotate.instance_eval{@retention}).to eq(@time_now - (90 * 3600 * 24))
|
117
|
-
expect(@rotate.instance_eval{@pid_file}).to eq("/usr/local/nginx/logs/nginx.pid")
|
118
|
-
end
|
79
|
+
it "@rename_logs should be created" do
|
80
|
+
expect(rotate.rename_logs).not_to eq(nil)
|
119
81
|
end
|
120
82
|
|
121
|
-
|
122
|
-
|
123
|
-
rotate = NginxUtils::Logrotate.new(script_log: false)
|
124
|
-
expect(rotate.instance_eval{@logger}).to eq(false)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "@logger.level should be a specified level" do
|
128
|
-
rotate = NginxUtils::Logrotate.new(log_level: :warn, script_log: @script_log)
|
129
|
-
expect(rotate.instance_eval{@logger}.level).to eq(Logger::WARN)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "@root_dir should be a specified parameter" do
|
133
|
-
rotate = NginxUtils::Logrotate.new(root_dir: "/var/log/nginx", script_log: @script_log)
|
134
|
-
expect(rotate.instance_eval{@root_dir}).to eq("/var/log/nginx")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "@prefix should be a specified parameter" do
|
138
|
-
rotate = NginxUtils::Logrotate.new(prefix: "20130518", script_log: @script_log)
|
139
|
-
expect(rotate.instance_eval{@prefix}).to eq("20130518")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "@retention should be a specified period" do
|
143
|
-
rotate = NginxUtils::Logrotate.new(retention: 30, script_log: @script_log)
|
144
|
-
expect(rotate.instance_eval{@retention}).to eq(@time_now - (30 * 3600 * 24))
|
145
|
-
end
|
146
|
-
|
147
|
-
it "@pid_file should be a specified parameter" do
|
148
|
-
rotate = NginxUtils::Logrotate.new(pid_file: "/var/run/nginx.pid", script_log: @script_log)
|
149
|
-
expect(rotate.instance_eval{@pid_file}).to eq("/var/run/nginx.pid")
|
150
|
-
end
|
83
|
+
it "@delete_logs should be created" do
|
84
|
+
expect(rotate.delete_logs).not_to eq(nil)
|
151
85
|
end
|
152
86
|
end
|
153
87
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
88
|
+
context "with debug" do
|
89
|
+
let(:debug_rotate) {NginxUtils::Logrotate.new(debug: true)}
|
90
|
+
let(:params) {debug_rotate.instance_eval{@params}}
|
91
|
+
let(:execute) {debug_rotate.instance_eval{@execute}}
|
92
|
+
|
93
|
+
it "@execute should be false" do
|
94
|
+
expect(execute).to eq(false)
|
159
95
|
end
|
160
96
|
|
161
|
-
it "@
|
162
|
-
|
163
|
-
|
164
|
-
expect(@rotate.instance_eval{@execute}).to eq(false)
|
165
|
-
expect(@rotate.instance_eval{@execute}).not_to eq(old_execute)
|
97
|
+
it "@logger should be created with STDOUT" do
|
98
|
+
Logger.should_receive(:new).with(STDOUT)
|
99
|
+
debug_rotate.logger
|
166
100
|
end
|
167
101
|
|
168
|
-
it "
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
expect(
|
173
|
-
expect(
|
102
|
+
it "other parameters should be default" do
|
103
|
+
logger_mock.should_receive(:level=).with(Logger::DEBUG)
|
104
|
+
Time.stub(:now).and_return(time_now)
|
105
|
+
expect(params[:root_dir]).to eq(default[:root_dir])
|
106
|
+
expect(params[:target_logs]).to eq(default[:target_logs])
|
107
|
+
expect(params[:prefix]).to eq(default[:prefix])
|
108
|
+
expect(params[:retention]).to eq(default[:retention])
|
109
|
+
expect(params[:pid_file]).to eq(default[:pid_file])
|
174
110
|
end
|
111
|
+
end
|
175
112
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
expect(
|
180
|
-
expect(@rotate.instance_eval{@logger}).not_to eq(old_logger)
|
113
|
+
context "with custom params" do
|
114
|
+
it "@logger should be false if script_log is false" do
|
115
|
+
rotate = NginxUtils::Logrotate.new(script_log: false)
|
116
|
+
expect(rotate.logger).to eq(false)
|
181
117
|
end
|
182
118
|
|
183
119
|
it "@logger.level should be a specified level" do
|
184
|
-
|
185
|
-
|
186
|
-
expect(@rotate.instance_eval{@logger}.level).to eq(Logger::WARN)
|
187
|
-
expect(@rotate.instance_eval{@logger}.level).not_to eq(old_level)
|
120
|
+
logger_mock.should_receive(:level=).with(Logger::WARN)
|
121
|
+
NginxUtils::Logrotate.new(log_level: :warn)
|
188
122
|
end
|
189
123
|
|
190
|
-
it "@root_dir should be a specified parameter" do
|
191
|
-
|
192
|
-
|
193
|
-
expect(
|
194
|
-
expect(@rotate.instance_eval{@root_dir}).not_to eq(old_root_dir)
|
124
|
+
it "@params[:root_dir] should be a specified parameter" do
|
125
|
+
root_dir = "/var/log/nginx"
|
126
|
+
rotate = NginxUtils::Logrotate.new(root_dir: root_dir)
|
127
|
+
expect(rotate.instance_eval{@params[:root_dir]}).to eq(root_dir)
|
195
128
|
end
|
196
129
|
|
197
|
-
it "@
|
198
|
-
|
199
|
-
|
200
|
-
expect(
|
201
|
-
expect(@rotate.instance_eval{@target_logs}).not_to eq(old_target_logs)
|
130
|
+
it "@params[:prefix] should be a specified parameter" do
|
131
|
+
prefix = Time.now.strftime("%Y%m%d")
|
132
|
+
rotate = NginxUtils::Logrotate.new(prefix: prefix)
|
133
|
+
expect(rotate.instance_eval{@params[:prefix]}).to eq(prefix)
|
202
134
|
end
|
203
135
|
|
204
|
-
it "@
|
205
|
-
|
206
|
-
|
207
|
-
expect(
|
208
|
-
expect(@rotate.instance_eval{@prefix}).not_to eq(old_prefix)
|
136
|
+
it "@params[:retention] should be a specified period" do
|
137
|
+
retention = 30
|
138
|
+
rotate = NginxUtils::Logrotate.new(retention: retention)
|
139
|
+
expect(rotate.instance_eval{@params[:retention]}).to eq(retention)
|
209
140
|
end
|
210
141
|
|
211
|
-
it "@
|
212
|
-
|
213
|
-
|
214
|
-
expect(
|
215
|
-
expect(@rotate.instance_eval{@retention}).not_to eq(old_retention)
|
142
|
+
it "@params[:pid_file] should be a specified parameter" do
|
143
|
+
pid_file = "/var/run/nginx.pid"
|
144
|
+
rotate = NginxUtils::Logrotate.new(pid_file: pid_file)
|
145
|
+
expect(rotate.instance_eval{@params[:pid_file]}).to eq(pid_file)
|
216
146
|
end
|
147
|
+
end
|
148
|
+
end
|
217
149
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
150
|
+
describe "#config" do
|
151
|
+
let(:params) {rotate.instance_eval{@params}}
|
152
|
+
let(:execute) {rotate.instance_eval{@execute}}
|
153
|
+
|
154
|
+
it "@execute should be a false if debug is true" do
|
155
|
+
Logger.should_receive(:new).with(STDOUT)
|
156
|
+
rotate.config debug: true
|
157
|
+
expect(execute).to eq(false)
|
224
158
|
end
|
225
159
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
160
|
+
it "@execute should be a true if debug is false" do
|
161
|
+
rotate = NginxUtils::Logrotate.new(debug: true)
|
162
|
+
rotate.config debug: false
|
163
|
+
expect(rotate.instance_eval{@execute}).to eq(true)
|
164
|
+
end
|
231
165
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
expect(File.exists? "#{log}.#{@prefix}").to eq(true)
|
237
|
-
end
|
238
|
-
end
|
166
|
+
it "@logger should be a false if script_log is false" do
|
167
|
+
rotate.config script_log: false
|
168
|
+
expect(rotate.logger).to eq(false)
|
169
|
+
end
|
239
170
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
end
|
171
|
+
it "@logger.level should be a specified level" do
|
172
|
+
logger_mock.should_receive(:level=).with(Logger::WARN)
|
173
|
+
rotate.config log_level: :warn
|
174
|
+
end
|
245
175
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
end
|
176
|
+
it "@params[:root_dir] should be a specified parameter" do
|
177
|
+
root_dir = "/var/log/nginx"
|
178
|
+
rotate.config root_dir: root_dir
|
179
|
+
expect(params[:root_dir]).to eq(root_dir)
|
180
|
+
end
|
252
181
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
expect(File.exists? "#{log}.#{@prefix}").to eq(false)
|
259
|
-
end
|
260
|
-
end
|
182
|
+
it "@params[:target_logs] should be a specified parameter" do
|
183
|
+
target_logs = "*_log"
|
184
|
+
rotate.config target_logs: target_logs
|
185
|
+
expect(params[:target_logs]).to eq(target_logs)
|
186
|
+
end
|
261
187
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
end
|
188
|
+
it "@params[:prefix] should be a specified parameter" do
|
189
|
+
prefix = Time.now.strftime("%Y%m%d")
|
190
|
+
rotate.config prefix: prefix
|
191
|
+
expect(params[:prefix]).to eq(prefix)
|
267
192
|
end
|
268
193
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
194
|
+
it "@params[:retention] should be a specified period" do
|
195
|
+
retention = 30
|
196
|
+
rotate.config retention: retention
|
197
|
+
expect(params[:retention]).to eq(retention)
|
198
|
+
end
|
273
199
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
200
|
+
it "@params[:pid_file] should be a specified parameter" do
|
201
|
+
pid_file = "/var/run/nginx.pid"
|
202
|
+
rotate.config pid_file: pid_file
|
203
|
+
expect(params[:pid_file]).to eq(pid_file)
|
204
|
+
end
|
205
|
+
end
|
279
206
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
207
|
+
describe "#rename" do
|
208
|
+
before(:each) do
|
209
|
+
Dir.should_receive(:glob).exactly(2).times.and_return(files)
|
210
|
+
File.stub(:rename).and_return(true)
|
211
|
+
end
|
284
212
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
end
|
213
|
+
it "rename target logs" do
|
214
|
+
File.should_receive(:rename).exactly(2).times
|
215
|
+
rotate.rename
|
216
|
+
end
|
290
217
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
expect(log_lines.size).to eq(0)
|
295
|
-
end
|
218
|
+
it "output log file" do
|
219
|
+
logger_mock.should_receive(:debug).exactly(2).times
|
220
|
+
rotate.rename
|
296
221
|
end
|
297
222
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
223
|
+
it "do not rename if a file with the same name exists" do
|
224
|
+
File.stub(:exists?).and_return(true)
|
225
|
+
File.should_not_receive(:rename)
|
226
|
+
logger_mock.should_receive(:warn).exactly(2).times
|
227
|
+
rotate.rename
|
228
|
+
end
|
303
229
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
230
|
+
it "do not rename if not executable" do
|
231
|
+
File.should_not_receive(:rename)
|
232
|
+
rotate.config debug: true
|
233
|
+
rotate.rename
|
234
|
+
end
|
308
235
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
236
|
+
it "do not output log if script_log is false" do
|
237
|
+
logger_mock.should_not_receive(:debug)
|
238
|
+
rotate.config script_log: false
|
239
|
+
rotate.rename
|
240
|
+
end
|
241
|
+
end
|
314
242
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
243
|
+
describe "#delete" do
|
244
|
+
before(:each) do
|
245
|
+
Dir.should_receive(:glob).exactly(2).times.and_return(files)
|
246
|
+
delete_time = Time.now - ((default[:retention] + 1) * 3600 * 24)
|
247
|
+
File.stub(:stat).and_return(double("time mock", mtime: delete_time))
|
248
|
+
File.stub(:unlink).and_return(true)
|
249
|
+
end
|
320
250
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
end
|
251
|
+
it "delete target logs" do
|
252
|
+
File.should_receive(:unlink).exactly(2).times
|
253
|
+
rotate.delete
|
254
|
+
end
|
326
255
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
end
|
256
|
+
it "output log file" do
|
257
|
+
logger_mock.should_receive(:debug).exactly(2).times
|
258
|
+
rotate.delete
|
259
|
+
end
|
332
260
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
261
|
+
it "do not delete if not executable" do
|
262
|
+
File.should_not_receive(:unlink)
|
263
|
+
rotate.config debug: true
|
264
|
+
rotate.delete
|
265
|
+
end
|
338
266
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
267
|
+
it "do not output log if script_log is false" do
|
268
|
+
logger_mock.should_not_receive(:debug)
|
269
|
+
rotate.config script_log: false
|
270
|
+
rotate.delete
|
271
|
+
end
|
272
|
+
end
|
344
273
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
274
|
+
describe "#restart" do
|
275
|
+
before(:each) do
|
276
|
+
File.stub(:exists?).and_return(true)
|
277
|
+
File.stub(:read).and_return("2000")
|
278
|
+
Process.stub(:kill).and_return(1)
|
350
279
|
end
|
351
280
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
NginxUtils::Logrotate.any_instance.stub(:restart).and_return(true)
|
357
|
-
@rotate = NginxUtils::Logrotate.new(script_log: @script_log)
|
358
|
-
end
|
281
|
+
it "should execute reopen log" do
|
282
|
+
Process.should_receive(:kill).and_return(1)
|
283
|
+
rotate.restart
|
284
|
+
end
|
359
285
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
@rotate.execute
|
365
|
-
end
|
286
|
+
it "output success log" do
|
287
|
+
logger_mock.should_receive(:info)
|
288
|
+
rotate.restart
|
289
|
+
end
|
366
290
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
end
|
291
|
+
it "do not execute reopen log if not exists pid file" do
|
292
|
+
File.stub(:exists?).and_return(false)
|
293
|
+
Process.should_not_receive(:kill)
|
294
|
+
rotate.restart
|
295
|
+
end
|
373
296
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
297
|
+
it "should output log if not exists pid file" do
|
298
|
+
File.stub(:exists?).and_return(false)
|
299
|
+
logger_mock.should_receive(:warn)
|
300
|
+
rotate.restart
|
301
|
+
end
|
302
|
+
|
303
|
+
it "do not execute reopen log if not executable" do
|
304
|
+
Process.should_not_receive(:kill)
|
305
|
+
rotate.config debug: true
|
306
|
+
rotate.restart
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should generate an exception" do
|
310
|
+
Process.should_receive(:kill).and_raise("error")
|
311
|
+
logger_mock.should_receive(:error).exactly(2).times
|
312
|
+
expect(proc{rotate.restart}).to raise_error("Nginx restart failed")
|
313
|
+
end
|
314
|
+
|
315
|
+
it "do not output log if script_log is false" do
|
316
|
+
logger_mock.should_not_receive(:info)
|
317
|
+
rotate.config script_log: false
|
318
|
+
rotate.restart
|
379
319
|
end
|
380
320
|
end
|
381
|
-
|
321
|
+
|
322
|
+
describe "#execute" do
|
323
|
+
before(:each) do
|
324
|
+
NginxUtils::Logrotate.any_instance.stub(:rename).and_return(true)
|
325
|
+
NginxUtils::Logrotate.any_instance.stub(:delete).and_return(true)
|
326
|
+
NginxUtils::Logrotate.any_instance.stub(:restart).and_return(true)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should call rename and delete and restart methods" do
|
330
|
+
NginxUtils::Logrotate.any_instance.should_receive(:rename).and_return(true)
|
331
|
+
NginxUtils::Logrotate.any_instance.should_receive(:delete).and_return(true)
|
332
|
+
NginxUtils::Logrotate.any_instance.should_receive(:restart).and_return(true)
|
333
|
+
rotate.execute
|
334
|
+
end
|
335
|
+
|
336
|
+
it "output log file" do
|
337
|
+
logger_mock.should_receive(:info).exactly(2).times
|
338
|
+
rotate.execute
|
339
|
+
end
|
340
|
+
|
341
|
+
it "do not output log if script_log is false" do
|
342
|
+
logger_mock.should_not_receive(:info)
|
343
|
+
rotate.config script_log: false
|
344
|
+
rotate.execute
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|