Apache Mesos
mock_csi_plugin.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __TESTS_MOCK_CSI_PLUGIN_HPP__
18 #define __TESTS_MOCK_CSI_PLUGIN_HPP__
19 
20 #include <memory>
21 #include <string>
22 
23 #include <gmock/gmock.h>
24 
25 #include <grpcpp/grpcpp.h>
26 
27 #include <mesos/csi/v0.hpp>
28 #include <mesos/csi/v1.hpp>
29 
30 #include <process/grpc.hpp>
31 
32 #include <stout/none.hpp>
33 #include <stout/nothing.hpp>
34 #include <stout/option.hpp>
35 #include <stout/try.hpp>
36 
37 namespace mesos {
38 namespace internal {
39 namespace tests {
40 
41 // Definition of a mock CSI plugin to be used in tests with gmock.
49 {
50 public:
51  MockCSIPlugin();
52 
53  // CSI v0 RPCs.
54 
55  MOCK_METHOD3(GetPluginInfo, grpc::Status(
56  grpc::ServerContext*,
57  const csi::v0::GetPluginInfoRequest*,
58  csi::v0::GetPluginInfoResponse*));
59 
60  MOCK_METHOD3(GetPluginCapabilities, grpc::Status(
61  grpc::ServerContext*,
62  const csi::v0::GetPluginCapabilitiesRequest*,
63  csi::v0::GetPluginCapabilitiesResponse*));
64 
65  MOCK_METHOD3(Probe, grpc::Status(
66  grpc::ServerContext*,
67  const csi::v0::ProbeRequest*,
68  csi::v0::ProbeResponse*));
69 
70  MOCK_METHOD3(CreateVolume, grpc::Status(
71  grpc::ServerContext*,
72  const csi::v0::CreateVolumeRequest*,
73  csi::v0::CreateVolumeResponse*));
74 
75  MOCK_METHOD3(DeleteVolume, grpc::Status(
76  grpc::ServerContext*,
77  const csi::v0::DeleteVolumeRequest*,
78  csi::v0::DeleteVolumeResponse*));
79 
80  MOCK_METHOD3(ControllerPublishVolume, grpc::Status(
81  grpc::ServerContext*,
82  const csi::v0::ControllerPublishVolumeRequest*,
83  csi::v0::ControllerPublishVolumeResponse*));
84 
85  MOCK_METHOD3(ControllerUnpublishVolume, grpc::Status(
86  grpc::ServerContext*,
87  const csi::v0::ControllerUnpublishVolumeRequest*,
88  csi::v0::ControllerUnpublishVolumeResponse*));
89 
90  MOCK_METHOD3(ValidateVolumeCapabilities, grpc::Status(
91  grpc::ServerContext*,
92  const csi::v0::ValidateVolumeCapabilitiesRequest*,
93  csi::v0::ValidateVolumeCapabilitiesResponse*));
94 
95  MOCK_METHOD3(ListVolumes, grpc::Status(
96  grpc::ServerContext*,
97  const csi::v0::ListVolumesRequest*,
98  csi::v0::ListVolumesResponse*));
99 
100  MOCK_METHOD3(GetCapacity, grpc::Status(
101  grpc::ServerContext*,
102  const csi::v0::GetCapacityRequest*,
103  csi::v0::GetCapacityResponse*));
104 
105  MOCK_METHOD3(ControllerGetCapabilities, grpc::Status(
106  grpc::ServerContext*,
107  const csi::v0::ControllerGetCapabilitiesRequest*,
108  csi::v0::ControllerGetCapabilitiesResponse*));
109 
110  MOCK_METHOD3(NodeStageVolume, grpc::Status(
111  grpc::ServerContext*,
112  const csi::v0::NodeStageVolumeRequest*,
113  csi::v0::NodeStageVolumeResponse*));
114 
115  MOCK_METHOD3(NodeUnstageVolume, grpc::Status(
116  grpc::ServerContext*,
117  const csi::v0::NodeUnstageVolumeRequest*,
118  csi::v0::NodeUnstageVolumeResponse*));
119 
120  MOCK_METHOD3(NodePublishVolume, grpc::Status(
121  grpc::ServerContext*,
122  const csi::v0::NodePublishVolumeRequest*,
123  csi::v0::NodePublishVolumeResponse*));
124 
125  MOCK_METHOD3(NodeUnpublishVolume, grpc::Status(
126  grpc::ServerContext*,
127  const csi::v0::NodeUnpublishVolumeRequest*,
128  csi::v0::NodeUnpublishVolumeResponse*));
129 
130  MOCK_METHOD3(NodeGetId, grpc::Status(
131  grpc::ServerContext*,
132  const csi::v0::NodeGetIdRequest*,
133  csi::v0::NodeGetIdResponse*));
134 
135  MOCK_METHOD3(NodeGetCapabilities, grpc::Status(
136  grpc::ServerContext*,
137  const csi::v0::NodeGetCapabilitiesRequest*,
138  csi::v0::NodeGetCapabilitiesResponse*));
139 
140  // CSI v1 RPCs.
141 
142  MOCK_METHOD3(GetPluginInfo, grpc::Status(
143  grpc::ServerContext*,
144  const csi::v1::GetPluginInfoRequest*,
145  csi::v1::GetPluginInfoResponse*));
146 
147  MOCK_METHOD3(GetPluginCapabilities, grpc::Status(
148  grpc::ServerContext*,
149  const csi::v1::GetPluginCapabilitiesRequest*,
150  csi::v1::GetPluginCapabilitiesResponse*));
151 
152  MOCK_METHOD3(Probe, grpc::Status(
153  grpc::ServerContext*,
154  const csi::v1::ProbeRequest*,
155  csi::v1::ProbeResponse*));
156 
157  MOCK_METHOD3(CreateVolume, grpc::Status(
158  grpc::ServerContext*,
159  const csi::v1::CreateVolumeRequest*,
160  csi::v1::CreateVolumeResponse*));
161 
162  MOCK_METHOD3(DeleteVolume, grpc::Status(
163  grpc::ServerContext*,
164  const csi::v1::DeleteVolumeRequest*,
165  csi::v1::DeleteVolumeResponse*));
166 
167  MOCK_METHOD3(ControllerPublishVolume, grpc::Status(
168  grpc::ServerContext*,
169  const csi::v1::ControllerPublishVolumeRequest*,
170  csi::v1::ControllerPublishVolumeResponse*));
171 
172  MOCK_METHOD3(ControllerUnpublishVolume, grpc::Status(
173  grpc::ServerContext*,
174  const csi::v1::ControllerUnpublishVolumeRequest*,
175  csi::v1::ControllerUnpublishVolumeResponse*));
176 
177  MOCK_METHOD3(ValidateVolumeCapabilities, grpc::Status(
178  grpc::ServerContext*,
179  const csi::v1::ValidateVolumeCapabilitiesRequest*,
180  csi::v1::ValidateVolumeCapabilitiesResponse*));
181 
182  MOCK_METHOD3(ListVolumes, grpc::Status(
183  grpc::ServerContext*,
184  const csi::v1::ListVolumesRequest*,
185  csi::v1::ListVolumesResponse*));
186 
187  MOCK_METHOD3(GetCapacity, grpc::Status(
188  grpc::ServerContext*,
189  const csi::v1::GetCapacityRequest*,
190  csi::v1::GetCapacityResponse*));
191 
192  MOCK_METHOD3(ControllerGetCapabilities, grpc::Status(
193  grpc::ServerContext*,
194  const csi::v1::ControllerGetCapabilitiesRequest*,
195  csi::v1::ControllerGetCapabilitiesResponse*));
196 
197  MOCK_METHOD3(CreateSnapshot, grpc::Status(
198  grpc::ServerContext*,
199  const csi::v1::CreateSnapshotRequest*,
200  csi::v1::CreateSnapshotResponse*));
201 
202  MOCK_METHOD3(DeleteSnapshot, grpc::Status(
203  grpc::ServerContext*,
204  const csi::v1::DeleteSnapshotRequest*,
205  csi::v1::DeleteSnapshotResponse*));
206 
207  MOCK_METHOD3(ListSnapshots, grpc::Status(
208  grpc::ServerContext*,
209  const csi::v1::ListSnapshotsRequest*,
210  csi::v1::ListSnapshotsResponse*));
211 
212  MOCK_METHOD3(ControllerExpandVolume, grpc::Status(
213  grpc::ServerContext*,
214  const csi::v1::ControllerExpandVolumeRequest*,
215  csi::v1::ControllerExpandVolumeResponse*));
216 
217  MOCK_METHOD3(NodeStageVolume, grpc::Status(
218  grpc::ServerContext*,
219  const csi::v1::NodeStageVolumeRequest*,
220  csi::v1::NodeStageVolumeResponse*));
221 
222  MOCK_METHOD3(NodeUnstageVolume, grpc::Status(
223  grpc::ServerContext*,
224  const csi::v1::NodeUnstageVolumeRequest*,
225  csi::v1::NodeUnstageVolumeResponse*));
226 
227  MOCK_METHOD3(NodePublishVolume, grpc::Status(
228  grpc::ServerContext*,
229  const csi::v1::NodePublishVolumeRequest*,
230  csi::v1::NodePublishVolumeResponse*));
231 
232  MOCK_METHOD3(NodeUnpublishVolume, grpc::Status(
233  grpc::ServerContext*,
234  const csi::v1::NodeUnpublishVolumeRequest*,
235  csi::v1::NodeUnpublishVolumeResponse*));
236 
237  MOCK_METHOD3(NodeGetVolumeStats, grpc::Status(
238  grpc::ServerContext*,
239  const csi::v1::NodeGetVolumeStatsRequest*,
240  csi::v1::NodeGetVolumeStatsResponse*));
241 
242  MOCK_METHOD3(NodeExpandVolume, grpc::Status(
243  grpc::ServerContext*,
244  const csi::v1::NodeExpandVolumeRequest*,
245  csi::v1::NodeExpandVolumeResponse*));
246 
247  MOCK_METHOD3(NodeGetCapabilities, grpc::Status(
248  grpc::ServerContext*,
249  const csi::v1::NodeGetCapabilitiesRequest*,
250  csi::v1::NodeGetCapabilitiesResponse*));
251 
252  MOCK_METHOD3(NodeGetInfo, grpc::Status(
253  grpc::ServerContext*,
254  const csi::v1::NodeGetInfoRequest*,
255  csi::v1::NodeGetInfoResponse*));
256 
258  const Option<std::string>& address = None());
259 
261 
262 private:
263  std::unique_ptr<grpc::Server> server;
264 };
265 
266 } // namespace tests {
267 } // namespace internal {
268 } // namespace mesos {
269 
270 #endif // __TESTS_MOCK_CSI_PLUGIN_HPP__
Try< process::grpc::client::Connection > startup(const Option< std::string > &address=None())
Definition: check.hpp:33
Try< Address > address(int_fd s)
Returns the Address with the assigned ip and assigned port.
Definition: network.hpp:79
Definition: agent.hpp:25
Definition: none.hpp:27
Definition: attributes.hpp:24
Definition: mock_csi_plugin.hpp:42
CSIPluginContainerInfo::Service Service
Definition: service_manager.hpp:38
MOCK_METHOD3(GetPluginInfo, grpc::Status(grpc::ServerContext *, const csi::v0::GetPluginInfoRequest *, csi::v0::GetPluginInfoResponse *))