summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-05-19 00:05:17 +0300
committerEd Tanous <edtanous@google.com>2023-05-19 00:17:23 +0300
commitbb8f3bb4c83ea5411fec38c9bd51298448164d8b (patch)
treece6f9b7a46126d2c82fabf4abda7ae555a982921 /test
parent17b4d6b1bf8ed6281390935160bbe20c4b62e27c (diff)
downloadbmcweb-bb8f3bb4c83ea5411fec38c9bd51298448164d8b.tar.xz
Write test capable of catching regressions
This is a pretty simple test, but should be able to catch the regression injected in the previous commit. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I67de097059a6e0dd8d2c02c1aa6c69954a6d7be3
Diffstat (limited to 'test')
-rw-r--r--test/include/json_html_serializer.cpp50
1 files changed, 37 insertions, 13 deletions
diff --git a/test/include/json_html_serializer.cpp b/test/include/json_html_serializer.cpp
index b8afc9b727..b941a59a45 100644
--- a/test/include/json_html_serializer.cpp
+++ b/test/include/json_html_serializer.cpp
@@ -15,6 +15,20 @@ namespace json_html_util
namespace
{
+const std::string boilerplateStart =
+ "<html>\n"
+ "<head>\n"
+ "<title>Redfish API</title>\n"
+ "<link href=\"/redfish.css\" rel=\"stylesheet\">\n"
+ "</head>\n"
+ "<body>\n"
+ "<div class=\"container\">\n"
+ "<img src=\"/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n";
+
+const std::string boilerplateEnd = "</div>\n"
+ "</body>\n"
+ "</html>\n";
+
TEST(JsonHtmlSerializer, dumpHtmlLink)
{
std::string out;
@@ -23,19 +37,29 @@ TEST(JsonHtmlSerializer, dumpHtmlLink)
dumpHtml(out, j);
EXPECT_EQ(
out,
- "<html>\n"
- "<head>\n"
- "<title>Redfish API</title>\n"
- "<link href=\"/redfish.css\" rel=\"stylesheet\">\n"
- "</head>\n"
- "<body>\n"
- "<div class=\"container\">\n"
- "<img src=\"/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n"
- "<div class=\"content\">\n"
- "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n"
- "</div>\n"
- "</body>\n"
- "</html>\n");
+ boilerplateStart +
+ "<div class=\"content\">\n"
+ "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" +
+ boilerplateEnd);
+}
+
+TEST(JsonHtmlSerializer, dumpint)
+{
+ std::string out;
+ nlohmann::json j = 42;
+ dumpHtml(out, j);
+ EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" +
+ boilerplateEnd);
+}
+
+TEST(JsonHtmlSerializer, dumpstring)
+{
+ std::string out;
+ nlohmann::json j = "foobar";
+ dumpHtml(out, j);
+ EXPECT_EQ(out, boilerplateStart +
+ "<div class=\"content\">\n\"foobar\"</div>\n" +
+ boilerplateEnd);
}
} // namespace
} // namespace json_html_util