blob: 0ae7822b50c879567c412171e657c3d0558c36d7 [file] [log] [blame]
Patrick Ventureaceb4ba2018-09-27 14:50:37 -07001#include <blobs-ipmid/manager.hpp>
Patrick Venture7210b312018-10-03 14:01:35 -07002#include <blobs-ipmid/test/blob_mock.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -07003
4#include <gtest/gtest.h>
5
6namespace blobs
7{
8
9using ::testing::Return;
10
11TEST(ManagerStatTest, StatNoHandler)
12{
13 // There is no handler for this path.
14
15 BlobManager mgr;
16 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
17 auto m1ptr = m1.get();
18 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
19
20 struct BlobMeta meta;
21 std::string path = "/asdf/asdf";
22 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false));
23
24 EXPECT_FALSE(mgr.stat(path, &meta));
25}
26
27TEST(ManagerStatTest, StatHandlerFoundButFails)
28{
29 // There is a handler for this path but Stat fails.
30
31 BlobManager mgr;
32 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
33 auto m1ptr = m1.get();
34 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
35
36 struct BlobMeta meta;
37 std::string path = "/asdf/asdf";
38 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
39 EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(false));
40
41 EXPECT_FALSE(mgr.stat(path, &meta));
42}
43
44TEST(ManagerStatTest, StatHandlerFoundAndSucceeds)
45{
46 // There is a handler and Stat succeeds.
47
48 BlobManager mgr;
49 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
50 auto m1ptr = m1.get();
51 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
52
53 struct BlobMeta meta;
54 std::string path = "/asdf/asdf";
55 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
56 EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(true));
57
58 EXPECT_TRUE(mgr.stat(path, &meta));
59}
60} // namespace blobs