blob: f739b9e0e825c01e4a87cbae5da6226aaff41c1c [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#include "data_mock.hpp"
Patrick Venturedf848ee2018-11-06 15:44:00 -08002#include "firmware_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08003#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07004#include "util.hpp"
Patrick Venturedf848ee2018-11-06 15:44:00 -08005
Patrick Venture4eb55952018-11-16 15:36:24 -08006#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturedf848ee2018-11-06 15:44:00 -08007#include <vector>
8
9#include <gtest/gtest.h>
10
11namespace blobs
12{
13TEST(FirmwareHandlerCanHandleTest, VerifyItemsInListAreOk)
14{
Patrick Venturedf848ee2018-11-06 15:44:00 -080015 struct ListItem
16 {
17 std::string name;
18 bool expected;
19 };
20
21 std::vector<ListItem> items = {
22 {"asdf", true}, {"nope", false}, {"123123", false}, {"bcdf", true}};
23
Patrick Venturea78e39f2018-11-06 18:37:06 -080024 ImageHandlerMock imageMock;
25
26 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070027 {hashBlobId, &imageMock},
Patrick Venturea78e39f2018-11-06 18:37:06 -080028 {"asdf", &imageMock},
29 {"bcdf", &imageMock},
30 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080031 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080032 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080033 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080034
Patrick Venture4eb55952018-11-16 15:36:24 -080035 sdbusplus::SdBusMock sdbus_mock;
36 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
37
38 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture74059d62019-05-17 10:40:26 -070039 std::move(bus_mock), blobs, data, "");
Patrick Venturedf848ee2018-11-06 15:44:00 -080040
41 for (const auto& item : items)
42 {
43 EXPECT_EQ(item.expected, handler->canHandleBlob(item.name));
44 }
45}
46} // namespace blobs