Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / librbd / object_map / test_mock_UnlockRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "test/librbd/test_mock_fixture.h"
5 #include "test/librbd/test_support.h"
6 #include "test/librbd/mock/MockImageCtx.h"
7 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
8 #include "cls/lock/cls_lock_ops.h"
9 #include "librbd/ObjectMap.h"
10 #include "librbd/object_map/UnlockRequest.h"
11
12 // template definitions
13 #include "librbd/object_map/UnlockRequest.cc"
14
15 namespace librbd {
16 namespace object_map {
17
18 using ::testing::_;
19 using ::testing::InSequence;
20 using ::testing::Return;
21 using ::testing::StrEq;
22
23 class TestMockObjectMapUnlockRequest : public TestMockFixture {
24 public:
25   typedef UnlockRequest<MockImageCtx> MockUnlockRequest;
26
27   void expect_unlock(MockImageCtx &mock_image_ctx, int r) {
28     std::string oid(ObjectMap<>::object_map_name(mock_image_ctx.id,
29                                                  CEPH_NOSNAP));
30     EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx),
31                 exec(oid, _, StrEq("lock"), StrEq("unlock"), _, _, _))
32                   .WillOnce(Return(r));
33   }
34 };
35
36 TEST_F(TestMockObjectMapUnlockRequest, Success) {
37   librbd::ImageCtx *ictx;
38   ASSERT_EQ(0, open_image(m_image_name, &ictx));
39
40   MockImageCtx mock_image_ctx(*ictx);
41
42   C_SaferCond ctx;
43   MockUnlockRequest *req = new MockUnlockRequest(mock_image_ctx, &ctx);
44
45   InSequence seq;
46   expect_unlock(mock_image_ctx, 0);
47   req->send();
48
49   ASSERT_EQ(0, ctx.wait());
50 }
51
52 TEST_F(TestMockObjectMapUnlockRequest, UnlockError) {
53   librbd::ImageCtx *ictx;
54   ASSERT_EQ(0, open_image(m_image_name, &ictx));
55
56   MockImageCtx mock_image_ctx(*ictx);
57
58   C_SaferCond ctx;
59   MockUnlockRequest *req = new MockUnlockRequest(mock_image_ctx, &ctx);
60
61   InSequence seq;
62   expect_unlock(mock_image_ctx, -ENOENT);
63   req->send();
64
65   ASSERT_EQ(0, ctx.wait());
66 }
67
68 } // namespace object_map
69 } // namespace librbd