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_CALL(*tm.at("blob0"), status()) |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 35 | .WillOnce(Return(ActionStatus::success)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 36 | EXPECT_TRUE(h->open(0, blobs::read, "blob0")); |
| 37 | EXPECT_TRUE(h->close(0)); |
| 38 | } |
| 39 | |
| 40 | TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails) |
| 41 | { |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 42 | EXPECT_FALSE(h->close(0)); |
| 43 | } |
| 44 | |
| 45 | TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails) |
| 46 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 47 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 48 | EXPECT_CALL(*tm.at("blob0"), status()) |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 49 | .WillOnce(Return(ActionStatus::success)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 57 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 58 | EXPECT_CALL(*tm.at("blob0"), status()) |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 59 | .WillOnce(Return(ActionStatus::success)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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 | { |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 67 | EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true)); |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 68 | EXPECT_CALL(*tm.at("blob0"), status()) |
Jason Ling | c78bfc8 | 2020-11-05 18:58:16 -0800 | [diff] [blame] | 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 |