blob: 10c42273e3c445f24435fe4d1ab30396b5efbff5 [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"
4
Patrick Venture4eb55952018-11-16 15:36:24 -08005#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venture9e5aab22018-11-09 20:49:28 -08006#include <vector>
7
8#include <gmock/gmock.h>
9#include <gtest/gtest.h>
10
11namespace blobs
12{
13using ::testing::Eq;
14using ::testing::Return;
15using ::testing::StrEq;
16
17TEST(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
18{
19 /* Delete active image succeeds. */
20 DataHandlerMock dataMock;
21 ImageHandlerMock imageMock;
22
23 std::vector<HandlerPack> blobs = {
24 {FirmwareBlobHandler::hashBlobID, &imageMock},
25 {"asdf", &imageMock},
26 };
27 std::vector<DataHandlerPack> data = {
28 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
29 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
30 };
31
Patrick Venture4eb55952018-11-16 15:36:24 -080032 sdbusplus::SdBusMock sdbus_mock;
33 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
34
35 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
36 std::move(bus_mock), blobs, data);
Patrick Venture9e5aab22018-11-09 20:49:28 -080037
38 EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
39 .WillOnce(Return(true));
40
41 EXPECT_TRUE(handler->open(
42 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
43 FirmwareBlobHandler::hashBlobID));
44
45 /* The active hash blob_id was added. */
46 auto 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(),
49 FirmwareBlobHandler::activeHashBlobID));
50
51 /* Set up close() expectations. */
52 EXPECT_CALL(imageMock, close());
53 EXPECT_TRUE(handler->close(0));
54
55 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080056 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080057 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
58 FirmwareBlobHandler::activeHashBlobID));
59
60 /* Delete the blob. */
61 EXPECT_TRUE(handler->deleteBlob(FirmwareBlobHandler::activeHashBlobID));
62
63 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080064 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080065 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
66 FirmwareBlobHandler::activeHashBlobID));
67}
68
69} // namespace blobs