21 #include <gtest/gtest.h> 22 #include <gmock/gmock.h> 24 #include <aws/core/Aws.h> 25 #include <aws/s3/S3Client.h> 26 #include <aws/s3/model/PutObjectRequest.h> 32 using ::testing::Return;
37 std::ifstream ifile(name);
45 MOCK_CONST_METHOD1(PutObject, Model::PutObjectOutcome(
const Model::PutObjectRequest &));
51 bool enable_encryption =
false;
52 std::unique_ptr<MockS3Client>
client;
56 client = std::make_unique<MockS3Client>();
57 char upload_file_path[] =
"/tmp/S3FileUploadTestXXXXXX";
58 int fd = mkstemp(upload_file_path);
60 upload_file = std::string(upload_file_path);
64 remove(upload_file.c_str());
71 Aws::Client::ClientConfiguration config;
72 S3Facade s3_facade(enable_encryption, config);
74 auto outcome = s3_facade.
PutObject(upload_file,
"bucket",
"key");
75 EXPECT_FALSE(outcome.IsSuccess());
81 Model::PutObjectResult result;
82 Model::PutObjectOutcome outcome(result);
83 EXPECT_CALL(*client, PutObject(_))
84 .WillOnce(Return(outcome));
85 auto s3_facade = std::make_shared<S3Facade>(enable_encryption, std::move(client));
86 auto facade_outcome = s3_facade->PutObject(upload_file,
"bucket",
"key");
88 EXPECT_TRUE(facade_outcome.IsSuccess());
96 remove(upload_file.c_str());
97 auto s3_facade = std::make_shared<S3Facade>(enable_encryption, std::move(client));
99 auto outcome = s3_facade->PutObject(upload_file,
"bucket",
"key");
100 EXPECT_FALSE(outcome.IsSuccess());
101 EXPECT_EQ(S3Errors::INVALID_PARAMETER_VALUE, outcome.GetError().GetErrorType());
106 Aws::Client::AWSError<S3Errors> error(S3Errors::INTERNAL_FAILURE,
false);
107 Model::PutObjectOutcome outcome(error);
108 EXPECT_CALL(*client, PutObject(_))
109 .WillOnce(Return(outcome));
110 auto s3_facade = std::make_shared<S3Facade>(enable_encryption, std::move(client));
112 auto facade_outcome = s3_facade->PutObject(upload_file,
"bucket",
"key");
113 EXPECT_FALSE(outcome.IsSuccess());
114 EXPECT_EQ(S3Errors::INTERNAL_FAILURE, facade_outcome.GetError().GetErrorType());
virtual Model::PutObjectOutcome PutObject(const std::string &file_path, const std::string &bucket, const std::string &key)
Call s3 PutObject api to upload file to s3.
std::unique_ptr< MockS3Client > client
bool FileExists(const std::string &name)
TEST_F(S3FacadeTest, TestClientConfigConstructor)