Przeglądaj źródła

Fix rotate_file_fail_test on win32

pull/509/head
Luke Bakken 5 lat temu
rodzic
commit
a4ceb21b38
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: D99DE30E43EAE440
2 zmienionych plików z 29 dodań i 6 usunięć
  1. +17
    -5
      src/lager_rotator_default.erl
  2. +12
    -1
      src/lager_util.erl

+ 17
- 5
src/lager_rotator_default.erl Wyświetl plik

@ -138,22 +138,33 @@ rotate_file_zero_count_test() ->
rotate_file_fail_test() -> rotate_file_fail_test() ->
TestDir = lager_util:create_test_dir(), TestDir = lager_util:create_test_dir(),
TestLog = filename:join(TestDir, "rotation.log"), TestLog = filename:join(TestDir, "rotation.log"),
%% set known permissions on it %% set known permissions on it
os:cmd("chmod -R u+rwx " ++ TestDir),
ok = lager_util:set_dir_permissions("u+rwx", TestDir),
%% write a file %% write a file
file:write_file(TestLog, "hello"), file:write_file(TestLog, "hello"),
%% hose up the permissions
os:cmd("chmod -R u-w " ++ TestDir),
?assertMatch({error, _}, rotate_logfile(TestLog, 10)),
case os:type() of
{win32, _} -> ok;
_ ->
%% hose up the permissions
ok = lager_util:set_dir_permissions("u-w", TestDir),
?assertMatch({error, _}, rotate_logfile(TestLog, 10))
end,
%% check we still only have one file, rotation.log %% check we still only have one file, rotation.log
?assertEqual([TestLog], filelib:wildcard(TestLog++"*")), ?assertEqual([TestLog], filelib:wildcard(TestLog++"*")),
?assert(filelib:is_regular(TestLog)), ?assert(filelib:is_regular(TestLog)),
%% fix the permissions %% fix the permissions
os:cmd("chmod -R u+w " ++ TestDir),
ok = lager_util:set_dir_permissions("u+w", TestDir),
?assertMatch(ok, rotate_logfile(TestLog, 10)), ?assertMatch(ok, rotate_logfile(TestLog, 10)),
?assert(filelib:is_regular(TestLog ++ ".0")), ?assert(filelib:is_regular(TestLog ++ ".0")),
?assertEqual(true, filelib:is_regular(TestLog)), ?assertEqual(true, filelib:is_regular(TestLog)),
?assertEqual(2, length(filelib:wildcard(TestLog++"*"))), ?assertEqual(2, length(filelib:wildcard(TestLog++"*"))),
%% assert the new file is 0 size: %% assert the new file is 0 size:
case file:read_file_info(TestLog) of case file:read_file_info(TestLog) of
{ok, FInfo} -> {ok, FInfo} ->
@ -161,6 +172,7 @@ rotate_file_fail_test() ->
_ -> _ ->
?assert(false) ?assert(false)
end, end,
%% check that the .0 file now has the contents "hello" %% check that the .0 file now has the contents "hello"
?assertEqual({ok, <<"hello">>}, file:read_file(TestLog++".0")), ?assertEqual({ok, <<"hello">>}, file:read_file(TestLog++".0")),
lager_util:delete_test_dir(TestDir). lager_util:delete_test_dir(TestDir).

+ 12
- 1
src/lager_util.erl Wyświetl plik

@ -31,7 +31,9 @@
]). ]).
-ifdef(TEST). -ifdef(TEST).
-export([create_test_dir/0, delete_test_dir/1]).
-export([create_test_dir/0,
delete_test_dir/1,
set_dir_permissions/2]).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-endif. -endif.
@ -861,4 +863,13 @@ do_delete_test_dir(Dir) ->
end, Entries), end, Entries),
?assertEqual(ok, file:del_dir(Dir)). ?assertEqual(ok, file:del_dir(Dir)).
set_dir_permissions(Perms, Dir) ->
do_set_dir_permissions(os:type(), Perms, Dir).
do_set_dir_permissions({win32, _}, _Perms, _Dir) ->
ok;
do_set_dir_permissions({unix, _}, Perms, Dir) ->
os:cmd("chmod -R " ++ Perms ++ " " ++ Dir),
ok.
-endif. -endif.

Ładowanie…
Anuluj
Zapisz