blob: 87752ea3599e9c37e267a476e1e37dd49ad0fbf4 [file] [log] [blame]
Willy Tu067ece12022-06-16 02:07:06 -07001#include "helper.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07002#include "ipmi.hpp"
Patrick Venturecd8dab42019-01-15 19:57:38 -08003#include "manager_mock.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07004
Patrick Ventureef3aead2018-09-12 08:53:29 -07005#include <cstring>
6#include <string>
7
8#include <gtest/gtest.h>
9
10namespace blobs
11{
12
13using ::testing::Return;
14
Patrick Ventureef3aead2018-09-12 08:53:29 -070015TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure)
16{
17 // This tests to verify that if the index is invalid, it'll return failure.
18
19 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070020 std::vector<uint8_t> request;
Patrick Ventureef3aead2018-09-12 08:53:29 -070021 struct BmcBlobEnumerateTx req;
Patrick Ventureef3aead2018-09-12 08:53:29 -070022 req.blobIdx = 0;
Willy Tu067ece12022-06-16 02:07:06 -070023
24 request.resize(sizeof(struct BmcBlobEnumerateTx));
25 std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
Patrick Ventureef3aead2018-09-12 08:53:29 -070026
27 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(""));
Willy Tu067ece12022-06-16 02:07:06 -070028 EXPECT_EQ(ipmi::responseInvalidFieldRequest(),
29 enumerateBlob(&mgr, request));
Patrick Ventureef3aead2018-09-12 08:53:29 -070030}
31
32TEST(BlobEnumerateTest, BoringRequestByIdAndReceive)
33{
34 // This tests that if an index into the blob_id cache is valid, the command
35 // will return the blobId.
36
37 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070038 std::vector<uint8_t> request;
Patrick Ventureef3aead2018-09-12 08:53:29 -070039 struct BmcBlobEnumerateTx req;
Willy Tu067ece12022-06-16 02:07:06 -070040 req.blobIdx = 0;
Patrick Ventureef3aead2018-09-12 08:53:29 -070041 std::string blobId = "/asdf";
42
Willy Tu067ece12022-06-16 02:07:06 -070043 request.resize(sizeof(struct BmcBlobEnumerateTx));
44 std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
Patrick Ventureef3aead2018-09-12 08:53:29 -070045
46 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
47
Willy Tu067ece12022-06-16 02:07:06 -070048 auto result = validateReply(enumerateBlob(&mgr, request));
Patrick Ventureef3aead2018-09-12 08:53:29 -070049
50 // We're expecting this as a response.
51 // blobId.length + 1 + sizeof(uint16_t);
Willy Tu067ece12022-06-16 02:07:06 -070052 EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), result.size());
53 EXPECT_EQ(blobId,
54 // Remove crc and nul-terminator.
55 std::string(result.begin() + sizeof(uint16_t), result.end() - 1));
Patrick Ventureef3aead2018-09-12 08:53:29 -070056}
57} // namespace blobs