blob: c5292063c1425ff5980625a35055180dfe80833e [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
39TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails)
40{
Jason Lingc78bfc82020-11-05 18:58:16 -080041 EXPECT_FALSE(h->close(0));
42}
43
44TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails)
45{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080046 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080047 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
William A. Kennington III007c0162020-12-23 16:36:22 -080048 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080049 EXPECT_TRUE(h->close(0));
50 EXPECT_FALSE(h->close(0));
51}
52
53TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails)
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"));
57 EXPECT_FALSE(h->close(1));
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}
61
62TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted)
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"));
William A. Kennington III007c0162020-12-23 16:36:22 -080066 EXPECT_CALL(*tm.at("blob0"), abort()).Times(1);
Jason Lingc78bfc82020-11-05 18:58:16 -080067 EXPECT_TRUE(h->close(0));
68}
69
70} // namespace ipmi_flash