blob: a13a66d9d5bc37ca8b36461ac06dcebf69aa52d9 [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
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