-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockBtAdminServer.go
221 lines (195 loc) · 6.6 KB
/
mockBtAdminServer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package mockcbt
// A simple mock server.
import (
"context"
empty "google.golang.org/protobuf/types/known/emptypb"
gsrv "github.com/weathersource/go-gsrv"
pb "google.golang.org/genproto/googleapis/bigtable/admin/v2"
v1 "google.golang.org/genproto/googleapis/iam/v1"
"google.golang.org/genproto/googleapis/longrunning"
)
type MockBtAdminServer struct {
*MockServer
}
func newBtAdminServer() (*MockBtAdminServer, error) {
srv, err := gsrv.NewServer()
if err != nil {
return nil, err
}
mock := &MockBtAdminServer{&MockServer{Addr: srv.Addr}}
pb.RegisterBigtableInstanceAdminServer(srv.Gsrv, mock)
srv.Start()
return mock, nil
}
// Create an instance within a project.
func (s *MockBtAdminServer) CreateInstance(ctx context.Context, req *pb.CreateInstanceRequest) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// Gets information about an instance.
func (s *MockBtAdminServer) GetInstance(ctx context.Context, req *pb.GetInstanceRequest) (*pb.Instance, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.Instance), nil
}
// Lists information about instances in a project.
func (s *MockBtAdminServer) ListInstances(ctx context.Context, req *pb.ListInstancesRequest) (*pb.ListInstancesResponse, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.ListInstancesResponse), nil
}
// Updates an instance within a project.
func (s *MockBtAdminServer) UpdateInstance(ctx context.Context, req *pb.Instance) (*pb.Instance, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.Instance), nil
}
// Partially updates an instance within a project.
func (s *MockBtAdminServer) PartialUpdateInstance(ctx context.Context, req *pb.PartialUpdateInstanceRequest) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// Delete an instance from a project.
func (s *MockBtAdminServer) DeleteInstance(ctx context.Context, req *pb.DeleteInstanceRequest) (*empty.Empty, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*empty.Empty), nil
}
// Creates a cluster within an instance.
func (s *MockBtAdminServer) CreateCluster(ctx context.Context, req *pb.CreateClusterRequest) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// Gets information about a cluster.
func (s *MockBtAdminServer) GetCluster(ctx context.Context, req *pb.GetClusterRequest) (*pb.Cluster, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.Cluster), nil
}
// Lists information about clusters in an instance.
func (s *MockBtAdminServer) ListClusters(ctx context.Context, req *pb.ListClustersRequest) (*pb.ListClustersResponse, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.ListClustersResponse), nil
}
// Updates a cluster within an instance.
func (s *MockBtAdminServer) UpdateCluster(ctx context.Context, req *pb.Cluster) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// To disable autoscaling, clear cluster_config.cluster_autoscaling_config,
// and explicitly set a serve_node count via the update_mask.
func (s *MockBtAdminServer) PartialUpdateCluster(ctx context.Context, req *pb.PartialUpdateClusterRequest) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// Deletes a cluster from an instance.
func (s *MockBtAdminServer) DeleteCluster(ctx context.Context, req *pb.DeleteClusterRequest) (*empty.Empty, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*empty.Empty), nil
}
// Creates an app profile within an instance.
func (s *MockBtAdminServer) CreateAppProfile(ctx context.Context, req *pb.CreateAppProfileRequest) (*pb.AppProfile, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.AppProfile), nil
}
// Gets information about an app profile.
func (s *MockBtAdminServer) GetAppProfile(ctx context.Context, req *pb.GetAppProfileRequest) (*pb.AppProfile, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.AppProfile), nil
}
// Lists information about app profiles in an instance.
func (s *MockBtAdminServer) ListAppProfiles(ctx context.Context, req *pb.ListAppProfilesRequest) (*pb.ListAppProfilesResponse, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.ListAppProfilesResponse), nil
}
// Updates an app profile within an instance.
func (s *MockBtAdminServer) UpdateAppProfile(ctx context.Context, req *pb.UpdateAppProfileRequest) (*longrunning.Operation, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*longrunning.Operation), nil
}
// Deletes an app profile from an instance.
func (s *MockBtAdminServer) DeleteAppProfile(ctx context.Context, req *pb.DeleteAppProfileRequest) (*empty.Empty, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*empty.Empty), nil
}
// Gets the access control policy for an instance resource. Returns an empty
// policy if an instance exists but does not have a policy set.
func (s *MockBtAdminServer) GetIamPolicy(ctx context.Context, req *v1.GetIamPolicyRequest) (*v1.Policy, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*v1.Policy), nil
}
// Sets the access control policy on an instance resource. Replaces any
// existing policy.
func (s *MockBtAdminServer) SetIamPolicy(ctx context.Context, req *v1.SetIamPolicyRequest) (*v1.Policy, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*v1.Policy), nil
}
// Returns permissions that the caller has on the specified instance resource.
func (s *MockBtAdminServer) TestIamPermissions(ctx context.Context, req *v1.TestIamPermissionsRequest) (*v1.TestIamPermissionsResponse, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*v1.TestIamPermissionsResponse), nil
}
// Lists hot tablets in a cluster, within the time range provided. Hot
// tablets are ordered based on CPU usage.
func (s *MockBtAdminServer) ListHotTablets(ctx context.Context, req *pb.ListHotTabletsRequest) (*pb.ListHotTabletsResponse, error) {
res, err := s.popRPC(req)
if err != nil {
return nil, err
}
return res.(*pb.ListHotTabletsResponse), nil
}