|
|
|
|
#define _TR_TESTING_
|
|
|
|
|
#ifndef _TR_TEST_SERVER_CONTEXT_HPP_
|
|
|
|
|
#define _TR_TEST_SERVER_CONTEXT_HPP_
|
|
|
|
|
|
|
|
|
|
#include <Catch/catch.hpp>
|
|
|
|
|
#include <json.hpp>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
class TestRequest {
|
|
|
|
|
public:
|
|
|
|
|
std::stringstream content;
|
|
|
|
|
std::string path;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestResponse : public std::stringstream {
|
|
|
|
|
public:
|
|
|
|
|
std::string buffer;
|
|
|
|
|
std::unordered_map<std::string, std::string> headers_;
|
|
|
|
|
std::string string();
|
|
|
|
|
std::string message();
|
|
|
|
|
std::string code();
|
|
|
|
|
std::string content();
|
|
|
|
|
const std::unordered_map<std::string, std::string> &headers();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CommonResponse {
|
|
|
|
|
public:
|
|
|
|
|
static void service_unavailable(std::shared_ptr<TestResponse> response);
|
|
|
|
|
static void ok(std::shared_ptr<TestResponse> response, const nlohmann::json &data);
|
|
|
|
|
static void bad_request(std::shared_ptr<TestResponse> response);
|
|
|
|
|
static void accepted(std::shared_ptr<TestResponse> response);
|
|
|
|
|
static void no_content(std::shared_ptr<TestResponse> response);
|
|
|
|
|
static void created(std::shared_ptr<TestResponse> response, std::shared_ptr<TestRequest> request, const std::string &location);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|