From d613b595baf11c71df5c2c04f2b380926e34d93c Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 27 Jun 2013 15:45:02 -0400 Subject: [PATCH] Add a test for rotation failing and returning an error --- src/lager_util.erl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lager_util.erl b/src/lager_util.erl index e54d074..ae88d19 100644 --- a/src/lager_util.erl +++ b/src/lager_util.erl @@ -565,6 +565,25 @@ rotate_file_test() -> rotate_logfile("rotation.log", 10) end || N <- lists:seq(0, 20)]. +rotate_file_fail_test() -> + %% make sure the directory exists + ?assertEqual(ok, filelib:ensure_dir("rotation/rotation.log")), + %% fix the permissions on it + os:cmd("chown -R u+rwx rotation"), + %% delete any old files + [ok = file:delete(F) || F <- filelib:wildcard("rotation/*")], + %% write a file + file:write_file("rotation/rotation.log", "hello"), + %% hose up the permissions + os:cmd("chown u-w rotation"), + ?assertMatch({error, _}, rotate_logfile("rotation.log", 10)), + ?assert(filelib:is_regular("rotation/rotation.log")), + os:cmd("chown u+w rotation"), + ?assertMatch(ok, rotate_logfile("rotation/rotation.log", 10)), + ?assert(filelib:is_regular("rotation/rotation.log.0")), + ?assertEqual(false, filelib:is_regular("rotation/rotation.log")), + ok. + check_trace_test() -> trace_filter(none), %% match by module