]>
Commit | Line | Data |
---|---|---|
d2e6a577 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 "cls/rbd/cls_rbd_types.h" | |
6 | #include "librbd/journal/TypeTraits.h" | |
7 | #include "tools/rbd_mirror/image_replayer/GetMirrorImageIdRequest.h" | |
8 | #include "test/journal/mock/MockJournaler.h" | |
9 | #include "test/librados_test_stub/MockTestMemIoCtxImpl.h" | |
10 | #include "test/librbd/mock/MockImageCtx.h" | |
11 | #include "test/librbd/mock/MockJournal.h" | |
12 | ||
13 | namespace librbd { | |
14 | ||
15 | namespace { | |
16 | ||
17 | struct MockTestImageCtx : public librbd::MockImageCtx { | |
18 | MockTestImageCtx(librbd::ImageCtx &image_ctx) | |
19 | : librbd::MockImageCtx(image_ctx) { | |
20 | } | |
21 | }; | |
22 | ||
23 | } // anonymous namespace | |
24 | } // namespace librbd | |
25 | ||
26 | // template definitions | |
27 | #include "tools/rbd_mirror/image_replayer/GetMirrorImageIdRequest.cc" | |
28 | ||
29 | namespace rbd { | |
30 | namespace mirror { | |
31 | namespace image_replayer { | |
32 | ||
33 | using ::testing::_; | |
34 | using ::testing::DoAll; | |
35 | using ::testing::InSequence; | |
36 | using ::testing::Invoke; | |
37 | using ::testing::Return; | |
38 | using ::testing::StrEq; | |
39 | using ::testing::WithArg; | |
40 | using ::testing::WithArgs; | |
41 | ||
42 | class TestMockImageReplayerGetMirrorImageIdRequest : public TestMockFixture { | |
43 | public: | |
44 | typedef GetMirrorImageIdRequest<librbd::MockTestImageCtx> MockGetMirrorImageIdRequest; | |
45 | ||
46 | void expect_mirror_image_get_image_id(librados::IoCtx &io_ctx, | |
47 | const std::string &image_id, int r) { | |
48 | bufferlist bl; | |
11fdf7f2 | 49 | encode(image_id, bl); |
d2e6a577 FG |
50 | |
51 | EXPECT_CALL(get_mock_io_ctx(io_ctx), | |
52 | exec(RBD_MIRRORING, _, StrEq("rbd"), StrEq("mirror_image_get_image_id"), _, _, _)) | |
53 | .WillOnce(DoAll(WithArg<5>(Invoke([bl](bufferlist *out_bl) { | |
54 | *out_bl = bl; | |
55 | })), | |
56 | Return(r))); | |
57 | } | |
58 | ||
59 | }; | |
60 | ||
61 | TEST_F(TestMockImageReplayerGetMirrorImageIdRequest, Success) { | |
62 | InSequence seq; | |
63 | expect_mirror_image_get_image_id(m_local_io_ctx, "image id", 0); | |
64 | ||
65 | std::string image_id; | |
66 | C_SaferCond ctx; | |
67 | auto req = MockGetMirrorImageIdRequest::create(m_local_io_ctx, | |
68 | "global image id", | |
69 | &image_id, &ctx); | |
70 | req->send(); | |
71 | ||
72 | ASSERT_EQ(0, ctx.wait()); | |
73 | ASSERT_EQ(std::string("image id"), image_id); | |
74 | } | |
75 | ||
76 | TEST_F(TestMockImageReplayerGetMirrorImageIdRequest, MirrorImageIdDNE) { | |
77 | InSequence seq; | |
78 | expect_mirror_image_get_image_id(m_local_io_ctx, "", -ENOENT); | |
79 | ||
80 | std::string image_id; | |
81 | C_SaferCond ctx; | |
82 | auto req = MockGetMirrorImageIdRequest::create(m_local_io_ctx, | |
83 | "global image id", | |
84 | &image_id, &ctx); | |
85 | req->send(); | |
86 | ||
87 | ASSERT_EQ(-ENOENT, ctx.wait()); | |
88 | } | |
89 | ||
90 | TEST_F(TestMockImageReplayerGetMirrorImageIdRequest, MirrorImageIdError) { | |
91 | InSequence seq; | |
92 | expect_mirror_image_get_image_id(m_local_io_ctx, "", -EINVAL); | |
93 | ||
94 | std::string image_id; | |
95 | C_SaferCond ctx; | |
96 | auto req = MockGetMirrorImageIdRequest::create(m_local_io_ctx, | |
97 | "global image id", | |
98 | &image_id, &ctx); | |
99 | req->send(); | |
100 | ||
101 | ASSERT_EQ(-EINVAL, ctx.wait()); | |
102 | } | |
103 | ||
104 | } // namespace image_replayer | |
105 | } // namespace mirror | |
106 | } // namespace rbd |