]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/rbd_mirror/test_mock_fixture.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / 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 ::testing::NiceMock<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 dynamic_cast<librados::MockTestMemCluster*>(
43 librados_test_stub::get_cluster().get())->default_to_dispatch();
44
45 TestFixture::TearDown();
46 }
47
48 void TestMockFixture::expect_test_features(librbd::MockImageCtx &mock_image_ctx) {
49 EXPECT_CALL(mock_image_ctx, test_features(_, _))
50 .WillRepeatedly(WithArg<0>(Invoke([&mock_image_ctx](uint64_t features) {
51 return (mock_image_ctx.features & features) != 0;
52 })));
53 }
54
55 librados::MockTestMemCluster& TestMockFixture::get_mock_cluster() {
56 librados::MockTestMemCluster* mock_cluster = dynamic_cast<
57 librados::MockTestMemCluster*>(librados_test_stub::get_cluster().get());
58 ceph_assert(mock_cluster != nullptr);
59 return *mock_cluster;
60 }
61
62 } // namespace mirror
63 } // namespace rbd
64