blob: 85ad81b39b0729e8676fbb7494520c4b7d2cdacf [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::_;
11using ::testing::Return;
12
13TEST(ManagerCloseTest, CloseNoSessionReturnsFalse)
14{
15 // Calling Close on a session that doesn't exist should return false.
16
17 BlobManager mgr;
18 uint16_t sess = 1;
19
20 EXPECT_FALSE(mgr.close(sess));
21}
22
23TEST(ManagerCloseTest, CloseSessionFoundButHandlerReturnsFalse)
24{
25 // The handler was found but it returned failure.
26
27 BlobManager mgr;
28 std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
29 auto m1ptr = m1.get();
30 EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
31
32 uint16_t flags = OpenFlags::read, sess;
33 std::string path = "/asdf/asdf";
34
35 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
36 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
37 EXPECT_TRUE(mgr.open(flags, path, &sess));
38
39 EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(false));
40
41 EXPECT_FALSE(mgr.close(sess));
42
43 // TODO(venture): The session wasn't closed, need to verify. Could call
44 // public GetHandler method.
45}
46
47TEST(ManagerCloseTest, CloseSessionFoundAndHandlerReturnsSuccess)
48{
49 // The handler was found and returned success.
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 = OpenFlags::read, sess;
57 std::string path = "/asdf/asdf";
58
59 EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
60 EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
61 EXPECT_TRUE(mgr.open(flags, path, &sess));
62
63 EXPECT_CALL(*m1ptr, close(sess)).WillOnce(Return(true));
64
65 EXPECT_TRUE(mgr.close(sess));
66}
67} // namespace blobs