blob: 755dc309a9001b86ab0add65a2878c6d6355220f [file] [log] [blame]
Patrick Venture9e5aab22018-11-09 20:49:28 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
3#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07004#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07005#include "verification_mock.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08006
7#include <vector>
8
9#include <gmock/gmock.h>
10#include <gtest/gtest.h>
11
Patrick Venture1d5a31c2019-05-20 11:38:22 -070012namespace ipmi_flash
Patrick Venture9e5aab22018-11-09 20:49:28 -080013{
14using ::testing::Eq;
15using ::testing::Return;
16using ::testing::StrEq;
17
18TEST(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
19{
20 /* Delete active image succeeds. */
21 DataHandlerMock dataMock;
22 ImageHandlerMock imageMock;
23
24 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070025 {hashBlobId, &imageMock},
Patrick Venture9e5aab22018-11-09 20:49:28 -080026 {"asdf", &imageMock},
27 };
28 std::vector<DataHandlerPack> data = {
29 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
30 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
31 };
32
Patrick Venture4eb55952018-11-16 15:36:24 -080033 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070034 blobs, data, CreateVerifyMock());
Patrick Venture9e5aab22018-11-09 20:49:28 -080035
Patrick Venture7dad86f2019-05-17 08:52:20 -070036 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture9e5aab22018-11-09 20:49:28 -080037
38 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070039 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070040 hashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080041
42 /* The active hash blob_id was added. */
43 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080044 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080045 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070046 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080047
48 /* Set up close() expectations. */
49 EXPECT_CALL(imageMock, close());
50 EXPECT_TRUE(handler->close(0));
51
52 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080053 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080054 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070055 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080056
57 /* Delete the blob. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070058 EXPECT_TRUE(handler->deleteBlob(activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080059
60 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080061 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080062 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070063 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080064}
65
Patrick Venture1d5a31c2019-05-20 11:38:22 -070066} // namespace ipmi_flash