blob: 87ef59aab11a2a910f0b4856a241616bf7cbead0 [file] [log] [blame]
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "hoth_update_unittest.hpp"
#include <string>
#include <vector>
#include <gtest/gtest.h>
using ::testing::Return;
using ::testing::UnorderedElementsAreArray;
namespace ipmi_hoth
{
class HothUpdateBasicTest : public HothUpdateTest
{};
TEST_F(HothUpdateBasicTest, CanHandleBlobChecksNameInvalid)
{
// Verify canHandleBlob checks and returns false on an invalid name.
EXPECT_FALSE(hvn.canHandleBlob("asdf"));
EXPECT_FALSE(hvn.canHandleBlob("dev/hoth/firmware_update"));
EXPECT_FALSE(hvn.canHandleBlob("/dev/hoth/firmware_update2"));
EXPECT_FALSE(hvn.canHandleBlob("/dev/hoth/hoth0/t/firmware_update"));
EXPECT_FALSE(hvn.canHandleBlob("/dev/hoth/command_passthru"));
}
TEST_F(HothUpdateBasicTest, CanHandleBlobChecksNameValid)
{
// Verify canHandleBlob checks and returns true on the valid name.
EXPECT_TRUE(hvn.canHandleBlob("/dev/hoth/firmware_update"));
EXPECT_TRUE(hvn.canHandleBlob("/dev/hoth/hoth0/firmware_update"));
}
TEST_F(HothUpdateBasicTest, VerifyBehaviorOfBlobIds)
{
// Verify the correct BlobIds is returned from the hoth update handler.
internal::Dbus::SubTreeMapping mapping = {
{"/xyz/openbmc_project/Control", {}},
{"/xyz/openbmc_project/Control/Hoth2nologue", {}},
{"/xyz/openbmc_project/Control/Hoth/nologue/2", {}},
{"/xyz/openbmc_project/Control/Hoth", {}},
{"/xyz/openbmc_project/Control/Hoth/hoth0", {}},
{"/xyz/openbmc_project/Control/Hoth/hoth1", {}},
};
EXPECT_CALL(dbus, getHothdMapping()).WillOnce(Return(mapping));
std::vector<std::string> expected = {
"/dev/hoth/firmware_update",
"/dev/hoth/hoth0/firmware_update",
"/dev/hoth/hoth1/firmware_update",
};
EXPECT_THAT(hvn.getBlobIds(), UnorderedElementsAreArray(expected));
}
} // namespace ipmi_hoth