blob: 941f72d69c485c92070de3837c13cb84b4500f4f [file] [log] [blame]
Jason Lingc78bfc82020-11-05 18:58:16 -08001#include "version_handler.hpp"
William A. Kennington IIIabf17352020-12-22 21:07:11 -08002#include "version_mock.hpp"
Jason Lingc78bfc82020-11-05 18:58:16 -08003
William A. Kennington IIIabf17352020-12-22 21:07:11 -08004#include <memory>
Jason Lingc78bfc82020-11-05 18:58:16 -08005#include <string>
6#include <vector>
7
8#include <gtest/gtest.h>
William A. Kennington IIIabf17352020-12-22 21:07:11 -08009
Jason Lingc78bfc82020-11-05 18:58:16 -080010using ::testing::Return;
William A. Kennington IIIabf17352020-12-22 21:07:11 -080011
Jason Lingc78bfc82020-11-05 18:58:16 -080012namespace ipmi_flash
13{
14
15class VersionCloseExpireBlobTest : public ::testing::Test
16{
17 protected:
18 void SetUp() override
19 {
William A. Kennington IIIabf17352020-12-22 21:07:11 -080020 h = std::make_unique<VersionBlobHandler>(
21 createMockVersionConfigs(blobNames, &im, &tm));
Jason Lingc78bfc82020-11-05 18:58:16 -080022 }
William A. Kennington IIIabf17352020-12-22 21:07:11 -080023
Jason Lingc78bfc82020-11-05 18:58:16 -080024 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
30TEST_F(VersionCloseExpireBlobTest, VerifyOpenThenClose)
31{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080032 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080033 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080034 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080035 EXPECT_TRUE(h->close(0));
36}
37
William A. Kennington III9936c452020-12-23 23:31:23 -080038TEST_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
Jason Lingc78bfc82020-11-05 18:58:16 -080048TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails)
49{
Jason Lingc78bfc82020-11-05 18:58:16 -080050 EXPECT_FALSE(h->close(0));
51}
52
53TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails)
54{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080055 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080056 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080057 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080058 EXPECT_TRUE(h->close(0));
59 EXPECT_FALSE(h->close(0));
60}
61
62TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails)
63{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080064 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080065 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
66 EXPECT_FALSE(h->close(1));
William A. Kennington III007c0162020-12-23 16:36:22 -080067 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080068 EXPECT_TRUE(h->close(0));
69}
70
71TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted)
72{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080073 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080074 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080075 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080076 EXPECT_TRUE(h->close(0));
77}
78
79} // namespace ipmi_flash