ADD: changed the way of retreiving the result from the curl request
This commit is contained in:
@@ -59,8 +59,6 @@ ENDIF()
|
||||
include/kubecontrol/PodController.hpp
|
||||
src/kubecontrol/PodController.cpp
|
||||
|
||||
include/kubecontrol/WriterMemoryClass.hpp
|
||||
|
||||
include/kubecontrol/Utils.hpp
|
||||
src/kubecontrol/Utils.cpp
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <fstream>
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
#include <kubecontrol/WriterMemoryClass.hpp>
|
||||
#include <loguru.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#define MAX_FILE_LENGTH 200000
|
||||
|
||||
class WriterMemoryClass
|
||||
{
|
||||
public:
|
||||
|
||||
// Callback must be declared static, otherwise it won't link...
|
||||
size_t WriteMemoryCallback(char* ptr, size_t size, size_t nmemb)
|
||||
{
|
||||
str_pBuffer.erase();
|
||||
str_pBuffer = std::string(ptr);
|
||||
|
||||
return str_pBuffer.size();
|
||||
};
|
||||
|
||||
std::string getResponse()
|
||||
{
|
||||
// return std::string(m_pBuffer);
|
||||
return str_pBuffer;
|
||||
}
|
||||
|
||||
void print()
|
||||
{
|
||||
std::cout << "Size: " << str_pBuffer.size() << std::endl;
|
||||
std::cout << "Content: " << std::endl << str_pBuffer << std::endl;
|
||||
}
|
||||
|
||||
// Public member vars
|
||||
private:
|
||||
std::string str_pBuffer;
|
||||
};
|
||||
@@ -198,10 +198,8 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(test);
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
@@ -226,7 +224,7 @@ namespace kubecontrol
|
||||
request.perform();
|
||||
|
||||
request.reset();
|
||||
std::string response = mWriterChunk.getResponse();
|
||||
std::string response = result.str();
|
||||
InfoPod.update(response);
|
||||
while (InfoPod.Status != "Running" && InfoPod.Status != "Succeeded") {
|
||||
|
||||
@@ -252,10 +250,8 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *writefunction = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(writefunction);
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
request.setOpt(new curlpp::options::Url(curlURL));
|
||||
@@ -269,7 +265,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
auto response = mWriterChunk.getResponse();
|
||||
auto response = result.str();
|
||||
|
||||
LOG_S(INFO)<<InfoPod.getRelatedPods().size();
|
||||
if (InfoPod.getRelatedPods().size() > 0)
|
||||
@@ -297,10 +293,8 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *writefunction = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(writefunction);
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
request.setOpt(new curlpp::options::Url(curlURL));
|
||||
@@ -314,7 +308,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
auto response = mWriterChunk.getResponse();
|
||||
auto response = result.str();
|
||||
|
||||
|
||||
return response;
|
||||
@@ -334,12 +328,9 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(test);
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
@@ -349,7 +340,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
return mWriterChunk.getResponse();
|
||||
return result.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -290,11 +290,10 @@ namespace kubecontrol
|
||||
|
||||
auto request = std::make_unique<curlpp::Easy>();
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
|
||||
request->setOpt(test);
|
||||
// request->setOpt(test);
|
||||
std::stringstream result;
|
||||
request->setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
request->setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
@@ -306,8 +305,9 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request->perform();
|
||||
std::string response = mWriterChunk.getResponse();
|
||||
|
||||
// std::string response = mWriterChunk.getResponse();
|
||||
std::string response = result.str();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <kubecontrol/WriterMemoryClass.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -54,13 +53,10 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(test);
|
||||
std::stringstream result;
|
||||
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
request.setOpt(new curlpp::options::Url(curlURL));
|
||||
@@ -73,7 +69,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
auto response = mWriterChunk.getResponse();
|
||||
auto response = result.str();
|
||||
|
||||
|
||||
|
||||
@@ -96,10 +92,12 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(test);
|
||||
// WriterMemoryClass mWriterChunk;
|
||||
// curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
// curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
// request.setOpt(test);
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
@@ -148,7 +146,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
auto response = mWriterChunk.getResponse();
|
||||
auto response = result.str();
|
||||
LOG_S(INFO)<<response;
|
||||
}
|
||||
|
||||
@@ -166,10 +164,9 @@ namespace kubecontrol
|
||||
curlpp::Cleanup cleaner;
|
||||
curlpp::Easy request;
|
||||
|
||||
WriterMemoryClass mWriterChunk;
|
||||
curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor);
|
||||
request.setOpt(test);
|
||||
std::stringstream result;
|
||||
request.setOpt(cURLpp::Options::WriteStream(&result));
|
||||
|
||||
|
||||
request.setOpt(new curlpp::options::HttpHeader(headers));
|
||||
|
||||
@@ -189,7 +186,7 @@ namespace kubecontrol
|
||||
|
||||
|
||||
request.perform();
|
||||
auto response = mWriterChunk.getResponse();
|
||||
auto response = result.str();
|
||||
// LOG_S(INFO)<<response;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
SCENARIO("Testing the SimCore Sensor")
|
||||
{
|
||||
kubecontrol::PodController podc("docs/config");
|
||||
auto tmp = podc.getInfoForPod("webapp");
|
||||
podc.checkPodsHierarchy();
|
||||
auto tmp = podc.getInfoForPod("hamburg");
|
||||
LOG_S(INFO)<<tmp;
|
||||
kubecontrol::PodInfo info(tmp);
|
||||
|
||||
@@ -22,7 +23,7 @@ SCENARIO("Testing the SimCore Sensor")
|
||||
|
||||
THEN("check if Track attributes are correct")
|
||||
{
|
||||
REQUIRE(info.Uuid == "webapp");
|
||||
REQUIRE(info.Uuid == "hamburg");
|
||||
|
||||
// REQUIRE(info1 != "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user