Github user rnewson commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-mrview/pull/33#discussion_r41280730
--- Diff: src/couch_mrview_cleanup.erl ---
@@ -41,7 +41,52 @@ 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(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}.
+
+remove_on_delete_test() ->
+ try
+ {RootDir, ViewFile} = setup(true),
+ ?assert(filelib:is_regular(ViewFile)),
+ delete_view_file(RootDir, ViewFile),
+ ?assert(not filelib:is_regular(ViewFile)),
+ RenamedViewFile = couch_server:renamed_filename(ViewFile),
+ ?assert(filelib:is_regular(RenamedViewFile)),
+ ok
+ after
+ meck:unload(config)
+ end.
+
+regular_delete_test() ->
+ try
+ {RootDir, ViewFile} = setup(false),
+ ?assert(filelib:is_regular(ViewFile)),
+ delete_view_file(RootDir, ViewFile),
+ ?assert(not filelib:is_regular(ViewFile)),
+ RenamedViewFile = couch_server:renamed_filename(ViewFile),
+ ?assert(not filelib:is_regular(RenamedViewFile)),
+ ok
+ after
+ meck:unload(config)
--- End diff --
can we use setup/teardown in the usual eunit way?
---
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.
---