blob: 900615b9c4e3335b73f9201012077c37ae00f15f [file]
#include "power_supply.hpp"
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "utility.hpp"
#include "async_resp.hpp"
#include "snapshot_fixture.hpp"
#include <nlohmann/json.hpp>
#include "test/g3/mock_managed_store_test.hpp"
namespace redfish {
namespace {
constexpr const char* chassisId = "platform1";
constexpr const char* 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