Skip to content

Commit 1e629c7

Browse files
committed
unit test for transfer
1 parent de95b1e commit 1e629c7

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

tests/aws-cpp-sdk-transfer-unit-tests/TransferUnitTests.cpp

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,17 @@ const char* ALLOCATION_TAG = "TransferUnitTest";
1919

2020
class MockS3Client : public S3Client {
2121
public:
22-
MockS3Client() : S3Client(), shouldReturnWrongRange(false) {}
23-
24-
void SetReturnWrongRange(bool wrongRange) {
25-
shouldReturnWrongRange = wrongRange;
26-
}
22+
MockS3Client() : S3Client(){};
2723

28-
GetObjectOutcome GetObject(const GetObjectRequest& request) const override {
24+
GetObjectOutcome GetObject(const GetObjectRequest&) const override {
2925
GetObjectResult result;
30-
31-
if (request.RangeHasBeenSet()) {
32-
if (shouldReturnWrongRange) {
33-
// Return a different range than requested
34-
result.SetContentRange("bytes 1024-2047/2048");
35-
} else {
36-
// Parse the requested range and return matching ContentRange
37-
Aws::String requestRange = request.GetRange();
38-
if (requestRange.find("bytes=") == 0) {
39-
Aws::String range = requestRange.substr(6); // Remove "bytes="
40-
result.SetContentRange("bytes " + range + "/2048");
41-
}
42-
}
43-
}
44-
45-
// Create a raw pointer stream
26+
// Return wrong range to trigger validation failure
27+
result.SetContentRange("bytes 1024-2047/2048");
4628
auto stream = Aws::New<std::stringstream>(ALLOCATION_TAG);
4729
*stream << "mock data";
4830
result.ReplaceBody(stream);
49-
5031
return GetObjectOutcome(std::move(result));
5132
}
52-
53-
private:
54-
bool shouldReturnWrongRange;
5533
};
5634

5735
class TransferUnitTest : public testing::Test {
@@ -62,39 +40,21 @@ class TransferUnitTest : public testing::Test {
6240
}
6341

6442
static void SetUpTestSuite() {
65-
#ifdef USE_AWS_MEMORY_MANAGEMENT
66-
_testMemorySystem.reset(new ExactTestMemorySystem(1024, 128));
67-
_options.memoryManagementOptions.memoryManager = _testMemorySystem.get();
68-
#endif
6943
InitAPI(_options);
7044
}
7145

7246
static void TearDownTestSuite() {
7347
ShutdownAPI(_options);
74-
#ifdef USE_AWS_MEMORY_MANAGEMENT
75-
EXPECT_EQ(_testMemorySystem->GetCurrentOutstandingAllocations(), 0ULL);
76-
EXPECT_EQ(_testMemorySystem->GetCurrentBytesAllocated(), 0ULL);
77-
EXPECT_TRUE(_testMemorySystem->IsClean());
78-
_testMemorySystem.reset();
79-
#endif
8048
}
8149

8250
std::shared_ptr<PooledThreadExecutor> executor;
8351
std::shared_ptr<MockS3Client> mockS3Client;
8452
static SDKOptions _options;
85-
#ifdef USE_AWS_MEMORY_MANAGEMENT
86-
static std::unique_ptr<ExactTestMemorySystem> _testMemorySystem;
87-
#endif
8853
};
8954

9055
SDKOptions TransferUnitTest::_options;
91-
#ifdef USE_AWS_MEMORY_MANAGEMENT
92-
std::unique_ptr<ExactTestMemorySystem> TransferUnitTest::_testMemorySystem = nullptr;
93-
#endif
9456

95-
TEST_F(TransferUnitTest, ContentRangeVerification_Failure) {
96-
mockS3Client->SetReturnWrongRange(true);
97-
57+
TEST_F(TransferUnitTest, ContentValidationShouldFail) {
9858
TransferManagerConfiguration config(executor.get());
9959
config.s3Client = mockS3Client;
10060
auto transferManager = TransferManager::Create(config);
@@ -103,6 +63,7 @@ TEST_F(TransferUnitTest, ContentRangeVerification_Failure) {
10363
return Aws::New<std::stringstream>(ALLOCATION_TAG);
10464
};
10565

66+
// Request bytes 0-1023 but mock returns 1024-2047, should fail validation
10667
auto handle = transferManager->DownloadFile("test-bucket", "test-key", 0, 1024, createStreamFn);
10768
handle->WaitUntilFinished();
10869

0 commit comments

Comments
 (0)