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