From cc8ad9ebf29bb5660fc5835fdc126b7bd169b35f Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 2 Jun 2022 23:47:13 +0400 Subject: [PATCH] Testing of HTTP errors in XML format --- test/server.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/test/server.cpp b/test/server.cpp index df1907dd3..5aeed662e 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -310,7 +310,7 @@ enum ExpectedResponseDataType // Operator overloading is used as a means of defining a mini-DSL for // defining test data in a concise way (see usage in -// TEST_F(ServerTest, 404WithBodyTesting)) +// TEST_F(ServerTest, Http404HtmlError)) ExpectedResponseData operator==(ExpectedResponseDataType t, std::string s) { switch (t) @@ -545,7 +545,7 @@ std::string TestContentIn400HtmlResponse::pageTitle() const { } // namespace TestingOfHtmlResponses -TEST_F(ServerTest, 404WithBodyTesting) +TEST_F(ServerTest, Http404HtmlError) { using namespace TestingOfHtmlResponses; const std::vector testData{ @@ -735,7 +735,7 @@ TEST_F(ServerTest, 404WithBodyTesting) } } -TEST_F(ServerTest, 400WithBodyTesting) +TEST_F(ServerTest, Http400HtmlError) { using namespace TestingOfHtmlResponses; const std::vector testData{ @@ -811,6 +811,85 @@ TEST_F(ServerTest, 400WithBodyTesting) } } +TEST_F(ServerTest, HttpXmlError) +{ + struct TestData + { + std::string url; + int expectedStatusCode; + std::string expectedXml; + + std::string fullExpectedXml() const + { + return R"()" + expectedXml; + } + + TestContext ctx() const + { + return TestContext{ {"url", url} }; + } + }; + + const std::vector testData{ + { /* url */ "/ROOT/search?format=xml", + /* HTTP status code */ 400, + /* expected response XML */ R"( +Invalid request +The requested URL "/ROOT/search?format=xml" is not a valid request. +Too many books requested (4) where limit is 3 +)" }, + { /* url */ "/ROOT/search?format=xml&content=zimfile", + /* HTTP status code */ 400, + /* expected response XML */ R"( +Invalid request +The requested URL "/ROOT/search?content=zimfile&format=xml" is not a valid request. +No query provided. +)" }, + { /* url */ "/ROOT/search?format=xml&content=non-existing-book&pattern=asdfqwerty", + /* HTTP status code */ 400, + /* expected response XML */ R"( +Invalid request +The requested URL "/ROOT/search?content=non-existing-book&format=xml&pattern=asdfqwerty" is not a valid request. +No such book: non-existing-book +)" }, + { /* url */ "/ROOT/search?format=xml&content=non-existing-book&pattern=a\"