mirror of https://github.com/kiwix/libkiwix.git
Enhanced the server unit-test with corner cases
This commit is contained in:
parent
081a2b2fa6
commit
0b48ab20bb
Binary file not shown.
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
rm -f corner_cases.zim
|
||||
zimwriterfs -w empty.html \
|
||||
-f empty.png \
|
||||
-l=en \
|
||||
-t="ZIM corner cases" \
|
||||
-d="" \
|
||||
-c="" \
|
||||
-p="" \
|
||||
corner_cases \
|
||||
corner_cases.zim \
|
||||
&& echo 'corner_cases.zim was successfully created' \
|
||||
|| echo '!!! Failed to create corner_cases.zim !!!' >&2
|
|
@ -29,6 +29,9 @@ if gtest_dep.found() and not meson.is_cross_build()
|
|||
configure_file(input : 'data/wikipedia_en_ray_charles_mini_2020-03.zim',
|
||||
output : 'zimfile.zim',
|
||||
copy: true )
|
||||
configure_file(input : 'data/corner_cases.zim',
|
||||
output : 'corner_cases.zim',
|
||||
copy: true )
|
||||
|
||||
foreach test_name : tests
|
||||
# XXX: implicit_include_directories must be set to false, otherwise
|
||||
|
|
|
@ -50,9 +50,10 @@ class ZimFileServer
|
|||
{
|
||||
public: // types
|
||||
typedef std::shared_ptr<httplib::Response> Response;
|
||||
typedef std::vector<std::string> FilePathCollection;
|
||||
|
||||
public: // functions
|
||||
ZimFileServer(int serverPort, std::string zimpath);
|
||||
ZimFileServer(int serverPort, const FilePathCollection& zimpaths);
|
||||
~ZimFileServer();
|
||||
|
||||
Response GET(const char* path, const Headers& headers = Headers())
|
||||
|
@ -73,11 +74,13 @@ private: // data
|
|||
std::unique_ptr<httplib::Client> client;
|
||||
};
|
||||
|
||||
ZimFileServer::ZimFileServer(int serverPort, std::string zimpath)
|
||||
ZimFileServer::ZimFileServer(int serverPort, const FilePathCollection& zimpaths)
|
||||
: manager(&this->library)
|
||||
{
|
||||
for ( const auto zimpath : zimpaths ) {
|
||||
if (!manager.addBookFromPath(zimpath, zimpath, "", false))
|
||||
throw std::runtime_error("Unable to add the ZIM file '" + zimpath + "'");
|
||||
}
|
||||
|
||||
const std::string address = "127.0.0.1";
|
||||
nameMapper.reset(new kiwix::HumanReadableNameMapper(library, false));
|
||||
|
@ -104,11 +107,14 @@ protected:
|
|||
std::unique_ptr<ZimFileServer> zfs1_;
|
||||
|
||||
const int PORT = 8001;
|
||||
const std::string ZIMFILE = "./test/zimfile.zim";
|
||||
const ZimFileServer::FilePathCollection ZIMFILES {
|
||||
"./test/zimfile.zim",
|
||||
"./test/corner_cases.zim"
|
||||
};
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
zfs1_.reset(new ZimFileServer(PORT, ZIMFILE));
|
||||
zfs1_.reset(new ZimFileServer(PORT, ZIMFILES));
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
|
@ -174,6 +180,10 @@ const ResourceCollection resources200Uncompressible{
|
|||
{ WITH_ETAG, "/meta?content=zimfile&name=favicon" },
|
||||
|
||||
{ WITH_ETAG, "/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" },
|
||||
|
||||
{ WITH_ETAG, "/corner_cases/A/empty.html" },
|
||||
{ WITH_ETAG, "/corner_cases/-/empty.css" },
|
||||
{ WITH_ETAG, "/corner_cases/-/empty.js" },
|
||||
};
|
||||
|
||||
ResourceCollection all200Resources()
|
||||
|
@ -307,7 +317,7 @@ TEST_F(ServerTest, ETagIsTheSameAcrossHeadAndGet)
|
|||
|
||||
TEST_F(ServerTest, DifferentServerInstancesProduceDifferentETags)
|
||||
{
|
||||
ZimFileServer zfs2(PORT + 1, ZIMFILE);
|
||||
ZimFileServer zfs2(PORT + 1, ZIMFILES);
|
||||
for ( const Resource& res : all200Resources() ) {
|
||||
if ( !res.etag_expected ) continue;
|
||||
const auto h1 = zfs1_->HEAD(res.url);
|
||||
|
|
Loading…
Reference in New Issue