blob: efdff5d27080d6fd49fcd606497610155e1d9a02 [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::_;
11using ::testing::Return;
William A. Kennington IIIabf17352020-12-22 21:07:11 -080012
Jason Lingc78bfc82020-11-05 18:58:16 -080013namespace ipmi_flash
14{
15
16class VersionCloseExpireBlobTest : public ::testing::Test
17{
18 protected:
19 void SetUp() override
20 {
William A. Kennington IIIabf17352020-12-22 21:07:11 -080021 h = std::make_unique<VersionBlobHandler>(
22 createMockVersionConfigs(blobNames, &im, &tm));
Jason Lingc78bfc82020-11-05 18:58:16 -080023 }
William A. Kennington IIIabf17352020-12-22 21:07:11 -080024
Jason Lingc78bfc82020-11-05 18:58:16 -080025 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
31TEST_F(VersionCloseExpireBlobTest, VerifyOpenThenClose)
32{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080033 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080034 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080035 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080036 EXPECT_TRUE(h->close(0));
37}
38
William A. Kennington III9936c452020-12-23 23:31:23 -080039TEST_F(VersionCloseExpireBlobTest, VerifySingleAbort)
40{
41 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
42 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
43 EXPECT_TRUE(h->open(1, blobs::read, "blob0"));
44 EXPECT_TRUE(h->close(0));
45 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
46 EXPECT_TRUE(h->close(1));
47}
48
Jason Lingc78bfc82020-11-05 18:58:16 -080049TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails)
50{
Jason Lingc78bfc82020-11-05 18:58:16 -080051 EXPECT_FALSE(h->close(0));
52}
53
54TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails)
55{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080056 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080057 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080058 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080059 EXPECT_TRUE(h->close(0));
60 EXPECT_FALSE(h->close(0));
61}
62
63TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails)
64{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080065 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080066 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
67 EXPECT_FALSE(h->close(1));
William A. Kennington III007c0162020-12-23 16:36:22 -080068 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080069 EXPECT_TRUE(h->close(0));
70}
71
72TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted)
73{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080074 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080075 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080076 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080077 EXPECT_TRUE(h->close(0));
78}
79
80} // namespace ipmi_flash