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