blob: 1bf4af75f256bf317a7e0feede840129436ea74a [file] [log] [blame]
Matt Spinler15ee6ae2019-07-08 16:50:06 -05001#include "extensions/openpower-pels/additional_data.hpp"
2
3#include <gtest/gtest.h>
4
5using namespace openpower::pels;
6
7TEST(AdditionalDataTest, GetKeywords)
8{
9 std::vector<std::string> data{"KEY1=VALUE1", "KEY2=VALUE2",
10 "KEY3=", "HELLOWORLD", "=VALUE5"};
11 AdditionalData ad{data};
12
13 EXPECT_TRUE(ad.getValue("KEY1"));
14 EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1");
15
16 EXPECT_TRUE(ad.getValue("KEY2"));
17 EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2");
18
19 EXPECT_FALSE(ad.getValue("x"));
20
21 auto value3 = ad.getValue("KEY3");
22 EXPECT_TRUE(value3);
23 EXPECT_TRUE((*value3).empty());
24
25 EXPECT_FALSE(ad.getValue("HELLOWORLD"));
26 EXPECT_FALSE(ad.getValue("VALUE5"));
Matt Spinlerafa857c2019-10-24 13:03:46 -050027
28 auto json = ad.toJSON();
29 std::string expected = R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":""})";
30 EXPECT_EQ(json.dump(), expected);
31
32 ad.remove("KEY1");
33 EXPECT_FALSE(ad.getValue("KEY1"));
Matt Spinler15ee6ae2019-07-08 16:50:06 -050034}