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