TEST_F(S3InterfaceServiceTest, uploadPartOfDataFailedResponse) { S3VectorUInt8 raw; raw.resize(100); EXPECT_CALL(mockRESTfulService, put(_, _, _)).WillRepeatedly(Throw(S3ConnectionError(""))); EXPECT_THROW( this->uploadPartOfData( raw, S3Url("https://s3-us-west-2.amazonaws.com/s3test.pivotal.io/whatever"), 11, "xyz"), S3FailedAfterRetry); }
Response S3RESTfulService::put(const string &url, HTTPHeaders &headers, const S3VectorUInt8 &data) { Response response(RESPONSE_ERROR); headers.CreateList(); CURLWrapper wrapper(url, headers.GetList(), this->lowSpeedLimit, this->lowSpeedTime, this->debugCurl); CURL *curl = wrapper.curl; curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, RESTfulServiceWriteFuncCallback); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, this->verifyCert); UploadData uploadData(data); curl_easy_setopt(curl, CURLOPT_READDATA, (void *)&uploadData); curl_easy_setopt(curl, CURLOPT_READFUNCTION, RESTfulServiceReadFuncCallback); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)data.size()); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *)&response); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, RESTfulServiceHeadersWriteFuncCallback); this->performCurl(curl, response); return response; }
TEST_F(S3InterfaceServiceTest, fetchDataRoutine) { vector<uint8_t> raw; srand(time(NULL)); for (int i = 0; i < 100; i++) { raw.push_back(rand() & 0xFF); } Response response(RESPONSE_OK, raw); EXPECT_CALL(mockRESTfulService, get(_, _)).WillOnce(Return(response)); S3VectorUInt8 buffer; uint64_t len = this->fetchData( 0, buffer, 100, S3Url("https://s3-us-west-2.amazonaws.com/s3test.pivotal.io/whatever")); EXPECT_EQ(buffer.size(), raw.size()); EXPECT_EQ(0, memcmp(buffer.data(), raw.data(), 100)); EXPECT_EQ((uint64_t)100, len); }
Response S3RESTfulService::deleteRequest(const string &url, HTTPHeaders &headers) { Response response(RESPONSE_ERROR); headers.CreateList(); CURLWrapper wrapper(url, headers.GetList(), this->lowSpeedLimit, this->lowSpeedTime, this->debugCurl); CURL *curl = wrapper.curl; curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, RESTfulServiceAbortFuncCallback); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, this->verifyCert); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); S3VectorUInt8 data; UploadData uploadData(data); curl_easy_setopt(curl, CURLOPT_READDATA, (void *)&uploadData); curl_easy_setopt(curl, CURLOPT_READFUNCTION, RESTfulServiceReadFuncCallback); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)data.size()); this->performCurl(curl, response); return response; }
TEST_F(S3InterfaceServiceTest, uploadPartOfDataRoutine) { S3VectorUInt8 raw; raw.resize(100); uint8_t headers[] = "x-amz-id-2: Vvag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==\r\n" "x-amz-request-id: 656c76696e6727732072657175657374\r\n" "Date: Mon, 1 Nov 2010 20:34:56 GMT\r\n" "ETag: \"b54357faf0632cce46e942fa68356b38\"\r\n" "Content-Length: 0\r\n" "Connection: keep-alive\r\n" "Server: AmazonS3\r\n"; vector<uint8_t> data(headers, headers + sizeof(headers) - 1); Response response(RESPONSE_OK, data, raw); EXPECT_CALL(mockRESTfulService, put(_, _, _)).WillOnce(Return(response)); EXPECT_EQ("\"b54357faf0632cce46e942fa68356b38\"", this->uploadPartOfData( raw, S3Url("https://s3-us-west-2.amazonaws.com/s3test.pivotal.io/whatever"), 11, "xyz")); }