Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Nov 15, 2024
1 parent 9f7e0fb commit c202da6
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/functional/s3transfer/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def setUp(self):
self.region = 'us-west-2'
self.bucket = "test_bucket"
self.s3express_bucket = 's3expressbucket--usw2-az5--x-s3'
self.mrap_accesspoint = 'arn:aws:s3::123456789012:accesspoint/mfzwi23gnjvgw.mrap'
self.mrap_bucket = 'mfzwi23gnjvgw.mrap'
self.key = "test_key"
self.expected_content = b'my content'
self.expected_download_content = b'new content'
Expand All @@ -82,6 +84,8 @@ def setUp(self):
f'{self.s3express_bucket}.s3express-usw2-az5.us-west-2.amazonaws.com'
)
self.expected_s3express_path = f'/{self.key}'
self.expected_mrap_host = f'{self.mrap_bucket}.accesspoint.s3-global.amazonaws.com'
self.expected_mrap_path = f"/{self.key}"
self.s3_request = mock.Mock(awscrt.s3.S3Request)
self.s3_crt_client = mock.Mock(awscrt.s3.S3Client)
self.s3_crt_client.make_request.side_effect = (
Expand Down Expand Up @@ -156,6 +160,26 @@ def _assert_exected_s3express_request(
awscrt.auth.AwsSigningAlgorithm.V4_S3EXPRESS
)

def _assert_exected_mrap_request(
self,
make_request_kwargs,
expected_http_method='GET'
):
self._assert_expected_crt_http_request(
make_request_kwargs["request"],
expected_host=self.expected_mrap_host,
expected_path=self.expected_mrap_path,
expected_http_method=expected_http_method,
)
self.assertIn('signing_config', make_request_kwargs)
self.assertEqual(
make_request_kwargs['signing_config'].algorithm,
awscrt.auth.AwsSigningAlgorithm.V4_ASYMMETRIC
)
self.assertEqual(
make_request_kwargs['signing_config'].region, "*"
)

def _assert_subscribers_called(self, expected_future=None):
self.assertTrue(self.record_subscriber.on_queued_called)
self.assertTrue(self.record_subscriber.on_done_called)
Expand Down Expand Up @@ -388,6 +412,17 @@ def test_upload_with_s3express(self):
expected_http_method='PUT'
)

def test_upload_with_mrap(self):
future = self.transfer_manager.upload(
self.filename, self.mrap_accesspoint, self.key, {},
[self.record_subscriber]
)
future.result()
self._assert_exected_mrap_request(
self.s3_crt_client.make_request.call_args[1],
expected_http_method='PUT'
)

def test_download(self):
future = self.transfer_manager.download(
self.bucket, self.key, self.filename, {}, [self.record_subscriber]
Expand Down Expand Up @@ -501,6 +536,17 @@ def test_download_with_s3express(self):
expected_http_method='GET'
)

def test_download_with_mrap(self):
future = self.transfer_manager.download(
self.mrap_accesspoint, self.key, self.filename, {},
[self.record_subscriber]
)
future.result()
self._assert_exected_mrap_request(
self.s3_crt_client.make_request.call_args[1],
expected_http_method='GET'
)

def test_delete(self):
future = self.transfer_manager.delete(
self.bucket, self.key, {}, [self.record_subscriber]
Expand Down

0 comments on commit c202da6

Please sign in to comment.