diff --git a/test/server.cpp b/test/server.cpp index 8d9a2054b..525eb69c9 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -364,18 +364,59 @@ std::string makeExpected404Response(const std::string& body) return removeEOLWhitespaceMarkers(preBody + body + postBody); } -TEST_F(ServerTest, RandomOnNonExistentBook) +TEST_F(ServerTest, 404WithBodyTesting) { - const auto r = zfs1_->GET("/ROOT/random?content=non-existent-book"); - const std::string expectedResponse = makeExpected404Response(R"( + typedef std::pair UrlAndExpectedBody; + const std::vector testData{ + { /* url */ "/ROOT/random?content=non-existent-book", + /* expected body */ R"(

Not Found

//EOLWHITESPACEMARKER

No such book: non-existent-book

-)"); +)" }, - EXPECT_EQ(r->body, expectedResponse); + { /* url */ "/ROOT/suggest?content=no-such-book&term=whatever", + /* expected body */ R"( +

Not Found

+ //EOLWHITESPACEMARKER +

+ No such book: no-such-book +

+)" }, + + { /* url */ "/ROOT/raw/no-such-book/meta/Title", + /* expected body */ R"( +

Not Found

+

+ The requested URL "/ROOT/raw/no-such-book/meta/Title" was not found on this server. +

+

+ No such book: no-such-book +

+)" }, + + { /* url */ "/ROOT/raw/zimfile/XYZ", + /* expected body */ R"( +

Not Found

+

+ The requested URL "/ROOT/raw/zimfile/XYZ" was not found on this server. +

+

+ XYZ is not a valid request for raw content. +

+)" } + }; + + for ( const auto& urlAndExpectedBody : testData ) { + const std::string url = urlAndExpectedBody.first; + const std::string expectedBody = urlAndExpectedBody.second; + const TestContext ctx{ {"url", url} }; + const auto r = zfs1_->GET(url.c_str()); + EXPECT_EQ(r->status, 404) << ctx; + EXPECT_EQ(r->body, makeExpected404Response(expectedBody)) << ctx; + } } TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle)