1 #include "dbus_log_watcher.hpp"
2 #include "dbus_utility.hpp"
3 #include "event_logs_object_type.hpp"
4
5 #include <cstdint>
6 #include <string>
7 #include <vector>
8
9 #include <gtest/gtest.h>
10
11 namespace redfish
12 {
13
14 using namespace dbus::utility;
15
TEST(DBusLogWatcher,EventLogObjectFromDBusSuccess)16 TEST(DBusLogWatcher, EventLogObjectFromDBusSuccess)
17 {
18 const DBusPropertiesMap propMapStub = {
19 {"AdditionalData",
20 DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
21 {"EventId", DbusVariantType("")},
22 {"Id", DbusVariantType(static_cast<uint32_t>(1838))},
23
24 // use 'Message' for MessageId as per the design
25 // https://github.com/openbmc/docs/blob/d886ce89fe66c128b3ab492e530ad48fa0c1b4eb/designs/event-logging.md?plain=1#L448
26 {"Message", DbusVariantType("OpenBMC.0.1.PowerButtonPressed")},
27 {"Resolution", DbusVariantType("")},
28 {"Resolved", DbusVariantType(true)},
29 {"ServiceProviderNotify", DbusVariantType("")},
30 {"Severity", DbusVariantType("")},
31 {"Timestamp", DbusVariantType(static_cast<uint64_t>(1638312095123))},
32 {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
33 };
34
35 EventLogObjectsType event;
36
37 const bool status =
38 DbusEventLogMonitor::eventLogObjectFromDBus(propMapStub, event);
39
40 EXPECT_TRUE(status);
41
42 EXPECT_EQ(event.id, "1838");
43
44 EXPECT_EQ(event.timestamp, "2021-11-30T22:41:35.123+00:00");
45
46 EXPECT_EQ(event.messageId, "OpenBMC.0.1.PowerButtonPressed");
47
48 // dbus event subscriptions currently do not support message args
49 EXPECT_TRUE(event.messageArgs.empty());
50 }
51
TEST(DBusLogWatcher,EventLogObjectFromDBusFailMissingProperty)52 TEST(DBusLogWatcher, EventLogObjectFromDBusFailMissingProperty)
53 {
54 // missing 'Resolved'
55 const DBusPropertiesMap propMapWrong = {
56 {"AdditionalData",
57 DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
58 {"EventId", DbusVariantType("")},
59 {"Id", DbusVariantType(static_cast<uint32_t>(1838))},
60 {"Message", DbusVariantType("")},
61 {"Resolution", DbusVariantType("")},
62 {"ServiceProviderNotify", DbusVariantType("")},
63 {"Severity", DbusVariantType("")},
64 {"Timestamp", DbusVariantType(static_cast<uint64_t>(3832))},
65 {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
66 };
67
68 EventLogObjectsType event;
69
70 const bool status =
71 DbusEventLogMonitor::eventLogObjectFromDBus(propMapWrong, event);
72
73 EXPECT_FALSE(status);
74 }
75
76 } // namespace redfish
77