summaryrefslogtreecommitdiff
path: root/test/redfish-core/include/submit_test_event_test.cpp
blob: 3e819ea1c2ed65990702f0582f1fcfcfe6c50e02 (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
#include "event_service_manager.hpp"
#include "subscription.hpp"

#include <boost/url/url.hpp>

#include <string>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

using ::testing::Optional;
using ::testing::StrEq;

namespace redfish
{
static TestEvent createTestEvent()
{
    TestEvent testEvent;
    testEvent.eventGroupId = 1;
    testEvent.eventTimestamp = "2021-01";
    testEvent.message = "Test Message";
    testEvent.messageArgs = std::vector<std::string>{"arg1", "arg2"};
    testEvent.messageId = "Dummy message ID";
    testEvent.originOfCondition = "/redfish/v1/Chassis/GPU_SXM_1";
    testEvent.resolution = "custom resolution";
    testEvent.severity = "whatever";
    return testEvent;
}

TEST(EventServiceManager, submitTestEVent)
{
    boost::urls::url url;
    EventServiceManager& evt = EventServiceManager::getInstance();
    {
        TestEvent testEvent;
        EXPECT_TRUE(evt.sendTestEventLog(testEvent));
    }
    {
        TestEvent testEvent;
        testEvent.eventGroupId = 1;
        testEvent.eventTimestamp = "2021-01-01T00:00:00Z";
        testEvent.message = "Custom Message";
        testEvent.messageArgs =
            std::vector<std::string>{"GPU_SXM_1", "Restart Recommended"};
        testEvent.messageId = "Base.1.13.ResetRecommended";
        testEvent.originOfCondition = "/redfish/v1/Chassis/GPU_SXM_1";
        testEvent.resolution =
            "Reset the GPU at the next service window since the ECC errors are contained";
        testEvent.severity = "Informational";
        EXPECT_TRUE(evt.sendTestEventLog(testEvent));
    }
    {
        TestEvent testEvent = createTestEvent();

        bool result = evt.sendTestEventLog(testEvent);

        EXPECT_TRUE(result);

        EXPECT_THAT(testEvent.eventGroupId, Optional(1));
        EXPECT_THAT(testEvent.eventTimestamp, Optional(StrEq("2021-01")));
        EXPECT_THAT(testEvent.message, Optional(StrEq("Test Message")));
        EXPECT_THAT(testEvent.messageId, Optional(StrEq("Dummy message ID")));
        EXPECT_THAT(testEvent.originOfCondition,
                    Optional(StrEq("/redfish/v1/Chassis/GPU_SXM_1")));
        EXPECT_THAT(testEvent.resolution, Optional(StrEq("custom resolution")));
        EXPECT_THAT(testEvent.severity, Optional(StrEq("whatever")));
    }
}
} // namespace redfish