Testing of static front-end resource customization

One important missing test is that the content of the customized
resource is read from storage every time rather than once. Testing
that requirement would involve creating temporary files which is a
little more work.
This commit is contained in:
Veloman Yunkan committed 2022-06-22 17:11:08 +04:00
1 parent 0086049d4f
commit 1139f2cb4c
5 files changed
+73 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
/non-existent-item text/plain ./test/helloworld.txt
/ text/html ./test/welcome.html
/skin/index.css application/json ./test/helloworld.txt
/zimfile/A/Ray_Charles ray/charles ./test/welcome.html
/search text/html ./test/helloworld.txt
+1
View File
@@ -0,0 +1 @@
Hello world!
+1
View File
@@ -0,0 +1 @@
<html><head></head><body>Welcome</body></html>
+4 -1
View File
@@ -36,7 +36,10 @@ if gtest_dep.found() and not meson.is_cross_build()
'zimfile&other.zim',
'corner_cases.zim',
'poor.zim',
'library.xml'
'library.xml',
'customized_resources.txt',
'helloworld.txt',
'welcome.html',
]
foreach file : data_files
# configure_file(input : 'data/' + file,
+62
View File
@@ -287,6 +287,68 @@ TEST_F(ServerTest, 404)
}
}
struct CustomizedServerTest : ServerTest
{
void SetUp()
{
setenv("KIWIX_SERVE_CUSTOMIZED_RESOURCES", "./test/customized_resources.txt", 1);
ServerTest::SetUp();
}
};
typedef std::vector<std::string> StringCollection;
std::string getHeaderValue(const Headers& headers, const std::string& name)
{
const auto er = headers.equal_range(name);
const auto n = std::distance(er.first, er.second);
if (n == 0)
throw std::runtime_error("Missing header: " + name);
if (n > 1)
throw std::runtime_error("Multiple occurrences of header: " + name);
return er.first->second;
}
TEST_F(CustomizedServerTest, NewResourcesCanBeAdded)
{
// ServerTest.404 verifies that "/ROOT/non-existent-item" doesn't exist
const auto r = zfs1_->GET("/ROOT/non-existent-item");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(getHeaderValue(r->headers, "Content-Type"), "text/plain");
EXPECT_EQ(r->body, "Hello world!\n");
}
TEST_F(CustomizedServerTest, ContentOfAnyServableUrlCanBeOverriden)
{
{
const auto r = zfs1_->GET("/ROOT/");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(getHeaderValue(r->headers, "Content-Type"), "text/html");
EXPECT_EQ(r->body, "<html><head></head><body>Welcome</body></html>\n");
}
{
const auto r = zfs1_->GET("/ROOT/skin/index.css");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(getHeaderValue(r->headers, "Content-Type"), "application/json");
EXPECT_EQ(r->body, "Hello world!\n");
}
{
const auto r = zfs1_->GET("/ROOT/zimfile/A/Ray_Charles");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(getHeaderValue(r->headers, "Content-Type"), "ray/charles");
EXPECT_EQ(r->body, "<html><head></head><body>Welcome</body></html>\n");
}
{
const auto r = zfs1_->GET("/ROOT/search?pattern=la+femme");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(getHeaderValue(r->headers, "Content-Type"), "text/html");
EXPECT_EQ(r->body, "Hello world!\n");
}
}
namespace TestingOfHtmlResponses
{