blob: 0697bbd15d0a31048a9eddd1d47993eda2282c6e [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();
42 EXPECT_EQ(3, currentBlobs.size());
43 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();
51 EXPECT_EQ(3, currentBlobs.size());
52 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();
59 EXPECT_EQ(2, currentBlobs.size());
60 EXPECT_EQ(0, std::count(currentBlobs.begin(), currentBlobs.end(),
61 FirmwareBlobHandler::activeHashBlobID));
62}
63
64} // namespace blobs