diff --git a/services/blob/test/MultiPartUploadTest.cpp b/services/blob/test/MultiPartUploadTest.cpp index 5b1ecdf06..23bb08e66 100644 --- a/services/blob/test/MultiPartUploadTest.cpp +++ b/services/blob/test/MultiPartUploadTest.cpp @@ -1,77 +1,77 @@ #include #include "AwsS3Bucket.h" +#include "Constants.h" #include "MultiPartUploader.h" #include "S3Tools.h" #include "TestTools.h" #include "Tools.h" #include #include #include using namespace comm::network; class MultiPartUploadTest : public testing::Test { protected: std::shared_ptr s3Client; - const std::string bucketName = "commapp-test"; std::unique_ptr bucket; virtual void SetUp() { Aws::InitAPI({}); s3Client = std::move(getS3Client()); - bucket = std::make_unique(bucketName); + bucket = std::make_unique(BLOB_BUCKET_NAME); } virtual void TearDown() { Aws::ShutdownAPI({}); } }; std::string generateNByes(const size_t n) { std::string result; result.resize(n); memset((char *)result.data(), 'A', n); return result; } TEST_F(MultiPartUploadTest, ThrowingTooSmallPart) { std::string objectName = createObject(*bucket); - MultiPartUploader mpu(s3Client, bucketName, objectName); + MultiPartUploader mpu(s3Client, BLOB_BUCKET_NAME, objectName); mpu.addPart("xxx"); mpu.addPart("xxx"); EXPECT_THROW(mpu.finishUpload(), std::runtime_error); } TEST_F(MultiPartUploadTest, ThrowingTooSmallPartOneByte) { std::string objectName = createObject(*bucket); - MultiPartUploader mpu(s3Client, bucketName, objectName); + MultiPartUploader mpu(s3Client, BLOB_BUCKET_NAME, objectName); mpu.addPart(generateNByes(AWS_MULTIPART_UPLOAD_MINIMUM_CHUNK_SIZE - 1)); mpu.addPart("xxx"); EXPECT_THROW(mpu.finishUpload(), std::runtime_error); } TEST_F(MultiPartUploadTest, SuccessfulWriteMultipleChunks) { std::string objectName = createObject(*bucket); - MultiPartUploader mpu(s3Client, bucketName, objectName); + MultiPartUploader mpu(s3Client, BLOB_BUCKET_NAME, objectName); mpu.addPart(generateNByes(AWS_MULTIPART_UPLOAD_MINIMUM_CHUNK_SIZE)); mpu.addPart("xxx"); mpu.finishUpload(); EXPECT_THROW( bucket->getObjectData(objectName), tools::invalid_argument_error); EXPECT_EQ( bucket->getObjectSize(objectName), AWS_MULTIPART_UPLOAD_MINIMUM_CHUNK_SIZE + 3); bucket->removeObject(objectName); } TEST_F(MultiPartUploadTest, SuccessfulWriteOneChunk) { std::string objectName = createObject(*bucket); - MultiPartUploader mpu(s3Client, bucketName, objectName); + MultiPartUploader mpu(s3Client, BLOB_BUCKET_NAME, objectName); mpu.addPart("xxx"); mpu.finishUpload(); EXPECT_EQ(bucket->getObjectSize(objectName), 3); bucket->removeObject(objectName); } diff --git a/services/blob/test/StorageManagerTest.cpp b/services/blob/test/StorageManagerTest.cpp index e30cf06e2..35665aff9 100644 --- a/services/blob/test/StorageManagerTest.cpp +++ b/services/blob/test/StorageManagerTest.cpp @@ -1,59 +1,63 @@ #include +#include "Constants.h" #include "S3Tools.h" #include "TestTools.h" #include #include #include #include #include using namespace comm::network; class StorageManagerTest : public testing::Test { public: protected: - const std::string bucketName = "commapp-test"; const std::string data = "yiU3VaZlKfTteO10yrWmK1Q5BOvBQrdmj2aBlnoLuhxLfRZK1n8" "26FRXJAGhPswR1r8yxtwxyLkv3I4J4tlH4brDP10mrB99XpM6"; virtual void SetUp() { Aws::InitAPI({}); } virtual void TearDown() { Aws::ShutdownAPI({}); } }; TEST_F(StorageManagerTest, ObjectOperationsTest) { - EXPECT_TRUE(getBucket(bucketName).isAvailable()); - std::string objectName = createObject(getBucket(bucketName)); + EXPECT_TRUE(getBucket(BLOB_BUCKET_NAME).isAvailable()); + std::string objectName = createObject(getBucket(BLOB_BUCKET_NAME)); - getBucket(bucketName).writeObject(objectName, data); + getBucket(BLOB_BUCKET_NAME).writeObject(objectName, data); - EXPECT_EQ(getBucket(bucketName).getObjectSize(objectName), data.size()); - EXPECT_TRUE(getBucket(bucketName).getObjectData(objectName) == data); + EXPECT_EQ(getBucket(BLOB_BUCKET_NAME).getObjectSize(objectName), data.size()); + EXPECT_TRUE(getBucket(BLOB_BUCKET_NAME).getObjectData(objectName) == data); std::string chunkedData; const size_t chunkSize = data.size() / 10; std::function callback = [&chunkedData](const std::string &chunk) { chunkedData += chunk; }; - getBucket(bucketName).getObjectDataChunks(objectName, callback, chunkSize); + getBucket(BLOB_BUCKET_NAME) + .getObjectDataChunks(objectName, callback, chunkSize); EXPECT_TRUE(data == chunkedData); - getBucket(bucketName).renameObject(objectName, objectName + "c"); + getBucket(BLOB_BUCKET_NAME).renameObject(objectName, objectName + "c"); EXPECT_THROW( - getBucket(bucketName).getObjectData(objectName), std::runtime_error); - EXPECT_TRUE(getBucket(bucketName).getObjectData(objectName + "c") == data); - getBucket(bucketName).renameObject(objectName + "c", objectName); + getBucket(BLOB_BUCKET_NAME).getObjectData(objectName), + std::runtime_error); + EXPECT_TRUE( + getBucket(BLOB_BUCKET_NAME).getObjectData(objectName + "c") == data); + getBucket(BLOB_BUCKET_NAME).renameObject(objectName + "c", objectName); - getBucket(bucketName).clearObject(objectName); - EXPECT_EQ(getBucket(bucketName).getObjectSize(objectName), 0); + getBucket(BLOB_BUCKET_NAME).clearObject(objectName); + EXPECT_EQ(getBucket(BLOB_BUCKET_NAME).getObjectSize(objectName), 0); - getBucket(bucketName).removeObject(objectName); + getBucket(BLOB_BUCKET_NAME).removeObject(objectName); EXPECT_THROW( - getBucket(bucketName).getObjectData(objectName), std::runtime_error); + getBucket(BLOB_BUCKET_NAME).getObjectData(objectName), + std::runtime_error); }