summaryrefslogtreecommitdiffstats
path: root/test/manager_stat_unittest.cpp
blob: 4f66278655f2a29d15fedb26f84666a49763c1b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "blob_mock.hpp"
#include "manager.hpp"

#include <gtest/gtest.h>

namespace blobs
{

using ::testing::Return;

TEST(ManagerStatTest, StatNoHandler)
{
    // There is no handler for this path.

    BlobManager mgr;
    std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
    auto m1ptr = m1.get();
    EXPECT_TRUE(mgr.registerHandler(std::move(m1)));

    BlobMeta meta;
    std::string path = "/asdf/asdf";
    EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false));

    EXPECT_FALSE(mgr.stat(path, &meta));
}

TEST(ManagerStatTest, StatHandlerFoundButFails)
{
    // There is a handler for this path but Stat fails.

    BlobManager mgr;
    std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
    auto m1ptr = m1.get();
    EXPECT_TRUE(mgr.registerHandler(std::move(m1)));

    BlobMeta meta;
    std::string path = "/asdf/asdf";
    EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
    EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(false));

    EXPECT_FALSE(mgr.stat(path, &meta));
}

TEST(ManagerStatTest, StatHandlerFoundAndSucceeds)
{
    // There is a handler and Stat succeeds.

    BlobManager mgr;
    std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
    auto m1ptr = m1.get();
    EXPECT_TRUE(mgr.registerHandler(std::move(m1)));

    BlobMeta meta;
    std::string path = "/asdf/asdf";
    EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
    EXPECT_CALL(*m1ptr, stat(path, &meta)).WillOnce(Return(true));

    EXPECT_TRUE(mgr.stat(path, &meta));
}
} // namespace blobs
OpenPOWER on IntegriCloud