blob: 7f36a568032e5a1b9399058c241f224295dc7afb [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{
16using ::testing::Eq;
17using ::testing::Return;
18using ::testing::StrEq;
19
Patrick Venture70b9a1d2019-05-20 18:18:12 -070020class FirmwareHandlerDeleteTest : public FakeLpcFirmwareTest
21{
22};
23
24TEST_F(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
Patrick Venture9e5aab22018-11-09 20:49:28 -080025{
26 /* Delete active image succeeds. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070027 EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
Patrick Venture9e5aab22018-11-09 20:49:28 -080028
29 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070030 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
Patrick Venture7dad86f2019-05-17 08:52:20 -070031 hashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080032
33 /* The active hash blob_id was added. */
34 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080035 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080036 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070037 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080038
39 /* Set up close() expectations. */
40 EXPECT_CALL(imageMock, close());
41 EXPECT_TRUE(handler->close(0));
42
43 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 /* Delete the blob. */
Patrick Venture7dad86f2019-05-17 08:52:20 -070049 EXPECT_TRUE(handler->deleteBlob(activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080050
51 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080052 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080053 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
Patrick Venture7dad86f2019-05-17 08:52:20 -070054 activeHashBlobId));
Patrick Venture9e5aab22018-11-09 20:49:28 -080055}
56
Patrick Venture1d5a31c2019-05-20 11:38:22 -070057} // namespace ipmi_flash