blob: 83b4a43c9ab68cbc409c1db69c3128ff33943ead [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_CALL(*tm.at("blob0"), status())
Jason Lingc78bfc82020-11-05 18:58:16 -080035 .WillOnce(Return(ActionStatus::success));
Jason Lingc78bfc82020-11-05 18:58:16 -080036 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
37 EXPECT_TRUE(h->close(0));
38}
39
40TEST_F(VersionCloseExpireBlobTest, VerifyUnopenedBlobCloseFails)
41{
Jason Lingc78bfc82020-11-05 18:58:16 -080042 EXPECT_FALSE(h->close(0));
43}
44
45TEST_F(VersionCloseExpireBlobTest, VerifyDoubleCloseFails)
46{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080047 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080048 EXPECT_CALL(*tm.at("blob0"), status())
Jason Lingc78bfc82020-11-05 18:58:16 -080049 .WillOnce(Return(ActionStatus::success));
Jason Lingc78bfc82020-11-05 18:58:16 -080050 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
51 EXPECT_TRUE(h->close(0));
52 EXPECT_FALSE(h->close(0));
53}
54
55TEST_F(VersionCloseExpireBlobTest, VerifyBadSessionNumberCloseFails)
56{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080057 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080058 EXPECT_CALL(*tm.at("blob0"), status())
Jason Lingc78bfc82020-11-05 18:58:16 -080059 .WillOnce(Return(ActionStatus::success));
Jason Lingc78bfc82020-11-05 18:58:16 -080060 EXPECT_TRUE(h->open(0, blobs::read, "blob0"));
61 EXPECT_FALSE(h->close(1));
62 EXPECT_TRUE(h->close(0));
63}
64
65TEST_F(VersionCloseExpireBlobTest, VerifyRunningActionIsAborted)
66{
William A. Kennington IIIabf17352020-12-22 21:07:11 -080067 EXPECT_CALL(*tm.at("blob0"), trigger()).WillOnce(Return(true));
Jason Lingc78bfc82020-11-05 18:58:16 -080068 EXPECT_CALL(*tm.at("blob0"), status())
Jason Lingc78bfc82020-11-05 18:58:16 -080069 .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