1 #include "ipmi.hpp"
2 #include "manager_mock.hpp"
3 
4 #include <cstring>
5 #include <string>
6 
7 #include <gtest/gtest.h>
8 
9 namespace blobs
10 {
11 
12 using ::testing::Return;
13 
TEST(BlobCloseTest,ManagerRejectsCloseReturnsFailure)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;
21     std::vector<uint8_t> request;
22     struct BmcBlobCloseTx req;
23 
24     req.crc = 0;
25     req.sessionId = sessionId;
26 
27     dataLen = sizeof(req);
28     request.resize(dataLen);
29     std::memcpy(request.data(), &req, dataLen);
30 
31     EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(false));
32     EXPECT_EQ(ipmi::responseUnspecifiedError(), closeBlob(&mgr, request));
33 }
34 
TEST(BlobCloseTest,BlobClosedReturnsSuccess)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;
42     std::vector<uint8_t> request;
43     struct BmcBlobCloseTx req;
44 
45     req.crc = 0;
46     req.sessionId = sessionId;
47 
48     dataLen = sizeof(req);
49     request.resize(dataLen);
50     std::memcpy(request.data(), &req, dataLen);
51 
52     EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(true));
53     EXPECT_EQ(ipmi::responseSuccess(std::vector<uint8_t>{}),
54               closeBlob(&mgr, request));
55 }
56 } // namespace blobs
57