blob: 72aff85c5700302f10e6eba3741b5590de392b50 [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#include <string>
4
5#include <gtest/gtest.h>
6
7namespace blobs
8{
9
10using ::testing::_;
11using ::testing::Return;
12
13TEST(ManagerOpenTest, OpenButNoHandler)
14{
15 // No handler claims to be able to open the file.
16
17 BlobManager mgr;
18 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
19 auto m1ptr = m1.get();
20 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
21
22 uint16_t flags = OpenFlags::read, sess;
23 std::string path = "/asdf/asdf";
24
25 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(false));
26 EXPECT_FALSE(mgr.open(flags, path, &sess));
27}
28
29TEST(ManagerOpenTest, OpenButHandlerFailsOpen)
30{
31 // The handler is found but Open fails.
32
33 BlobManager mgr;
34 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
35 auto m1ptr = m1.get();
36 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
37
38 uint16_t flags = OpenFlags::read, sess;
39 std::string path = "/asdf/asdf";
40
41 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
42 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(false));
43 EXPECT_FALSE(mgr.open(flags, path, &sess));
44}
45
46TEST(ManagerOpenTest, OpenFailsMustSupplyAtLeastReadOrWriteFlag)
47{
48 // One must supply either read or write in the flags for the session to
49 // open.
50
51 BlobManager mgr;
52 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
53 auto m1ptr = m1.get();
54 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
55
56 uint16_t flags = 0, sess;
57 std::string path = "/asdf/asdf";
58
59 /* It checks if someone can handle the blob before it checks the flags. */
60 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
61
62 EXPECT_FALSE(mgr.open(flags, path, &sess));
63}
64
65TEST(ManagerOpenTest, OpenSucceeds)
66{
67 // The handler is found and Open succeeds.
68
69 BlobManager mgr;
70 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
71 auto m1ptr = m1.get();
72 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
73
74 uint16_t flags = OpenFlags::read, sess;
75 std::string path = "/asdf/asdf";
76
77 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
78 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
79 EXPECT_TRUE(mgr.open(flags, path, &sess));
80
81 // TODO(venture): Need a way to verify the session is associated with it,
82 // maybe just call Read() or SessionStat()
83}
84} // namespace blobs