1 #include "helper.hpp"
2 #include "ipmi.hpp"
3 #include "manager_mock.hpp"
4
5 #include <cstring>
6 #include <string>
7
8 #include <gtest/gtest.h>
9
10 namespace blobs
11 {
12
13 using ::testing::Return;
14
TEST(BlobEnumerateTest,VerifyIfRequestByIdInvalidReturnsFailure)15 TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure)
16 {
17 // This tests to verify that if the index is invalid, it'll return failure.
18
19 ManagerMock mgr;
20 std::vector<uint8_t> request;
21 struct BmcBlobEnumerateTx req;
22 req.blobIdx = 0;
23
24 request.resize(sizeof(struct BmcBlobEnumerateTx));
25 std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
26
27 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(""));
28 EXPECT_EQ(ipmi::responseInvalidFieldRequest(),
29 enumerateBlob(&mgr, request));
30 }
31
TEST(BlobEnumerateTest,BoringRequestByIdAndReceive)32 TEST(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;
38 std::vector<uint8_t> request;
39 struct BmcBlobEnumerateTx req;
40 req.blobIdx = 0;
41 std::string blobId = "/asdf";
42
43 request.resize(sizeof(struct BmcBlobEnumerateTx));
44 std::memcpy(request.data(), &req, sizeof(struct BmcBlobEnumerateTx));
45
46 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
47
48 auto result = validateReply(enumerateBlob(&mgr, request));
49
50 // We're expecting this as a response.
51 // blobId.length + 1 + sizeof(uint16_t);
52 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));
56 }
57 } // namespace blobs
58