Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/33#discussion_r41408967
  
    --- Diff: src/couch_mrview_cleanup.erl ---
    @@ -41,7 +41,71 @@ run(Db) ->
     
         lists:foreach(fun(FN) ->
             couch_log:debug("Deleting stale view file: ~s", [FN]),
    -        couch_file:delete(RootDir, FN, false)
    +        delete_view_file(RootDir, FN)
         end, ToDelete),
     
         ok.
    +
    +delete_view_file(RootDir, FullFilePath) ->
    +    couch_server:delete_file(RootDir, FullFilePath, [sync]).
    +
    +-ifdef(TEST).
    +-include_lib("couch/include/couch_eunit.hrl").
    +
    +setup(rename) ->
    +    setup(true);
    +setup(delete) ->
    +    setup(false);
    +setup(RenameOnDelete) ->
    +    meck:new(config, [passthrough]),
    +    meck:expect(config, get_boolean, fun
    +        ("couchdb", "rename_on_delete", _Default) -> RenameOnDelete
    +    end),
    +    ViewFile = ?tempfile() ++ ".view",
    +    RootDir = filename:dirname(ViewFile),
    +    ok = couch_file:init_delete_dir(RootDir),
    +    ok = file:write_file(ViewFile, <<>>),
    +    {RootDir, ViewFile}.
    +
    +teardown(_, {_, ViewFile}) ->
    +    (catch meck:unload(config)),
    +    (catch file:delete(ViewFile)).
    +
    +delete_view_file_test_() ->
    +    Funs = [
    +        fun should_rename_on_delete/2,
    +        fun should_delete/2
    +    ],
    +    [
    +        make_test_case(rename, [fun should_rename_on_delete/2]),
    +        make_test_case(delete, [fun should_delete/2])
    +    ].
    +
    +make_test_case(Mod, Funs) ->
    +    {
    +        lists:flatten(io_lib:format("~s", [Mod])),
    +        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- 
Funs]}
    +    }.
    +
    +should_rename_on_delete(_, {RootDir, ViewFile}) ->
    +    ?_test(begin
    +        ?assert(filelib:is_regular(ViewFile)),
    +        Result = delete_view_file(RootDir, ViewFile),
    +        ?assertMatch({ok, {renamed, _}}, Result),
    +        {ok, {renamed, RenamedViewFile}} = Result,
    +        ?assertNot(filelib:is_regular(ViewFile)),
    +        ?assert(filelib:is_regular(RenamedViewFile))
    --- End diff --
    
    much clearer.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to