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; }