Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / rbd_mirror / test_mock_fixture.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/rbd_mirror/test_mock_fixture.h"
5 #include "include/rbd/librbd.hpp"
6 #include "test/librados_test_stub/LibradosTestStub.h"
7 #include "test/librados_test_stub/MockTestMemCluster.h"
8 #include "test/librados_test_stub/MockTestMemRadosClient.h"
9 #include "test/librbd/mock/MockImageCtx.h"
10
11 namespace rbd {
12 namespace mirror {
13
14 using ::testing::_;
15 using ::testing::Invoke;
16 using ::testing::WithArg;
17
18 TestMockFixture::TestClusterRef TestMockFixture::s_test_cluster;
19
20 void TestMockFixture::SetUpTestCase() {
21   s_test_cluster = librados_test_stub::get_cluster();
22
23   // use a mock version of the in-memory rados client
24   librados_test_stub::set_cluster(boost::shared_ptr<librados::TestCluster>(
25     new librados::MockTestMemCluster()));
26   TestFixture::SetUpTestCase();
27 }
28
29 void TestMockFixture::TearDownTestCase() {
30   TestFixture::TearDownTestCase();
31   librados_test_stub::set_cluster(s_test_cluster);
32 }
33
34 void TestMockFixture::TearDown() {
35   // Mock rados client lives across tests -- reset it to initial state
36   librados::MockTestMemRadosClient *mock_rados_client =
37     get_mock_io_ctx(m_local_io_ctx).get_mock_rados_client();
38   ASSERT_TRUE(mock_rados_client != nullptr);
39
40   ::testing::Mock::VerifyAndClear(mock_rados_client);
41   mock_rados_client->default_to_dispatch();
42
43   TestFixture::TearDown();
44 }
45
46 void TestMockFixture::expect_test_features(librbd::MockImageCtx &mock_image_ctx) {
47   EXPECT_CALL(mock_image_ctx, test_features(_, _))
48     .WillRepeatedly(WithArg<0>(Invoke([&mock_image_ctx](uint64_t features) {
49         return (mock_image_ctx.features & features) != 0;
50       })));
51 }
52
53 } // namespace mirror
54 } // namespace rbd
55