| #include <memory> | |
| #include <string> | |
| #include <gmock/gmock.h> | |
| #include <gtest/gtest.h> | |
| #include "absl/functional/any_invocable.h" | |
| #include "dbus_utility.hpp" | |
| #include "log_services.hpp" | |
| #include "test/redfish-core/lib/snapshot_fixture.hpp" | |
| #include "managed_store.hpp" | |
| #include "test/g3/mock_managed_store.hpp" | |
| namespace redfish { | |
| namespace { | |
| using ::dbus::utility::DbusVariantType; | |
| using ::managedStore::SimulateFailedAsyncPostDbusCallThreadSafeAction; | |
| using ::managedStore::SimulateSuccessfulAsyncPostDbusCallThreadSafeAction; | |
| using ::testing::_; | |
| using ::testing::An; | |
| TEST_F(SnapshotFixture, | |
| DeleteLogServiceEntrySendsCorrectDbusCallFailedResponse) { | |
| // Setup dbus mocking | |
| EXPECT_CALL( | |
| *dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| 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( | |
| *dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| 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( | |
| *dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| 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( | |
| *dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| 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 |