Skip to content

Commit

Permalink
Add unit tests for CloudUploadController
Browse files Browse the repository at this point in the history
Adds tests for ClourUploadController which verify that it computes the
correct max_archive_size and chunk_size given the supplied arguments
and cloud interface properties.

Relates to BAR-113.
  • Loading branch information
mikewallace1979 committed Sep 22, 2023
1 parent e6a62fc commit c03d615
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CloudBackupUploaderBarman,
CloudProviderError,
CloudTarUploader,
CloudUploadController,
CloudUploadingError,
FileUploadStatistics,
DEFAULT_DELIMITER,
Expand Down Expand Up @@ -3400,6 +3401,90 @@ def test_add(self, mock_cloud_interface, compression, tmpdir):
assert uploader.chunk_size == chunk_size


class TestCloudUploadController(object):
"""Tests for the CloudUploadController class."""

@pytest.mark.parametrize(
("max_archive_size_arg", "max_archive_size_property"),
((100, 1000), (100, 1000)),
)
@mock.patch("barman.cloud.CloudInterface")
def test_init_max_archive_size(
self, mock_cloud_interface, max_archive_size_arg, max_archive_size_property
):
"""Test creation of CloudUploadController with max_archive_size values."""
# GIVEN a mock cloud interface with the specified MAX_ARCHIVE_SIZE value
# and an arbitrary MIN_CHUNK_SIZE value
mock_cloud_interface.MAX_ARCHIVE_SIZE = max_archive_size_property
mock_cloud_interface.MIN_CHUNK_SIZE = 5 << 20

# WHEN a CloudUploadController is created with the requested max_archive_size
controller = CloudUploadController(
mock_cloud_interface, "prefix", max_archive_size_arg, None
)

# THEN the max_archive_size is set to the lower of requested max_archive_size
# and the cloud interface MAX_ARCHIVE_SIZE
assert controller.max_archive_size == min(
max_archive_size_arg, max_archive_size_property
)

@pytest.mark.parametrize(
(
"min_chunk_size_arg",
"min_chunk_size_property",
"max_archive_size",
"expected_chunk_size",
),
(
# When the supplied min_chunk_size is larger than
# CloudInterface.MIN_CHUNK_SIZE and larger than the chunk size calculated
# from max_archive_size and CloudInterface.MAX_CHUNKS_PER_FILE then we
# expect CloudUploadController.chunk_size to be min_chunk_size.
(10 << 20, 5 << 20, 1 << 30, 10 << 20),
# When CloudInterface.MIN_CHUNK_SIZE is larger than the supplied
# min_chunk_size and larger than the chunk size calculated from
# max_archive_size and CloudInterface.MAX_CHUNKS_PER_FILE then we
# expect CloudUploadController.chunk_size to be
# CloudInterface.MIN_CHUNK_SIZE.
(5 << 20, 10 << 20, 1 << 30, 10 << 20),
# When the chunk size calculated from max_archive_size and
# CloudInterface.MAX_CHUNKS_PER_FILE is larger than the supplied
# min_chunk_size and CloudInterface.MIN_CHUNK_SIZE then we
# expect CloudUploadController.chunk_size to be the calculated
# value.
(5 << 10, 5 << 10, 1 << 30, 214748),
),
)
@mock.patch("barman.cloud.CloudInterface")
def test_init_min_chunk_size(
self,
mock_cloud_interface,
min_chunk_size_arg,
min_chunk_size_property,
max_archive_size,
expected_chunk_size,
):
"""Test creation of CloudUploadController with max_archive_size values."""
# GIVEN a CloudInterface with a specified MIN_CHUNK_SIZE and MAX_ARCHIVE_SIZE
# and a fixed MAX_CHUNKS_PER_FILE value of 10000
mock_cloud_interface.MIN_CHUNK_SIZE = min_chunk_size_property
mock_cloud_interface.MAX_ARCHIVE_SIZE = max_archive_size
mock_cloud_interface.MAX_CHUNKS_PER_FILE = 10000

# WHEN a CloudUploadController is created with the requested min_chunk_size
controller = CloudUploadController(
mock_cloud_interface,
"prefix",
max_archive_size,
None,
min_chunk_size=min_chunk_size_arg,
)

# THEN the chunk_size is set to the expected value
assert controller.chunk_size == expected_chunk_size


class TestCloudBackupUploader(object):
"""Tests for the CloudBackupUploader class."""

Expand Down

0 comments on commit c03d615

Please sign in to comment.