blob: 4f66278655f2a29d15fedb26f84666a49763c1b7 [file] [log] [blame]
Patrick Venturecd8dab42019-01-15 19:57:38 -08001#include "blob_mock.hpp"
2#include "manager.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
Patrick Venture8bc11772019-06-04 07:20:24 -070020 BlobMeta meta;
Patrick Ventureef3aead2018-09-12 08:53:29 -070021 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
Patrick Venture8bc11772019-06-04 07:20:24 -070036 BlobMeta meta;
Patrick Ventureef3aead2018-09-12 08:53:29 -070037 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
Patrick Venture8bc11772019-06-04 07:20:24 -070053 BlobMeta meta;
Patrick Ventureef3aead2018-09-12 08:53:29 -070054 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