1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
18 "git.arvados.org/arvados.git/sdk/go/arvados"
19 "git.arvados.org/arvados.git/sdk/go/httpserver"
22 var ErrStubUnimplemented = errors.New("stub unimplemented")
25 // The error to return from every stubbed API method.
31 // BaseURL implements federation.backend
32 func (as *APIStub) BaseURL() url.URL {
33 return url.URL{Scheme: "https", Host: "apistub.example.com"}
35 func (as *APIStub) ConfigGet(ctx context.Context) (json.RawMessage, error) {
36 as.appendCall(ctx, as.ConfigGet, nil)
39 func (as *APIStub) VocabularyGet(ctx context.Context) (arvados.Vocabulary, error) {
40 as.appendCall(ctx, as.VocabularyGet, nil)
41 return arvados.Vocabulary{}, as.Error
43 func (as *APIStub) DiscoveryDocument(ctx context.Context) (arvados.DiscoveryDocument, error) {
44 as.appendCall(ctx, as.DiscoveryDocument, nil)
45 return arvados.DiscoveryDocument{}, as.Error
47 func (as *APIStub) Login(ctx context.Context, options arvados.LoginOptions) (arvados.LoginResponse, error) {
48 as.appendCall(ctx, as.Login, options)
49 return arvados.LoginResponse{}, as.Error
51 func (as *APIStub) Logout(ctx context.Context, options arvados.LogoutOptions) (arvados.LogoutResponse, error) {
52 as.appendCall(ctx, as.Logout, options)
53 return arvados.LogoutResponse{}, as.Error
55 func (as *APIStub) AuthorizedKeyCreate(ctx context.Context, options arvados.CreateOptions) (arvados.AuthorizedKey, error) {
56 as.appendCall(ctx, as.AuthorizedKeyCreate, options)
57 return arvados.AuthorizedKey{}, as.Error
59 func (as *APIStub) AuthorizedKeyUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.AuthorizedKey, error) {
60 as.appendCall(ctx, as.AuthorizedKeyUpdate, options)
61 return arvados.AuthorizedKey{}, as.Error
63 func (as *APIStub) AuthorizedKeyGet(ctx context.Context, options arvados.GetOptions) (arvados.AuthorizedKey, error) {
64 as.appendCall(ctx, as.AuthorizedKeyGet, options)
65 return arvados.AuthorizedKey{}, as.Error
67 func (as *APIStub) AuthorizedKeyList(ctx context.Context, options arvados.ListOptions) (arvados.AuthorizedKeyList, error) {
68 as.appendCall(ctx, as.AuthorizedKeyList, options)
69 return arvados.AuthorizedKeyList{}, as.Error
71 func (as *APIStub) AuthorizedKeyDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.AuthorizedKey, error) {
72 as.appendCall(ctx, as.AuthorizedKeyDelete, options)
73 return arvados.AuthorizedKey{}, as.Error
75 func (as *APIStub) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
76 as.appendCall(ctx, as.CollectionCreate, options)
77 return arvados.Collection{}, as.Error
79 func (as *APIStub) CollectionUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Collection, error) {
80 as.appendCall(ctx, as.CollectionUpdate, options)
81 return arvados.Collection{}, as.Error
83 func (as *APIStub) CollectionGet(ctx context.Context, options arvados.GetOptions) (arvados.Collection, error) {
84 as.appendCall(ctx, as.CollectionGet, options)
85 return arvados.Collection{}, as.Error
87 func (as *APIStub) CollectionList(ctx context.Context, options arvados.ListOptions) (arvados.CollectionList, error) {
88 as.appendCall(ctx, as.CollectionList, options)
89 return arvados.CollectionList{}, as.Error
91 func (as *APIStub) CollectionProvenance(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
92 as.appendCall(ctx, as.CollectionProvenance, options)
95 func (as *APIStub) CollectionUsedBy(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
96 as.appendCall(ctx, as.CollectionUsedBy, options)
99 func (as *APIStub) CollectionDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
100 as.appendCall(ctx, as.CollectionDelete, options)
101 return arvados.Collection{}, as.Error
103 func (as *APIStub) CollectionTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
104 as.appendCall(ctx, as.CollectionTrash, options)
105 return arvados.Collection{}, as.Error
107 func (as *APIStub) CollectionUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Collection, error) {
108 as.appendCall(ctx, as.CollectionUntrash, options)
109 return arvados.Collection{}, as.Error
111 func (as *APIStub) ComputedPermissionList(ctx context.Context, options arvados.ListOptions) (arvados.ComputedPermissionList, error) {
112 as.appendCall(ctx, as.ComputedPermissionList, options)
113 return arvados.ComputedPermissionList{}, as.Error
115 func (as *APIStub) ContainerCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Container, error) {
116 as.appendCall(ctx, as.ContainerCreate, options)
117 return arvados.Container{}, as.Error
119 func (as *APIStub) ContainerUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
120 as.appendCall(ctx, as.ContainerUpdate, options)
121 return arvados.Container{}, as.Error
123 func (as *APIStub) ContainerPriorityUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
124 as.appendCall(ctx, as.ContainerPriorityUpdate, options)
125 return arvados.Container{}, as.Error
127 func (as *APIStub) ContainerGet(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
128 as.appendCall(ctx, as.ContainerGet, options)
129 return arvados.Container{}, as.Error
131 func (as *APIStub) ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
132 as.appendCall(ctx, as.ContainerList, options)
133 return arvados.ContainerList{}, as.Error
135 func (as *APIStub) ContainerDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Container, error) {
136 as.appendCall(ctx, as.ContainerDelete, options)
137 return arvados.Container{}, as.Error
139 func (as *APIStub) ContainerLock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
140 as.appendCall(ctx, as.ContainerLock, options)
141 return arvados.Container{}, as.Error
143 func (as *APIStub) ContainerUnlock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
144 as.appendCall(ctx, as.ContainerUnlock, options)
145 return arvados.Container{}, as.Error
147 func (as *APIStub) ContainerSSH(ctx context.Context, options arvados.ContainerSSHOptions) (arvados.ConnectionResponse, error) {
148 as.appendCall(ctx, as.ContainerSSH, options)
149 return arvados.ConnectionResponse{}, as.Error
151 func (as *APIStub) ContainerGatewayTunnel(ctx context.Context, options arvados.ContainerGatewayTunnelOptions) (arvados.ConnectionResponse, error) {
152 as.appendCall(ctx, as.ContainerGatewayTunnel, options)
153 return arvados.ConnectionResponse{}, as.Error
155 func (as *APIStub) ContainerRequestCreate(ctx context.Context, options arvados.CreateOptions) (arvados.ContainerRequest, error) {
156 as.appendCall(ctx, as.ContainerRequestCreate, options)
157 return arvados.ContainerRequest{}, as.Error
159 func (as *APIStub) ContainerRequestUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.ContainerRequest, error) {
160 as.appendCall(ctx, as.ContainerRequestUpdate, options)
161 return arvados.ContainerRequest{}, as.Error
163 func (as *APIStub) ContainerRequestGet(ctx context.Context, options arvados.GetOptions) (arvados.ContainerRequest, error) {
164 as.appendCall(ctx, as.ContainerRequestGet, options)
165 return arvados.ContainerRequest{}, as.Error
167 func (as *APIStub) ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
168 as.appendCall(ctx, as.ContainerRequestList, options)
169 return arvados.ContainerRequestList{}, as.Error
171 func (as *APIStub) ContainerRequestDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.ContainerRequest, error) {
172 as.appendCall(ctx, as.ContainerRequestDelete, options)
173 return arvados.ContainerRequest{}, as.Error
175 func (as *APIStub) ContainerRequestContainerStatus(ctx context.Context, options arvados.GetOptions) (arvados.ContainerStatus, error) {
176 as.appendCall(ctx, as.ContainerRequestContainerStatus, options)
177 return arvados.ContainerStatus{}, as.Error
179 func (as *APIStub) ContainerRequestLog(ctx context.Context, options arvados.ContainerLogOptions) (http.Handler, error) {
180 as.appendCall(ctx, as.ContainerRequestLog, options)
181 // Return a handler that responds with the configured
182 // error/success status.
183 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
185 w.WriteHeader(http.StatusOK)
186 } else if err := httpserver.HTTPStatusError(nil); errors.As(as.Error, &err) {
187 w.WriteHeader(err.HTTPStatus())
188 io.WriteString(w, err.Error())
190 w.WriteHeader(http.StatusInternalServerError)
191 io.WriteString(w, err.Error())
195 func (as *APIStub) GroupCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Group, error) {
196 as.appendCall(ctx, as.GroupCreate, options)
197 return arvados.Group{}, as.Error
199 func (as *APIStub) GroupUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Group, error) {
200 as.appendCall(ctx, as.GroupUpdate, options)
201 return arvados.Group{}, as.Error
203 func (as *APIStub) GroupGet(ctx context.Context, options arvados.GetOptions) (arvados.Group, error) {
204 as.appendCall(ctx, as.GroupGet, options)
205 return arvados.Group{}, as.Error
207 func (as *APIStub) GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
208 as.appendCall(ctx, as.GroupList, options)
209 return arvados.GroupList{}, as.Error
211 func (as *APIStub) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
212 as.appendCall(ctx, as.GroupContents, options)
213 return arvados.ObjectList{}, as.Error
215 func (as *APIStub) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
216 as.appendCall(ctx, as.GroupShared, options)
217 return arvados.GroupList{}, as.Error
219 func (as *APIStub) GroupDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
220 as.appendCall(ctx, as.GroupDelete, options)
221 return arvados.Group{}, as.Error
223 func (as *APIStub) GroupTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
224 as.appendCall(ctx, as.GroupTrash, options)
225 return arvados.Group{}, as.Error
227 func (as *APIStub) GroupUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Group, error) {
228 as.appendCall(ctx, as.GroupUntrash, options)
229 return arvados.Group{}, as.Error
231 func (as *APIStub) LinkCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Link, error) {
232 as.appendCall(ctx, as.LinkCreate, options)
233 return arvados.Link{}, as.Error
235 func (as *APIStub) LinkUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Link, error) {
236 as.appendCall(ctx, as.LinkUpdate, options)
237 return arvados.Link{}, as.Error
239 func (as *APIStub) LinkGet(ctx context.Context, options arvados.GetOptions) (arvados.Link, error) {
240 as.appendCall(ctx, as.LinkGet, options)
241 return arvados.Link{}, as.Error
243 func (as *APIStub) LinkList(ctx context.Context, options arvados.ListOptions) (arvados.LinkList, error) {
244 as.appendCall(ctx, as.LinkList, options)
245 return arvados.LinkList{}, as.Error
247 func (as *APIStub) LinkDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Link, error) {
248 as.appendCall(ctx, as.LinkDelete, options)
249 return arvados.Link{}, as.Error
251 func (as *APIStub) LogCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Log, error) {
252 as.appendCall(ctx, as.LogCreate, options)
253 return arvados.Log{}, as.Error
255 func (as *APIStub) LogUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Log, error) {
256 as.appendCall(ctx, as.LogUpdate, options)
257 return arvados.Log{}, as.Error
259 func (as *APIStub) LogGet(ctx context.Context, options arvados.GetOptions) (arvados.Log, error) {
260 as.appendCall(ctx, as.LogGet, options)
261 return arvados.Log{}, as.Error
263 func (as *APIStub) LogList(ctx context.Context, options arvados.ListOptions) (arvados.LogList, error) {
264 as.appendCall(ctx, as.LogList, options)
265 return arvados.LogList{}, as.Error
267 func (as *APIStub) LogDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Log, error) {
268 as.appendCall(ctx, as.LogDelete, options)
269 return arvados.Log{}, as.Error
271 func (as *APIStub) SysTrashSweep(ctx context.Context, options struct{}) (struct{}, error) {
272 as.appendCall(ctx, as.SysTrashSweep, options)
273 return struct{}{}, as.Error
275 func (as *APIStub) UserCreate(ctx context.Context, options arvados.CreateOptions) (arvados.User, error) {
276 as.appendCall(ctx, as.UserCreate, options)
277 return arvados.User{}, as.Error
279 func (as *APIStub) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
280 as.appendCall(ctx, as.UserUpdate, options)
281 return arvados.User{}, as.Error
283 func (as *APIStub) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) {
284 as.appendCall(ctx, as.UserActivate, options)
285 return arvados.User{}, as.Error
287 func (as *APIStub) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
288 as.appendCall(ctx, as.UserSetup, options)
291 func (as *APIStub) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
292 as.appendCall(ctx, as.UserUnsetup, options)
293 return arvados.User{}, as.Error
295 func (as *APIStub) UserGet(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
296 as.appendCall(ctx, as.UserGet, options)
297 return arvados.User{}, as.Error
299 func (as *APIStub) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
300 as.appendCall(ctx, as.UserGetCurrent, options)
301 return arvados.User{}, as.Error
303 func (as *APIStub) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
304 as.appendCall(ctx, as.UserGetSystem, options)
305 return arvados.User{}, as.Error
307 func (as *APIStub) UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
308 as.appendCall(ctx, as.UserList, options)
309 return arvados.UserList{}, as.Error
311 func (as *APIStub) UserDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.User, error) {
312 as.appendCall(ctx, as.UserDelete, options)
313 return arvados.User{}, as.Error
315 func (as *APIStub) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) {
316 as.appendCall(ctx, as.UserMerge, options)
317 return arvados.User{}, as.Error
319 func (as *APIStub) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) {
320 as.appendCall(ctx, as.UserBatchUpdate, options)
321 return arvados.UserList{}, as.Error
323 func (as *APIStub) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
324 as.appendCall(ctx, as.UserAuthenticate, options)
325 return arvados.APIClientAuthorization{}, as.Error
327 func (as *APIStub) APIClientAuthorizationCurrent(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
328 as.appendCall(ctx, as.APIClientAuthorizationCurrent, options)
329 return arvados.APIClientAuthorization{}, as.Error
331 func (as *APIStub) APIClientAuthorizationCreate(ctx context.Context, options arvados.CreateOptions) (arvados.APIClientAuthorization, error) {
332 as.appendCall(ctx, as.APIClientAuthorizationCreate, options)
333 return arvados.APIClientAuthorization{}, as.Error
335 func (as *APIStub) APIClientAuthorizationUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.APIClientAuthorization, error) {
336 as.appendCall(ctx, as.APIClientAuthorizationUpdate, options)
337 return arvados.APIClientAuthorization{}, as.Error
339 func (as *APIStub) APIClientAuthorizationDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.APIClientAuthorization, error) {
340 as.appendCall(ctx, as.APIClientAuthorizationDelete, options)
341 return arvados.APIClientAuthorization{}, as.Error
343 func (as *APIStub) APIClientAuthorizationList(ctx context.Context, options arvados.ListOptions) (arvados.APIClientAuthorizationList, error) {
344 as.appendCall(ctx, as.APIClientAuthorizationList, options)
345 return arvados.APIClientAuthorizationList{}, as.Error
347 func (as *APIStub) APIClientAuthorizationGet(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
348 as.appendCall(ctx, as.APIClientAuthorizationGet, options)
349 return arvados.APIClientAuthorization{}, as.Error
351 func (as *APIStub) ReadAt(locator string, dst []byte, offset int) (int, error) {
352 as.appendCall(context.TODO(), as.ReadAt, struct {
356 }{locator, dst, offset})
359 func (as *APIStub) BlockRead(ctx context.Context, options arvados.BlockReadOptions) (int, error) {
360 as.appendCall(ctx, as.BlockRead, options)
363 func (as *APIStub) BlockWrite(ctx context.Context, options arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
364 as.appendCall(ctx, as.BlockWrite, options)
365 return arvados.BlockWriteResponse{}, as.Error
367 func (as *APIStub) LocalLocator(locator string) (int, error) {
368 as.appendCall(context.TODO(), as.LocalLocator, locator)
372 func (as *APIStub) appendCall(ctx context.Context, method interface{}, options interface{}) {
374 defer as.mtx.Unlock()
375 as.calls = append(as.calls, APIStubCall{method, ctx, options})
378 func (as *APIStub) Calls(method interface{}) []APIStubCall {
380 defer as.mtx.Unlock()
381 var calls []APIStubCall
382 for _, call := range as.calls {
383 if method == nil || (runtime.FuncForPC(reflect.ValueOf(call.Method).Pointer()).Name() ==
384 runtime.FuncForPC(reflect.ValueOf(method).Pointer()).Name()) {
385 calls = append(calls, call)
391 type APIStubCall struct {
393 Context context.Context