summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/dbus_log_watcher_test.cpp
blob: c2a33dffa3736123ced8ddf2603213566010eba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "dbus_log_watcher.hpp"
#include "dbus_utility.hpp"
#include "event_logs_object_type.hpp"

#include <cstdint>
#include <string>
#include <vector>

#include <gtest/gtest.h>

namespace redfish
{

using namespace dbus::utility;

TEST(DBusLogWatcher, EventLogObjectFromDBusSuccess)
{
    const DBusPropertiesMap propMapStub = {
        {"AdditionalData",
         DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
        {"EventId", DbusVariantType("")},
        {"Id", DbusVariantType(static_cast<uint32_t>(1838))},

        // use 'Message' for MessageId as per the design
        // https://github.com/openbmc/docs/blob/d886ce89fe66c128b3ab492e530ad48fa0c1b4eb/designs/event-logging.md?plain=1#L448
        {"Message", DbusVariantType("OpenBMC.0.1.PowerButtonPressed")},
        {"Resolution", DbusVariantType("")},
        {"Resolved", DbusVariantType(true)},
        {"ServiceProviderNotify", DbusVariantType("")},
        {"Severity", DbusVariantType("")},
        {"Timestamp", DbusVariantType(static_cast<uint64_t>(1638312095123))},
        {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
    };

    EventLogObjectsType event;

    const bool status =
        DbusEventLogMonitor::eventLogObjectFromDBus(propMapStub, event);

    EXPECT_TRUE(status);

    EXPECT_EQ(event.id, "1838");

    EXPECT_EQ(event.timestamp, "2021-11-30T22:41:35.123+00:00");

    EXPECT_EQ(event.messageId, "OpenBMC.0.1.PowerButtonPressed");

    // dbus event subscriptions currently do not support message args
    EXPECT_TRUE(event.messageArgs.empty());
}

TEST(DBusLogWatcher, EventLogObjectFromDBusFailMissingProperty)
{
    // missing 'Resolved'
    const DBusPropertiesMap propMapWrong = {
        {"AdditionalData",
         DbusVariantType(std::vector<std::string>{"KEY=VALUE"})},
        {"EventId", DbusVariantType("")},
        {"Id", DbusVariantType(static_cast<uint32_t>(1838))},
        {"Message", DbusVariantType("")},
        {"Resolution", DbusVariantType("")},
        {"ServiceProviderNotify", DbusVariantType("")},
        {"Severity", DbusVariantType("")},
        {"Timestamp", DbusVariantType(static_cast<uint64_t>(3832))},
        {"UpdateTimestamp", DbusVariantType(static_cast<uint64_t>(3899))},
    };

    EventLogObjectsType event;

    const bool status =
        DbusEventLogMonitor::eventLogObjectFromDBus(propMapWrong, event);

    EXPECT_FALSE(status);
}

} // namespace redfish