Skip to content

Commit d1a4197

Browse files
committed
s3 unit test
1 parent ac459fd commit d1a4197

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/aws-cpp-sdk-s3-unit-tests/S3UnitTests.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,41 @@ TEST_F(S3UnitTest, PutObjectShouldHaveCorrectUserAgent) {
378378
EXPECT_TRUE(archMetadata < businessMetrics);
379379
}
380380

381+
TEST_F(S3UnitTest, PutObjectS3ExpressShouldHaveJMetric) {
382+
auto request = PutObjectRequest()
383+
.WithBucket("test-express-bucket--usw2-az1--x-s3")
384+
.WithKey("test-key");
385+
386+
std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG, "test content");
387+
request.SetBody(body);
388+
389+
// Mock multiple responses for S3Express authentication flow
390+
for (int i = 0; i < 3; i++) {
391+
auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "test.com", HttpMethod::HTTP_GET);
392+
mockRequest->SetResponseStreamFactory([]() -> IOStream* {
393+
return Aws::New<StringStream>(ALLOCATION_TAG, "", std::ios_base::in | std::ios_base::binary);
394+
});
395+
auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest);
396+
mockResponse->SetResponseCode(HttpResponseCode::REQUEST_NOT_MADE);
397+
_mockHttpClient->AddResponseToReturn(mockResponse);
398+
}
399+
400+
// Check user agent features before and after call
401+
EXPECT_EQ(0u, request.GetUserAgentFeatures().size());
402+
403+
const auto response = _s3Client->PutObject(request);
404+
// Request will fail due to mock setup, but user agent features should be added
405+
EXPECT_FALSE(response.IsSuccess());
406+
407+
// Verify S3_EXPRESS_BUCKET feature (value 6) was added
408+
const auto& features = request.GetUserAgentFeatures();
409+
EXPECT_GT(features.size(), 0u);
410+
411+
bool hasS3ExpressFeature = std::find(features.begin(), features.end(),
412+
Aws::Client::UserAgentFeature::S3_EXPRESS_BUCKET) != features.end();
413+
EXPECT_TRUE(hasS3ExpressFeature);
414+
}
415+
381416
TEST_F(S3UnitTest, RequestShouldNotIncludeAChecksumIfNotRequired) {
382417
S3ClientConfiguration configuration{};
383418
configuration.checksumConfig.requestChecksumCalculation = RequestChecksumCalculation::WHEN_REQUIRED;

0 commit comments

Comments
 (0)