Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 2 | #include "manager_mock.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 4 | #include <cstring> |
| 5 | #include <string> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace blobs |
| 10 | { |
| 11 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 12 | using ::testing::Return; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 13 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 14 | TEST(BlobCloseTest, ManagerRejectsCloseReturnsFailure) |
| 15 | { |
| 16 | // The session manager returned failure to close, which we need to pass on. |
| 17 | |
| 18 | ManagerMock mgr; |
| 19 | uint16_t sessionId = 0x54; |
| 20 | size_t dataLen; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 21 | std::vector<uint8_t> request; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 22 | struct BmcBlobCloseTx req; |
| 23 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 24 | req.crc = 0; |
| 25 | req.sessionId = sessionId; |
| 26 | |
| 27 | dataLen = sizeof(req); |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 28 | request.resize(dataLen); |
| 29 | std::memcpy(request.data(), &req, dataLen); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 30 | |
| 31 | EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(false)); |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 32 | EXPECT_EQ(ipmi::responseUnspecifiedError(), closeBlob(&mgr, request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | TEST(BlobCloseTest, BlobClosedReturnsSuccess) |
| 36 | { |
| 37 | // Verify that if all goes right, success is returned. |
| 38 | |
| 39 | ManagerMock mgr; |
| 40 | uint16_t sessionId = 0x54; |
| 41 | size_t dataLen; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 42 | std::vector<uint8_t> request; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 43 | struct BmcBlobCloseTx req; |
| 44 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 45 | req.crc = 0; |
| 46 | req.sessionId = sessionId; |
| 47 | |
| 48 | dataLen = sizeof(req); |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 49 | request.resize(dataLen); |
| 50 | std::memcpy(request.data(), &req, dataLen); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 51 | |
| 52 | EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(true)); |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 53 | EXPECT_EQ(ipmi::responseSuccess(std::vector<uint8_t>{}), |
| 54 | closeBlob(&mgr, request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 55 | } |
| 56 | } // namespace blobs |