-
Notifications
You must be signed in to change notification settings - Fork 479
/
scheduler_setup_test.rb
132 lines (109 loc) · 2.97 KB
/
scheduler_setup_test.rb
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
# vim:fileencoding=utf-8
require_relative 'test_helper'
context 'Resque::Scheduler' do
setup do
ENV['VERBOSE'] = nil
nullify_logger
Resque::Scheduler.dynamic = false
Resque.redis.flushall
Resque::Scheduler.clear_schedule!
end
teardown { restore_devnull_logfile }
test 'set custom logger' do
custom_logger = Logger.new('/dev/null')
Resque::Scheduler.send(:logger=, custom_logger)
assert_equal(custom_logger, Resque::Scheduler.send(:logger))
end
test 'configure block' do
Resque::Scheduler.quiet = false
Resque::Scheduler.configure do |c|
c.quiet = true
end
assert_equal(Resque::Scheduler.quiet, true)
end
context 'when getting the env' do
def wipe
Resque::Scheduler.env = nil
Rails.env = nil
ENV['RAILS_ENV'] = nil
end
setup { wipe }
teardown { wipe }
test 'uses the value if set' do
Resque::Scheduler.env = 'foo'
assert_equal('foo', Resque::Scheduler.env)
end
test 'uses Rails.env if present' do
Rails.env = 'bar'
assert_equal('bar', Resque::Scheduler.env)
end
test 'uses $RAILS_ENV if present' do
ENV['RAILS_ENV'] = 'baz'
assert_equal('baz', Resque::Scheduler.env)
end
end
context 'logger default settings' do
setup { nullify_logger }
teardown { restore_devnull_logfile }
test 'uses STDOUT' do
assert_equal(
Resque::Scheduler.send(:logger)
.instance_variable_get(:@logdev).dev, $stdout
)
end
test 'not verbose' do
assert Resque::Scheduler.send(:logger).level > Logger::DEBUG
end
test 'not quieted' do
assert Resque::Scheduler.send(:logger).level < Logger::FATAL
end
end
context 'logger custom settings' do
setup { nullify_logger }
teardown { restore_devnull_logfile }
test 'uses logfile' do
Resque::Scheduler.logfile = '/dev/null'
assert_equal(
Resque::Scheduler.send(:logger)
.instance_variable_get(:@logdev).filename,
'/dev/null'
)
end
test 'set verbosity' do
Resque::Scheduler.verbose = true
assert Resque::Scheduler.send(:logger).level == Logger::DEBUG
end
test 'quiet logger' do
Resque::Scheduler.quiet = true
assert Resque::Scheduler.send(:logger).level == Logger::FATAL
end
end
context 'logger with json formatter' do
setup do
nullify_logger
Resque::Scheduler.logformat = 'json'
$stdout = StringIO.new
end
teardown do
$stdout = STDOUT
end
test 'logs with json' do
Resque::Scheduler.log! 'whatever'
assert $stdout.string =~ /"msg":"whatever"/
end
end
context 'logger with text formatter' do
setup do
nullify_logger
Resque::Scheduler.logformat = 'text'
$stdout = StringIO.new
end
teardown do
$stdout = STDOUT
end
test 'logs with text' do
Resque::Scheduler.log! 'another thing'
assert $stdout.string =~ /: another thing/
end
end
end