summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/utils/json_utils_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/redfish-core/include/utils/json_utils_test.cpp')
-rw-r--r--test/redfish-core/include/utils/json_utils_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/redfish-core/include/utils/json_utils_test.cpp b/test/redfish-core/include/utils/json_utils_test.cpp
index 5ef80eeba6..cf5929756b 100644
--- a/test/redfish-core/include/utils/json_utils_test.cpp
+++ b/test/redfish-core/include/utils/json_utils_test.cpp
@@ -6,10 +6,12 @@
#include <boost/beast/http/status.hpp>
#include <nlohmann/json.hpp>
+#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <system_error>
+#include <variant>
#include <vector>
#include <gmock/gmock.h> // IWYU pragma: keep
@@ -70,6 +72,33 @@ TEST(ReadJson, ValidObjectElementsReturnsTrueResponseOkValuesUnpackedCorrectly)
EXPECT_THAT(vec, ElementsAre(1, 2, 3));
}
+TEST(ReadJson, VariantValueUnpackedNull)
+{
+ crow::Response res;
+ nlohmann::json jsonRequest = {{"nullval", nullptr}};
+
+ std::variant<std::string, std::nullptr_t> str;
+
+ ASSERT_TRUE(readJson(jsonRequest, res, "nullval", str));
+ EXPECT_EQ(res.result(), boost::beast::http::status::ok);
+
+ EXPECT_TRUE(std::holds_alternative<std::nullptr_t>(str));
+}
+
+TEST(ReadJson, VariantValueUnpackedValue)
+{
+ crow::Response res;
+ nlohmann::json jsonRequest = {{"stringval", "mystring"}};
+
+ std::variant<std::string, std::nullptr_t> str;
+
+ ASSERT_TRUE(readJson(jsonRequest, res, "stringval", str));
+ EXPECT_EQ(res.result(), boost::beast::http::status::ok);
+
+ ASSERT_TRUE(std::holds_alternative<std::string>(str));
+ EXPECT_EQ(std::get<std::string>(str), "mystring");
+}
+
TEST(readJson, ExtraElementsReturnsFalseReponseIsBadRequest)
{
crow::Response res;