blob: 058295d4bcdc868b44b5563e180c5598a5fd7ddd [file] [log] [blame]
Patrick Venture9e5aab22018-11-09 20:49:28 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture70b9a1d2019-05-20 18:18:12 -07003#include "firmware_unittest.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08004#include "image_mock.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -07005#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07006#include "util.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{
Patrick Venture930c7b72019-05-24 11:11:08 -070015namespace
16{
17
Patrick Venture9e5aab22018-11-09 20:49:28 -080018using ::testing::Eq;
19using ::testing::Return;
20using ::testing::StrEq;
21
Patrick Venture70b9a1d2019-05-20 18:18:12 -070022class FirmwareHandlerDeleteTest : public FakeLpcFirmwareTest
23{
24};
25
26TEST_F(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
Patrick Venture9e5aab22018-11-09 20:49:28 -080027{
28 /* Delete active image succeeds. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070029 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture9e5aab22018-11-09 20:49:28 -080030
31 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070032 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070033 hashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080034
35 /* The active hash blob_id was added. */
36 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070037 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080038 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070039 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080040
41 /* Set up close() expectations. */
42 EXPECT_CALL(imageMock, close());
43 EXPECT_TRUE(handler->close(0));
44
45 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080046 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080047 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070048 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080049
50 /* Delete the blob. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070051 EXPECT_TRUE(handler->deleteBlob(activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080052
53 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080054 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080055 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070056 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080057}
58
Patrick Venture930c7b72019-05-24 11:11:08 -070059} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070060} // namespace ipmi_flash