Skip to content

Commit

Permalink
Add unit test to this implementation of keep and release
Browse files Browse the repository at this point in the history
This commits is adding a unit test to check if the annotation
methods were called.

References: BAR-222

Signed-off-by: Andre <andre.marchesini@enterprisedb.com>
  • Loading branch information
andremagui committed Aug 7, 2024
1 parent 81d23db commit 94c6405
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from psycopg2.tz import FixedOffsetTimezone

from barman import output
from barman.annotations import KeepManager
from barman.exceptions import (
CommandFailedException,
LockFileBusy,
Expand Down Expand Up @@ -2824,6 +2825,37 @@ def test_check_backup_validity_under_minimum_size(self, server, capsys):
in out
)

@patch("barman.annotations.KeepManagerMixin.release_keep")
@patch("barman.annotations.KeepManagerMixin.keep_backup")
@patch("barman.backup.BackupManager.recover")
def test_add_and_release_keep_annotation_when_recover(
self, recover_mock, keep_backup_mock, release_keep_mock, server
):
backup_info = build_test_backup_info(
backup_id="backup_id",
server=server,
)

keep_before_recover = server.backup_manager.should_keep_backup(
backup_info.backup_id
)
assert keep_before_recover is False

server.recover(backup_info, "fake/destination/path")

keep_after_recover = server.backup_manager.should_keep_backup(
backup_info.backup_id
)
assert keep_after_recover is False

keep_backup_mock.assert_called_once_with(
backup_id=backup_info.backup_id, target=KeepManager.TARGET_FULL
)
recover_mock.assert_called_once_with(
backup_info, "fake/destination/path", None, None
)
release_keep_mock.assert_called_once_with(backup_id=backup_info.backup_id)


class TestCheckStrategy(object):
"""
Expand Down

0 comments on commit 94c6405

Please sign in to comment.