From 7824a034ca571848a4a58a2d166ff9b57176ea33 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 21 Jan 2020 10:34:46 -0800 Subject: [PATCH] Add test for database dump directory removal. --- NEWS | 1 + tests/unit/hooks/test_dump.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/NEWS b/NEWS index 2d62f15..2e507f2 100644 --- a/NEWS +++ b/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 diff --git a/tests/unit/hooks/test_dump.py b/tests/unit/hooks/test_dump.py index d36f809..dc6e8dd 100644 --- a/tests/unit/hooks/test_dump.py +++ b/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()