blob: 700a75a0ad9b9ab83d7bd80e41e9d8ee79461559 [file] [log] [blame]
Patrick Venture21be45a2018-11-06 12:08:52 -08001#include "firmware_handler.hpp"
Patrick Venture84778b82019-06-26 20:11:09 -07002#include "flags.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08003#include "image_mock.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -07004#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07005#include "util.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08006
Patrick Venture52854622018-11-06 12:30:00 -08007#include <algorithm>
Patrick Ventured4e20de2019-07-18 12:48:05 -07008#include <memory>
Patrick Venturea78e39f2018-11-06 18:37:06 -08009#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -080010
11#include <gtest/gtest.h>
12
Patrick Venture1d5a31c2019-05-20 11:38:22 -070013namespace ipmi_flash
Patrick Venture21be45a2018-11-06 12:08:52 -080014{
Patrick Venture930c7b72019-05-24 11:11:08 -070015namespace
16{
17
18using ::testing::UnorderedElementsAreArray;
Patrick Venture52854622018-11-06 12:30:00 -080019
20TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080021{
Patrick Venture1cde5f92018-11-07 08:26:47 -080022 std::vector<DataHandlerPack> data = {
Patrick Venture84778b82019-06-26 20:11:09 -070023 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080024 };
25
Patrick Venture4eb55952018-11-16 15:36:24 -080026 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venturefa06a5f2019-07-01 09:22:38 -070027 {}, data, std::move(CreateActionMap("abcd")));
Patrick Venture1cde5f92018-11-07 08:26:47 -080028 EXPECT_EQ(handler, nullptr);
29}
30TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
31{
32 ImageHandlerMock imageMock;
33
Patrick Ventured4e20de2019-07-18 12:48:05 -070034 std::vector<HandlerPack> blobs;
35 blobs.push_back(std::move(
36 HandlerPack(hashBlobId, std::make_unique<ImageHandlerMock>())));
37 blobs.push_back(
38 std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>())));
Patrick Venture1cde5f92018-11-07 08:26:47 -080039
Patrick Venture4eb55952018-11-16 15:36:24 -080040 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventured4e20de2019-07-18 12:48:05 -070041 std::move(blobs), {}, std::move(CreateActionMap("asdf")));
Patrick Venture52854622018-11-06 12:30:00 -080042 EXPECT_EQ(handler, nullptr);
43}
Patrick Venture18235e62018-11-08 10:21:09 -080044TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
Patrick Venture52854622018-11-06 12:30:00 -080045{
Patrick Venture1cde5f92018-11-07 08:26:47 -080046 std::vector<DataHandlerPack> data = {
Patrick Venture84778b82019-06-26 20:11:09 -070047 {FirmwareFlags::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080048 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080049
Patrick Ventured4e20de2019-07-18 12:48:05 -070050 /* This works fine only if you also pass in the hash handler. */
51 std::vector<HandlerPack> blobs;
52 blobs.push_back(
53 std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>())));
54
Patrick Venture4eb55952018-11-16 15:36:24 -080055 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventured4e20de2019-07-18 12:48:05 -070056 std::move(blobs), data, std::move(CreateActionMap("asdf")));
Patrick Venture18235e62018-11-08 10:21:09 -080057 EXPECT_EQ(handler, nullptr);
58
Patrick Ventured4e20de2019-07-18 12:48:05 -070059 std::vector<HandlerPack> blobs2;
60 blobs2.push_back(
61 std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>())));
62 blobs2.push_back(std::move(
63 HandlerPack(hashBlobId, std::make_unique<ImageHandlerMock>())));
Patrick Venture18235e62018-11-08 10:21:09 -080064
Patrick Venture4eb55952018-11-16 15:36:24 -080065 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Ventured4e20de2019-07-18 12:48:05 -070066 std::move(blobs2), data, std::move(CreateActionMap("asdf")));
Patrick Venturefa06a5f2019-07-01 09:22:38 -070067
Patrick Venture21be45a2018-11-06 12:08:52 -080068 auto result = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070069 std::vector<std::string> expectedBlobs = {"asdf", hashBlobId};
70 EXPECT_THAT(result, UnorderedElementsAreArray(expectedBlobs));
Patrick Venture21be45a2018-11-06 12:08:52 -080071}
Patrick Venture930c7b72019-05-24 11:11:08 -070072
73} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070074} // namespace ipmi_flash