| #include "async_resp.hpp" |
| #include "chassis_utils.hpp" |
| #include "power_supply.hpp" |
| #include "snapshot_fixture.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| #include <nlohmann/json.hpp> |
| |
| #include <optional> |
| #include <string> |
| |
| #include <gtest/gtest.h> |
| |
| namespace redfish |
| { |
| namespace |
| { |
| |
| const std::string chassisId = "platfrom1"; |
| const std::string validChassisPath = |
| "/xyz/openbmc_project/inventory/system/board/platform1"; |
| |
| std::vector<std::string> getPowerSupplyIds() |
| { |
| auto dummyResp = std::make_shared<bmcweb::AsyncResp>(); |
| std::vector<std::string> res; |
| |
| // Get valid powerSupplyId |
| doPowerSupplyCollection(dummyResp, chassisId, |
| std::make_optional<std::string>(validChassisPath)); |
| |
| managedStore::MockManagedStoreTest::RunIoUntilDone(); |
| |
| nlohmann::json& json = dummyResp->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.type"], |
| "#PowerSupplyCollection.PowerSupplyCollection"); |
| EXPECT_EQ(json["Name"], "Power Supply Collection"); |
| EXPECT_EQ(json["@odata.id"], crow::utility::urlFromPieces( |
| "redfish", "v1", "Chassis", chassisId, |
| "PowerSubsystem", "PowerSupplies")); |
| EXPECT_TRUE(json.contains("Description")); |
| EXPECT_GT(json["Members@odata.count"], 0); |
| |
| for (const auto& member : dummyResp->res.jsonValue["Members"]) |
| { |
| auto odata_id = member["@odata.id"].get<std::string>(); |
| std::string powerSupplyId = |
| odata_id.substr(odata_id.find_last_of('/') + 1); |
| res.emplace_back(powerSupplyId); |
| } |
| |
| return res; |
| } |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, doPowerSupplyCollectionTest) |
| { |
| getPowerSupplyIds(); |
| } |
| |
| TEST_F(SnapshotFixture_Platform11_Config4, doPowerSupplyGetTest) |
| { |
| std::vector<std::string> powerSupplyIds; |
| |
| // Get powerSupplyId |
| powerSupplyIds = getPowerSupplyIds(); |
| |
| for (const auto& powerSupplyId : powerSupplyIds) |
| { |
| doPowerSupplyGet(share_async_resp_, chassisId, powerSupplyId, |
| validChassisPath); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.type"], "#PowerSupply.v1_5_0.PowerSupply"); |
| EXPECT_EQ(json["Name"], "Power Supply"); |
| EXPECT_EQ(json["Id"], powerSupplyId); |
| EXPECT_EQ(json["@odata.id"], |
| crow::utility::urlFromPieces("redfish", "v1", "Chassis", |
| chassisId, "PowerSubsystem", |
| "PowerSupplies", powerSupplyId)); |
| |
| EXPECT_TRUE(json.contains("Metrics")); |
| EXPECT_TRUE(json["Metrics"].contains("@odata.id")); |
| // getPowerSupplyState |
| // getPowerSupplyHealth |
| EXPECT_EQ(json["Status"]["State"], "Enabled"); |
| EXPECT_EQ(json["Status"]["Health"], "OK"); |
| } |
| } |
| |
| } // namespace |
| } // namespace redfish |