瀏覽代碼

Add test for database dump directory removal.

Dan Helfman 5 年之前
父節點
當前提交
7824a034ca
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 1 0
      NEWS
  2. 16 0
      tests/unit/hooks/test_dump.py

+ 1 - 0
NEWS

@@ -1,5 +1,6 @@
 1.4.22.dev0
  * #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput.
+ * After a backup of a database dump in directory format, properly remove the dump directory.
  * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
 
 1.4.21

+ 16 - 0
tests/unit/hooks/test_dump.py

@@ -66,6 +66,7 @@ def test_remove_database_dumps_removes_dump_for_each_database():
         'databases', 'bar', None
     ).and_return('databases/localhost/bar')
 
+    flexmock(module.os.path).should_receive('isdir').and_return(False)
     flexmock(module.os).should_receive('remove').with_args('databases/localhost/foo').once()
     flexmock(module.os).should_receive('remove').with_args('databases/localhost/bar').once()
     flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return(
@@ -77,6 +78,21 @@ def test_remove_database_dumps_removes_dump_for_each_database():
     module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False)
 
 
+def test_remove_database_dumps_removes_dump_in_directory_format():
+    databases = [{'name': 'foo'}]
+    flexmock(module).should_receive('make_database_dump_filename').with_args(
+        'databases', 'foo', None
+    ).and_return('databases/localhost/foo')
+
+    flexmock(module.os.path).should_receive('isdir').and_return(True)
+    flexmock(module.os).should_receive('remove').never()
+    flexmock(module.shutil).should_receive('rmtree').with_args('databases/localhost/foo').once()
+    flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return([])
+    flexmock(module.os).should_receive('rmdir').with_args('databases/localhost').once()
+
+    module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False)
+
+
 def test_remove_database_dumps_with_dry_run_skips_removal():
     databases = [{'name': 'foo'}, {'name': 'bar'}]
     flexmock(module.os).should_receive('rmdir').never()