mirror of https://github.com/kiwix/libkiwix.git
Introduced testing of HTTP response utils
This commit is contained in:
parent
8993f99587
commit
b9323f17bb
|
@ -29,7 +29,7 @@
|
|||
#include <stdexcept>
|
||||
|
||||
#include "byte_range.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "../tools/stringTools.h"
|
||||
|
||||
extern "C" {
|
||||
#include "microhttpd_wrapper.h"
|
||||
|
|
|
@ -101,6 +101,9 @@ class ContentResponse : public Response {
|
|||
kainjow::mustache::data data,
|
||||
const std::string& mimetype);
|
||||
|
||||
const std::string& getContent() const { return m_content; }
|
||||
const std::string& getMimeType() const { return m_mimeType; }
|
||||
|
||||
private:
|
||||
MHD_Response* create_mhd_response(const RequestContext& request);
|
||||
|
||||
|
@ -135,6 +138,8 @@ public: // functions
|
|||
|
||||
protected: // functions
|
||||
std::string getMessage(const std::string& msgId) const;
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr<ContentResponse> generateResponseObject() const;
|
||||
|
||||
public: //data
|
||||
|
|
|
@ -14,7 +14,8 @@ tests = [
|
|||
'opds_catalog',
|
||||
'server_helper',
|
||||
'lrucache',
|
||||
'i18n'
|
||||
'i18n',
|
||||
'response'
|
||||
]
|
||||
|
||||
if build_machine.system() != 'windows'
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#include "../src/server/response.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "../src/server/request_context.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace kiwix;
|
||||
|
||||
RequestContext makeHttpGetRequest(const std::string& url)
|
||||
{
|
||||
return RequestContext(nullptr, "", url, "GET", "1.1");
|
||||
}
|
||||
|
||||
std::string getResponseContent(const ContentResponseBlueprint& crb)
|
||||
{
|
||||
return crb.generateResponseObject()->getContent();
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
|
||||
|
||||
TEST(HTTPErrorResponse, shouldBeInEnglishByDefault) {
|
||||
const RequestContext req = makeHttpGetRequest("/asdf");
|
||||
HTTPErrorResponse errResp(req, MHD_HTTP_NOT_FOUND,
|
||||
"404-page-title",
|
||||
"404-page-heading",
|
||||
"/css/error.css");
|
||||
|
||||
EXPECT_EQ(getResponseContent(errResp),
|
||||
R"(<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
|
||||
<title>Content not found</title>
|
||||
<link type="text/css" href="/css/error.css" rel="Stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Not Found</h1>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
)");
|
||||
}
|
Loading…
Reference in New Issue