blob: a5550a997869c09e9977c73d48e5f7244ad22873 [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
5#include <vector>
6
7#include <gmock/gmock.h>
8#include <gtest/gtest.h>
9
10namespace blobs
11{
12using ::testing::Eq;
13using ::testing::Return;
14using ::testing::StrEq;
15
16TEST(FirmwareHandlerDeleteTest, DeleteActiveHashSucceeds)
17{
18 /* Delete active image succeeds. */
19 DataHandlerMock dataMock;
20 ImageHandlerMock imageMock;
21
22 std::vector<HandlerPack> blobs = {
23 {FirmwareBlobHandler::hashBlobID, &imageMock},
24 {"asdf", &imageMock},
25 };
26 std::vector<DataHandlerPack> data = {
27 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
28 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
29 };
30
31 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
32
33 EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
34 .WillOnce(Return(true));
35
36 EXPECT_TRUE(handler->open(
37 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
38 FirmwareBlobHandler::hashBlobID));
39
40 /* The active hash blob_id was added. */
41 auto currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080042 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080043 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
44 FirmwareBlobHandler::activeHashBlobID));
45
46 /* Set up close() expectations. */
47 EXPECT_CALL(imageMock, close());
48 EXPECT_TRUE(handler->close(0));
49
50 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080051 EXPECT_EQ(4, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080052 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(),
53 FirmwareBlobHandler::activeHashBlobID));
54
55 /* Delete the blob. */
56 EXPECT_TRUE(handler->deleteBlob(FirmwareBlobHandler::activeHashBlobID));
57
58 currentBlobs = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080059 EXPECT_EQ(3, currentBlobs.size());
Patrick Venture9e5aab22018-11-09 20:49:28 -080060 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
61 FirmwareBlobHandler::activeHashBlobID));
62}
63
64} // namespace blobs