1 #include "version_handler.hpp" 2 #include "version_mock.hpp" 3 4 #include <memory> 5 #include <string> 6 #include <vector> 7 8 #include <gtest/gtest.h> 9 10 using ::testing::_; 11 using ::testing::Return; 12 13 namespace ipmi_flash 14 { 15 16 class VersionCloseExpireBlobTest : public ::testing::Test 17 { 18 protected: 19 void SetUp() override 20 { 21 h = std::make_unique<VersionBlobHandler>( 22 createMockVersionConfigs(blobNames, &im, &tm)); 23 } 24 25 std::unique_ptr<blobs::GenericBlobInterface> h; 26 std::vector<std::string> blobNames{"blob0", "blob1", "blob2", "blob3"}; 27 std::unordered_map<std::string, TriggerMock*> tm; 28 std::unordered_map<std::string, ImageHandlerMock*> im; 29 }; 30 31 TEST_F(VersionCloseExpireBlobTest, VerifyOpenThenClose) 32 { 33 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); 34 EXPECT_CALL(*tm.at("blob0"), status()) 35 .WillOnce(Return(ActionStatus::success)); 36 EXPECT_TRUE(h->open(0, blobs::read, "blob0")); 37 EXPECT_TRUE(h->close(0)); 38 } 39 40 TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails) 41 { 42 EXPECT_FALSE(h->close(0)); 43 } 44 45 TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails) 46 { 47 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); 48 EXPECT_CALL(*tm.at("blob0"), status()) 49 .WillOnce(Return(ActionStatus::success)); 50 EXPECT_TRUE(h->open(0, blobs::read, "blob0")); 51 EXPECT_TRUE(h->close(0)); 52 EXPECT_FALSE(h->close(0)); 53 } 54 55 TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails) 56 { 57 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); 58 EXPECT_CALL(*tm.at("blob0"), status()) 59 .WillOnce(Return(ActionStatus::success)); 60 EXPECT_TRUE(h->open(0, blobs::read, "blob0")); 61 EXPECT_FALSE(h->close(1)); 62 EXPECT_TRUE(h->close(0)); 63 } 64 65 TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted) 66 { 67 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); 68 EXPECT_CALL(*tm.at("blob0"), status()) 69 .WillOnce(Return(ActionStatus::running)); 70 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1); 71 EXPECT_TRUE(h->open(0, blobs::read, "blob0")); 72 EXPECT_TRUE(h->close(0)); 73 } 74 75 } // namespace ipmi_flash 76