Add test for database dump directory removal.

This commit is contained in:
Dan Helfman 2020-01-21 10:34:46 -08:00
parent 8ef0ba2fae
commit 7824a034ca
2 changed files with 17 additions and 0 deletions

1
NEWS
View file

@ -1,5 +1,6 @@
1.4.22.dev0 1.4.22.dev0
* #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput. * #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. * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
1.4.21 1.4.21

View file

@ -66,6 +66,7 @@ def test_remove_database_dumps_removes_dump_for_each_database():
'databases', 'bar', None 'databases', 'bar', None
).and_return('databases/localhost/bar') ).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/foo').once()
flexmock(module.os).should_receive('remove').with_args('databases/localhost/bar').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( 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) 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(): def test_remove_database_dumps_with_dry_run_skips_removal():
databases = [{'name': 'foo'}, {'name': 'bar'}] databases = [{'name': 'foo'}, {'name': 'bar'}]
flexmock(module.os).should_receive('rmdir').never() flexmock(module.os).should_receive('rmdir').never()