blob: cae761af981504224a0dfe483648b86e7c50ea34 [file] [log] [blame]
#include "app.hpp"
#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "log_services.hpp"
#include "snapshot_fixture.hpp"
#include "test/g3/mock_managed_store_test.hpp"
#include <nlohmann/json.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace redfish
{
namespace
{
using ::dbus::utility::DbusVariantType;
using ::managedStore::SimulateFailedAsyncPostDbusCallThreadSafeAction;
using ::managedStore::SimulateSuccessfulAsyncPostDbusCallThreadSafeAction;
using ::testing::An;
using ::testing::_;
TEST_F(SnapshotFixture, DeleteLogServiceEntrySendsCorrectDbusCallFailedResponse)
{
// Setup dbus mocking
EXPECT_CALL(
*managedStore::GetManagedObjectStore(),
PostDbusCallToIoContextThreadSafe(
_,
An<absl::AnyInvocable<void(const boost::system::error_code&)>&&>(),
"xyz.openbmc_project.Logging",
"/xyz/openbmc_project/logging/entry/entry1",
"xyz.openbmc_project.Object.Delete", "Delete"))
.Times(1)
.WillOnce(SimulateFailedAsyncPostDbusCallThreadSafeAction::
SimulateFailedAsyncPostDbusCall());
// Call handler
handleDeleteEventLogEntry(app_, CreateRequest(), share_async_resp_,
"system", "entry1");
// Perform dbus calls
RunIoUntilDone();
// Response validation
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::internal_server_error);
}
TEST_F(SnapshotFixture,
DeleteLogServiceEntrySendsCorrectDbusCallSuccessfulResponse)
{
// Setup dbus mocking
EXPECT_CALL(
*managedStore::GetManagedObjectStore(),
PostDbusCallToIoContextThreadSafe(
_,
An<absl::AnyInvocable<void(const boost::system::error_code&)>&&>(),
"xyz.openbmc_project.Logging",
"/xyz/openbmc_project/logging/entry/entry1",
"xyz.openbmc_project.Object.Delete", "Delete"))
.Times(1)
.WillOnce(SimulateSuccessfulAsyncPostDbusCallThreadSafeAction::
SimulateSuccessfulAsyncPostDbusCall());
// Call handler
handleDeleteEventLogEntry(app_, CreateRequest(), share_async_resp_,
"system", "entry1");
// Perform dbus calls
RunIoUntilDone();
// Response validation
EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
}
TEST_F(SnapshotFixture, PatchLogServiceEntrySendsCorrectDbusCallFailedResponse)
{
// Setup dbus mocking
EXPECT_CALL(
*managedStore::GetManagedObjectStore(),
PostDbusCallToIoContextThreadSafe(
_,
An<absl::AnyInvocable<void(const boost::system::error_code&)>&&>(),
"xyz.openbmc_project.Logging",
"/xyz/openbmc_project/logging/entry/entry1",
"org.freedesktop.DBus.Properties", "Set",
"xyz.openbmc_project.Logging.Entry", "Resolved",
dbus::utility::DbusVariantType(true)))
.Times(1)
.WillOnce(SimulateFailedAsyncPostDbusCallThreadSafeAction::
SimulateFailedAsyncPostDbusCall());
// Call handler
handlePatchEventLogEntry(app_, CreateRequest("{\"Resolved\": true }"),
share_async_resp_, "system", "entry1");
// Perform dbus calls
RunIoUntilDone();
// Response validation
EXPECT_EQ(share_async_resp_->res.result(),
boost::beast::http::status::internal_server_error);
}
TEST_F(SnapshotFixture,
PatchLogServiceEntrySendsCorrectDbusCallSuccessfulResponse)
{
// Setup dbus mocking
EXPECT_CALL(
*managedStore::GetManagedObjectStore(),
PostDbusCallToIoContextThreadSafe(
_,
An<absl::AnyInvocable<void(const boost::system::error_code&)>&&>(),
"xyz.openbmc_project.Logging",
"/xyz/openbmc_project/logging/entry/entry1",
"org.freedesktop.DBus.Properties", "Set",
"xyz.openbmc_project.Logging.Entry", "Resolved",
dbus::utility::DbusVariantType(true)))
.Times(1)
.WillOnce(SimulateSuccessfulAsyncPostDbusCallThreadSafeAction::
SimulateSuccessfulAsyncPostDbusCall());
// Call handler
handlePatchEventLogEntry(app_, CreateRequest("{\"Resolved\": true }"),
share_async_resp_, "system", "entry1");
// Perform dbus calls
RunIoUntilDone();
// Response validation
EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok);
}
} // namespace
} // namespace redfish