blob: dc1202d4ba70e0399def065a89ae688aef8bb572 [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 <vector>
7
8#include <gtest/gtest.h>
9
10namespace blobs
11{
12
13using ::testing::Return;
14
Patrick Ventureef3aead2018-09-12 08:53:29 -070015// the request here is only the subcommand byte and therefore there's no invalid
16// length check, etc to handle within the method.
17
18TEST(BlobCountTest, ReturnsZeroBlobs)
19{
20 // Calling BmcBlobGetCount if there are no handlers registered should just
21 // return that there are 0 blobs.
22
23 ManagerMock mgr;
Patrick Ventureef3aead2018-09-12 08:53:29 -070024 struct BmcBlobCountRx rep;
Patrick Ventureef3aead2018-09-12 08:53:29 -070025
26 rep.crc = 0;
27 rep.blobCount = 0;
28
29 EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(0));
30
Willy Tu067ece12022-06-16 02:07:06 -070031 auto result = validateReply(getBlobCount(&mgr, {}));
Patrick Ventureef3aead2018-09-12 08:53:29 -070032
Willy Tu067ece12022-06-16 02:07:06 -070033 EXPECT_EQ(sizeof(rep), result.size());
34 EXPECT_EQ(0, std::memcmp(result.data(), &rep, sizeof(rep)));
Patrick Ventureef3aead2018-09-12 08:53:29 -070035}
36
37TEST(BlobCountTest, ReturnsTwoBlobs)
38{
39 // Calling BmcBlobGetCount with one handler registered that knows of two
40 // blobs will return that it found two blobs.
41
42 ManagerMock mgr;
Patrick Ventureef3aead2018-09-12 08:53:29 -070043 struct BmcBlobCountRx rep;
Patrick Ventureef3aead2018-09-12 08:53:29 -070044
45 rep.crc = 0;
46 rep.blobCount = 2;
47
48 EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(2));
49
Willy Tu067ece12022-06-16 02:07:06 -070050 auto result = validateReply(getBlobCount(&mgr, {}));
Patrick Ventureef3aead2018-09-12 08:53:29 -070051
Willy Tu067ece12022-06-16 02:07:06 -070052 EXPECT_EQ(sizeof(rep), result.size());
53 EXPECT_EQ(0, std::memcmp(result.data(), &rep, sizeof(rep)));
Patrick Ventureef3aead2018-09-12 08:53:29 -070054}
55} // namespace blobs