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_MOCKCSIPLUGIN_HPP__
18 #define __TESTS_MOCKCSIPLUGIN_HPP__
19 
20 #include <memory>
21 #include <string>
22 
23 #include <gmock/gmock.h>
24 
25 #include <grpc++/grpc++.h>
26 
27 #include <stout/nothing.hpp>
28 #include <stout/try.hpp>
29 
30 #include <csi/spec.hpp>
31 
32 namespace mesos {
33 namespace internal {
34 namespace tests {
35 
36 #define CSI_METHOD_FOREACH(macro) \
37  macro(GetSupportedVersions) \
38  macro(GetPluginInfo) \
39  macro(CreateVolume) \
40  macro(DeleteVolume) \
41  macro(ControllerPublishVolume) \
42  macro(ControllerUnpublishVolume) \
43  macro(ValidateVolumeCapabilities) \
44  macro(ListVolumes) \
45  macro(GetCapacity) \
46  macro(ControllerProbe) \
47  macro(ControllerGetCapabilities) \
48  macro(NodePublishVolume) \
49  macro(NodeUnpublishVolume) \
50  macro(GetNodeID) \
51  macro(NodeProbe) \
52  macro(NodeGetCapabilities)
53 
54 #define DECLARE_MOCK_CSI_METHOD(name) \
55  MOCK_METHOD3(name, grpc::Status( \
56  grpc::ServerContext* context, \
57  const csi::name##Request* request, \
58  csi::name##Response* response));
59 
60 // Definition of a mock CSI plugin to be used in tests with gmock.
61 class MockCSIPlugin : public csi::Identity::Service,
62  public csi::Controller::Service,
63  public csi::Node::Service
64 {
65 public:
66  MockCSIPlugin();
67 
69 
70  Try<Nothing> Startup(const std::string& address);
72 
73 private:
74  std::unique_ptr<grpc::Server> server;
75 };
76 
77 } // namespace tests {
78 } // namespace internal {
79 } // namespace mesos {
80 
81 #endif // __TESTS_MOCKCSIPLUGIN_HPP__
#define CSI_METHOD_FOREACH(macro)
Definition: mock_csi_plugin.hpp:36
Definition: try.hpp:34
Try< Address > address(int_fd s)
Returns the Address with the assigned ip and assigned port.
Definition: network.hpp:79
Definition: mock_csi_plugin.hpp:61
Try< Nothing > Startup(const std::string &address)
#define DECLARE_MOCK_CSI_METHOD(name)
Definition: mock_csi_plugin.hpp:54