Enter helper function makeExpected404Response()

This commit is contained in:
Veloman Yunkan
2022-01-20 20:41:23 +04:00
committed by Matthieu Gautier
parent a34dc725f9
commit 5f4256b900

View File

@ -322,10 +322,9 @@ TEST_F(ServerTest, 404)
EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url; EXPECT_EQ(404, zfs1_->GET(url)->status) << "url: " << url;
} }
TEST_F(ServerTest, RandomOnNonExistentBook) std::string makeExpected404Response(const std::string& body)
{ {
const auto r = zfs1_->GET("/ROOT/random?content=non-existent-book"); const std::string preBody = R"PREBODY(<!DOCTYPE html>
const char expectedResponse[] = R"EXPECTEDRESPONSE(<!DOCTYPE html>
<html> <html>
<head> <head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type" /> <meta content="text/html;charset=UTF-8" http-equiv="content-type" />
@ -356,17 +355,27 @@ TEST_F(ServerTest, RandomOnNonExistentBook)
</div> </div>
</span> </span>
</span> </span>
)PREBODY";
const std::string postBody = R"POSTBODY( </body>
</html>
)POSTBODY";
return removeEOLWhitespaceMarkers(preBody + body + postBody);
}
TEST_F(ServerTest, RandomOnNonExistentBook)
{
const auto r = zfs1_->GET("/ROOT/random?content=non-existent-book");
const std::string expectedResponse = makeExpected404Response(R"(
<h1>Not Found</h1> <h1>Not Found</h1>
//EOLWHITESPACEMARKER //EOLWHITESPACEMARKER
<p> <p>
No such book: non-existent-book No such book: non-existent-book
</p> </p>
</body> )");
</html>
)EXPECTEDRESPONSE";
EXPECT_EQ(r->body, removeEOLWhitespaceMarkers(expectedResponse)); EXPECT_EQ(r->body, expectedResponse);
} }
TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle) TEST_F(ServerTest, RandomPageRedirectsToAnExistingArticle)