Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 1 | #include "version_handler.hpp" |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 2 | #include "version_mock.hpp" |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 3 | |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 4 | #include <memory> |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 5 | #include <string> |
| 6 | #include <vector> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 9 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 10 | using ::testing::_; |
| 11 | using ::testing::Return; |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 12 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 13 | namespace ipmi_flash |
| 14 | { |
| 15 | |
| 16 | class VersionCloseExpireBlobTest : public ::testing::Test |
| 17 | { |
| 18 | protected: |
| 19 | void SetUp() override |
| 20 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 21 | h = std::make_unique<VersionBlobHandler>( |
| 22 | createMockVersionConfigs(blobNames, &im, &tm)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 23 | } |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 24 | |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 33 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 34 | EXPECT_TRUE(h->open(0, blobs::read, "blob0")); |
William A. Kennington III | 007c016 | 2020-12-23 16:36:22 -0800 | [diff] [blame^] | 35 | EXPECT_CALL(*tm.at("blob0"), abort()).Times(1); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 36 | EXPECT_TRUE(h->close(0)); |
| 37 | } |
| 38 | |
| 39 | TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails) |
| 40 | { |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 41 | EXPECT_FALSE(h->close(0)); |
| 42 | } |
| 43 | |
| 44 | TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails) |
| 45 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 46 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 47 | EXPECT_TRUE(h->open(0, blobs::read, "blob0")); |
William A. Kennington III | 007c016 | 2020-12-23 16:36:22 -0800 | [diff] [blame^] | 48 | EXPECT_CALL(*tm.at("blob0"), abort()).Times(1); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 49 | EXPECT_TRUE(h->close(0)); |
| 50 | EXPECT_FALSE(h->close(0)); |
| 51 | } |
| 52 | |
| 53 | TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails) |
| 54 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 55 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 56 | EXPECT_TRUE(h->open(0, blobs::read, "blob0")); |
| 57 | EXPECT_FALSE(h->close(1)); |
William A. Kennington III | 007c016 | 2020-12-23 16:36:22 -0800 | [diff] [blame^] | 58 | EXPECT_CALL(*tm.at("blob0"), abort()).Times(1); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 59 | EXPECT_TRUE(h->close(0)); |
| 60 | } |
| 61 | |
| 62 | TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted) |
| 63 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 64 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 65 | EXPECT_TRUE(h->open(0, blobs::read, "blob0")); |
William A. Kennington III | 007c016 | 2020-12-23 16:36:22 -0800 | [diff] [blame^] | 66 | EXPECT_CALL(*tm.at("blob0"), abort()).Times(1); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 67 | EXPECT_TRUE(h->close(0)); |
| 68 | } |
| 69 | |
| 70 | } // namespace ipmi_flash |