]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/rbd_mirror/test_mock_fixture.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / test / rbd_mirror / test_mock_fixture.cc
CommitLineData
7c673cae
FG
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
11namespace rbd {
12namespace mirror {
13
14using ::testing::_;
15using ::testing::Invoke;
16using ::testing::WithArg;
17
18TestMockFixture::TestClusterRef TestMockFixture::s_test_cluster;
19
20void 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>(
11fdf7f2 25 new ::testing::NiceMock<librados::MockTestMemCluster>()));
7c673cae
FG
26 TestFixture::SetUpTestCase();
27}
28
29void TestMockFixture::TearDownTestCase() {
30 TestFixture::TearDownTestCase();
31 librados_test_stub::set_cluster(s_test_cluster);
32}
33
34void 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();
11fdf7f2
TL
42 dynamic_cast<librados::MockTestMemCluster*>(
43 librados_test_stub::get_cluster().get())->default_to_dispatch();
7c673cae
FG
44
45 TestFixture::TearDown();
46}
47
48void 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
11fdf7f2
TL
55librados::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
7c673cae
FG
62} // namespace mirror
63} // namespace rbd
64