| // 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_skmhss_unittest.hpp" |
| |
| #include <cstdint> |
| #include <string> |
| #include <vector> |
| |
| #include <gtest/gtest.h> |
| |
| using ::testing::_; |
| using ::testing::ContainerEq; |
| using ::testing::Return; |
| using ::testing::UnorderedElementsAreArray; |
| |
| namespace ipmi_hoth |
| { |
| |
| TEST_F(HothSKMHSSBasicTest, HothIdMainOnly) |
| { |
| EXPECT_EQ("", hvn->pathToHothId(hvn->hothIdToPath(""))); |
| } |
| |
| TEST_F(HothSKMHSSBasicTest, CanHandleBlobChecksNameInvalid) |
| { |
| EXPECT_CALL(dbus, pingHothd(std::string_view(""))) |
| .WillRepeatedly(Return(true)); |
| EXPECT_FALSE(hvn->canHandleBlob("asdf")); |
| EXPECT_FALSE(hvn->canHandleBlob("/skm/hss-backup")); |
| EXPECT_FALSE(hvn->canHandleBlob("/skm/hss-backup/4")); |
| EXPECT_FALSE(hvn->canHandleBlob("/skm/hss-backup/15")); |
| EXPECT_FALSE(hvn->canHandleBlob("/dev/hoth/command_passthru")); |
| } |
| |
| TEST_F(HothSKMHSSBasicTest, CanHandleBlobChecksNameValid) |
| { |
| EXPECT_CALL(dbus, pingHothd(std::string_view(""))) |
| .WillRepeatedly(Return(true)); |
| EXPECT_TRUE(hvn->canHandleBlob("/skm/hss-backup/0")); |
| EXPECT_TRUE(hvn->canHandleBlob("/skm/hss-backup/1")); |
| EXPECT_TRUE(hvn->canHandleBlob("/skm/hss-backup/2")); |
| EXPECT_TRUE(hvn->canHandleBlob("/skm/hss-backup/3")); |
| } |
| |
| TEST_F(HothSKMHSSBasicTest, GetBlobIdsAsHssUnintialized) |
| { |
| hvn = createHandlerWithEmptyCache(); |
| std::vector<std::string> expected = {"/skm/hss-backup/"}; |
| EXPECT_CALL(dbus, pingHothd(std::string_view(""))).WillOnce(Return(true)); |
| EXPECT_THAT(hvn->getBlobIds(), ContainerEq(expected)); |
| } |
| |
| TEST_F(HothSKMHSSBasicTest, GetBlobIdsAsHssCommited) |
| { |
| std::vector<std::string> expected = { |
| "/skm/hss-backup/", "/skm/hss-backup/0", "/skm/hss-backup/1", |
| "/skm/hss-backup/2", "/skm/hss-backup/3", |
| }; |
| EXPECT_CALL(dbus, pingHothd(std::string_view(""))) |
| .WillRepeatedly(Return(true)); |
| EXPECT_THAT(hvn->getBlobIds(), UnorderedElementsAreArray(expected)); |
| } |
| |
| } // namespace ipmi_hoth |