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 <csi/spec.hpp>
24 
25 #include <gmock/gmock.h>
26 
27 #include <grpcpp/grpcpp.h>
28 
29 #include <process/grpc.hpp>
30 
31 #include <stout/none.hpp>
32 #include <stout/nothing.hpp>
33 #include <stout/option.hpp>
34 #include <stout/try.hpp>
35 
36 namespace mesos {
37 namespace internal {
38 namespace tests {
39 
40 #define CSI_METHOD_FOREACH(macro) \
41  macro(GetPluginInfo) \
42  macro(GetPluginCapabilities) \
43  macro(Probe) \
44  macro(CreateVolume) \
45  macro(DeleteVolume) \
46  macro(ControllerPublishVolume) \
47  macro(ControllerUnpublishVolume) \
48  macro(ValidateVolumeCapabilities) \
49  macro(ListVolumes) \
50  macro(GetCapacity) \
51  macro(ControllerGetCapabilities) \
52  macro(NodeStageVolume) \
53  macro(NodeUnstageVolume) \
54  macro(NodePublishVolume) \
55  macro(NodeUnpublishVolume) \
56  macro(NodeGetId) \
57  macro(NodeGetCapabilities)
58 
59 #define DECLARE_MOCK_CSI_METHOD(name) \
60  MOCK_METHOD3(name, grpc::Status( \
61  grpc::ServerContext* context, \
62  const csi::v0::name##Request* request, \
63  csi::v0::name##Response* response));
64 
65 // Definition of a mock CSI plugin to be used in tests with gmock.
66 class MockCSIPlugin : public csi::v0::Identity::Service,
67  public csi::v0::Controller::Service,
68  public csi::v0::Node::Service
69 {
70 public:
71  MockCSIPlugin();
72 
74 
76  const Option<std::string>& address = None());
78 
79 private:
80  std::unique_ptr<grpc::Server> server;
81 };
82 
83 } // namespace tests {
84 } // namespace internal {
85 } // namespace mesos {
86 
87 #endif // __TESTS_MOCKCSIPLUGIN_HPP__
#define CSI_METHOD_FOREACH(macro)
Definition: mock_csi_plugin.hpp:40
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: spec.hpp:30
Definition: none.hpp:27
Definition: attributes.hpp:24
Definition: mock_csi_plugin.hpp:66
#define DECLARE_MOCK_CSI_METHOD(name)
Definition: mock_csi_plugin.hpp:59