blob: ff2d7b3036343e83e356edf57b68a6128a579d58 [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"
Patrick Venture70b9a1d2019-05-20 18:18:12 -07004#include "firmware_unittest.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08005#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07006#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07007#include "verification_mock.hpp"
Patrick Venture9e5aab22018-11-09 20:49:28 -08008
9#include <vector>
10
11#include <gmock/gmock.h>
12#include <gtest/gtest.h>
13
Patrick Venture1d5a31c2019-05-20 11:38:22 -070014namespace ipmi_flash
Patrick Venture9e5aab22018-11-09 20:49:28 -080015{
Patrick Venture930c7b72019-05-24 11:11:08 -070016namespace
17{
18
Patrick Venture9e5aab22018-11-09 20:49:28 -080019using ::testing::Eq;
20using ::testing::Return;
21using ::testing::StrEq;
22
Patrick Venture70b9a1d2019-05-20 18:18:12 -070023class FirmwareHandlerDeleteTest : public FakeLpcFirmwareTest
24{
25};
26
27TEST_F(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
Patrick Venture9e5aab22018-11-09 20:49:28 -080028{
29 /* Delete active image succeeds. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070030 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture9e5aab22018-11-09 20:49:28 -080031
32 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070033 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070034 hashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080035
36 /* The active hash blob_id was added. */
37 auto currentBlobs = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070038 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080039 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070040 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080041
42 /* Set up close() expectations. */
43 EXPECT_CALL(imageMock, close());
44 EXPECT_TRUE(handler->close(0));
45
46 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080047 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080048 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070049 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080050
51 /* Delete the blob. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070052 EXPECT_TRUE(handler->deleteBlob(activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080053
54 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080055 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080056 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070057 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080058}
59
Patrick Venture930c7b72019-05-24 11:11:08 -070060} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070061} // namespace ipmi_flash