blob: 3c586238aeead013070b9324b6f50a7683ef3e05 [file] [log] [blame]
Patrick Venture27ac5822019-05-20 17:39:31 -07001#include "bmc_update_mock.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08002#include "data_mock.hpp"
3#include "firmware_handler.hpp"
4#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07006#include "verification_mock.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08007
8#include <vector>
9
10#include <gmock/gmock.h>
11#include <gtest/gtest.h>
12
Patrick Venture1d5a31c2019-05-20 11:38:22 -070013namespace ipmi_flash
Patrick Venture9e5aab22018-11-09 20:49:28 -080014{
15using ::testing::Eq;
16using ::testing::Return;
17using ::testing::StrEq;
18
19TEST(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
20{
21 /* Delete active image succeeds. */
22 DataHandlerMock dataMock;
23 ImageHandlerMock imageMock;
24
25 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070026 {hashBlobId, &imageMock},
Patrick Venture9e5aab22018-11-09 20:49:28 -080027 {"asdf", &imageMock},
28 };
29 std::vector<DataHandlerPack> data = {
30 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
31 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
32 };
33
Patrick Venture4eb55952018-11-16 15:36:24 -080034 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070035 blobs, data, CreateVerifyMock(), CreateUpdateMock());
Patrick Venture9e5aab22018-11-09 20:49:28 -080036
Patrick Venture7dad86f2019-05-17 08:52:20 -070037 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture9e5aab22018-11-09 20:49:28 -080038
39 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070040 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070041 hashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080042
43 /* The active hash blob_id was added. */
44 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080045 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080046 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070047 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080048
49 /* Set up close() expectations. */
50 EXPECT_CALL(imageMock, close());
51 EXPECT_TRUE(handler->close(0));
52
53 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080054 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080055 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070056 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080057
58 /* Delete the blob. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070059 EXPECT_TRUE(handler->deleteBlob(activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080060
61 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080062 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080063 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070064 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080065}
66
Patrick Venture1d5a31c2019-05-20 11:38:22 -070067} // namespace ipmi_flash