utility: Append Url Pieces to existing Url
Add helper function to append pieces to existing url to allow more
flexible control over the url. This allows us to avoid have each
resource append the pieces outside of the utility functions and help
maintain all url modifications in a central place for easy management.
Tested: Does not affect Redfish Tree. Unit Test passed.
Change-Id: I751f3c120cbadb465915b12aa253edd53ef32123
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/test/http/utility_test.cpp b/test/http/utility_test.cpp
index 8eef93f..58a2865 100644
--- a/test/http/utility_test.cpp
+++ b/test/http/utility_test.cpp
@@ -222,5 +222,18 @@
EXPECT_EQ(nlohmann::json(boost::urls::url_view(urlString)), urlString);
}
+TEST(AppendUrlFromPieces, PiecesAreAppendedViaDelimiters)
+{
+ boost::urls::url url = urlFromPieces("redfish", "v1", "foo");
+ EXPECT_EQ(std::string_view(url.data(), url.size()), "/redfish/v1/foo");
+
+ appendUrlPieces(url, "bar");
+ EXPECT_EQ(std::string_view(url.data(), url.size()), "/redfish/v1/foo/bar");
+
+ appendUrlPieces(url, "/", "bad&tring");
+ EXPECT_EQ(std::string_view(url.data(), url.size()),
+ "/redfish/v1/foo/bar/%2f/bad&tring");
+}
+
} // namespace
} // namespace crow::utility