test/caddy_test.rb in caddy-1.5.5 vs test/caddy_test.rb in caddy-1.6.0
- old
+ new
@@ -12,10 +12,18 @@
end
sleep(0.05)
end
+ def with_test_logger
+ sio = StringIO.new
+ Caddy.logger = Logger.new(sio)
+ yield
+ Caddy.logger = $test_logger
+ sio.string
+ end
+
def test_basic_lookup
Caddy[:test].refresher = -> { {foo: "bar"} }
Caddy.start
sleep(0.1)
@@ -120,19 +128,27 @@
end
def test_incepted_error_handling
Caddy[:test].refresher = -> { raise "boom" }
Caddy.error_handler = -> (_) { raise "boomboom" }
- Caddy.start
- sleep(0.1)
+ log_output = with_test_logger do
+ Caddy.start
+ sleep(0.1)
+ end
+
+ assert_match(/Caddy error handler itself errored/, log_output)
end
def test_bad_error_handler
Caddy[:test].refresher = -> { raise "boom" }
Caddy.error_handler = "no"
- Caddy.start
- sleep(0.1)
+ log_output = with_test_logger do
+ Caddy.start
+ sleep(0.1)
+ end
+
+ assert_match(/Caddy error handler not callable/, log_output)
end
def test_timeout
timed_out = nil
Caddy[:test].refresher = -> { sleep 1 }
@@ -147,20 +163,31 @@
end
def test_no_handler_timeout
Caddy[:test].refresher = -> { sleep 1 }
Caddy[:test].refresh_interval = 0.5
- Caddy.start
- sleep(2)
- Caddy.stop
- sleep(2)
+
+ log_output = with_test_logger do
+ Caddy.start
+ sleep(2)
+ Caddy.stop
+ sleep(2)
+ end
+
+ assert_match(/timed out/, log_output)
end
def test_no_handler
Caddy[:test].refresher = -> { raise "boom" }
Caddy.start
sleep(0.1)
+ log_output = with_test_logger do
+ Caddy.start
+ sleep(0.1)
+ end
+
+ assert_match(/failed with error/, log_output)
end
def test_requires_refesher
Caddy[:test].refresher = nil
@@ -169,9 +196,22 @@
def test_requires_initial_load
Caddy[:nope].refresher = -> { nil }
assert_raises { Caddy[:nope][:not_there] }
+ end
+
+ def test_does_synchronous_load
+ Caddy[:sync].refresher = -> { sleep 1; "sync" }
+
+ assert_raises { Caddy[:sync].cache }
+
+ log_output = with_test_logger do
+ Caddy.start
+ assert_equal "sync", Caddy[:sync].cache
+ end
+
+ assert_match(/doing synchronous load./, log_output)
end
def test_requires_positive_interval
Caddy[:test].refresh_interval = -2