| #include "cable.hpp" |
| |
| #include <memory> |
| #include <string> |
| #include <system_error> // NOLINT |
| |
| #include <gtest/gtest.h> |
| #include "http_request.hpp" |
| #include "utility.hpp" |
| #include "snapshot_fixture.hpp" |
| #include <nlohmann/json.hpp> |
| #include "managed_store.hpp" |
| #include "test/g3/mock_managed_store_test.hpp" |
| |
| #ifdef SNAPSHOT_FIXTURE_G3 |
| #include "devtools/build/runtime/get_runfiles_dir.h" |
| #endif |
| |
| namespace redfish { |
| namespace { |
| |
| class SnapshotFixture_CableFru : public redfish::SnapshotFixture { |
| protected: |
| static void SetUpTestSuite() { |
| // Have to manually call this as defining this current function prevents |
| // its parent's Setup from being called |
| ::managedStore::MockManagedStoreTest::SetUpTestSuite(); |
| #ifdef SNAPSHOT_FIXTURE_G3 |
| std::string snapshotFilepath_cableFruLocal = |
| ::devtools_build::GetDataDependencyFilepath( |
| "google3/third_party/openbmc_build_scripts/additional/" |
| "scrubbed_gBMCwebManagedStore_platform5_3_2024_08_26.json"); |
| EXPECT_TRUE(managedStore::GetManagedObjectStore()->deserialize( |
| snapshotFilepath_cableFruLocal)); |
| #else |
| EXPECT_TRUE(managedStore::GetManagedObjectStore()->deserialize( |
| snapshotFilepath_cableFru)); |
| #endif |
| } |
| // Use this to create a crow request for use in handlers |
| static crow::Request CreateRequest(const std::string& reqIn = "") { |
| // Dont need this error code ever |
| std::error_code ec; |
| return crow::Request(reqIn, ec); |
| } |
| }; |
| |
| TEST_F(SnapshotFixture_CableFru, handleCableGetTest) { |
| constexpr char kCable[] = "ioadapter_x16_1"; |
| handleCableGet(app_, CreateRequest(), share_async_resp_, kCable); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.type"], "#Cable.v1_0_0.Cable"); |
| EXPECT_EQ(json["@odata.id"], |
| crow::utility::urlFromPieces("redfish", "v1", "Cables", kCable)); |
| EXPECT_EQ(json["Id"], kCable); |
| EXPECT_EQ(json["Name"], "Cable"); |
| EXPECT_EQ(json["Status"]["State"], "Enabled"); |
| |
| EXPECT_TRUE(json.contains("Model")); |
| EXPECT_TRUE(json.contains("Manufacturer")); |
| EXPECT_TRUE(json.contains("PartNumber")); |
| EXPECT_TRUE(json.contains("SerialNumber")); |
| } |
| |
| TEST_F(SnapshotFixture_CableFru, getCableChassisAssociationTest) { |
| constexpr char kCable[] = "NcsiCable"; |
| handleCableGet(app_, CreateRequest(), share_async_resp_, kCable); |
| |
| RunIoUntilDone(); |
| |
| nlohmann::json& json = share_async_resp_->res.jsonValue; |
| |
| EXPECT_EQ(json["@odata.type"], "#Cable.v1_0_0.Cable"); |
| EXPECT_EQ(json["@odata.id"], |
| crow::utility::urlFromPieces("redfish", "v1", "Cables", kCable)); |
| EXPECT_EQ(json["Id"], kCable); |
| EXPECT_EQ( |
| json["Links"]["DownstreamChassis"][0]["@odata.id"], |
| crow::utility::urlFromPieces("redfish", "v1", "Chassis", "chassis3_1")); |
| EXPECT_EQ( |
| json["Links"]["UpstreamChassis"][0]["@odata.id"], |
| crow::utility::urlFromPieces("redfish", "v1", "Chassis", "platform5")); |
| EXPECT_EQ(json["Name"], "Cable"); |
| EXPECT_EQ(json["Status"]["State"], "Enabled"); |
| |
| EXPECT_TRUE(json.contains("Model")); |
| } |
| |
| } // namespace |
| } // namespace redfish |