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) ContainerCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Container, error) {
112 as.appendCall(ctx, as.ContainerCreate, options)
113 return arvados.Container{}, as.Error
115 func (as *APIStub) ContainerUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
116 as.appendCall(ctx, as.ContainerUpdate, options)
117 return arvados.Container{}, as.Error
119 func (as *APIStub) ContainerPriorityUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
120 as.appendCall(ctx, as.ContainerPriorityUpdate, options)
121 return arvados.Container{}, as.Error
123 func (as *APIStub) ContainerGet(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
124 as.appendCall(ctx, as.ContainerGet, options)
125 return arvados.Container{}, as.Error
127 func (as *APIStub) ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
128 as.appendCall(ctx, as.ContainerList, options)
129 return arvados.ContainerList{}, as.Error
131 func (as *APIStub) ContainerDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Container, error) {
132 as.appendCall(ctx, as.ContainerDelete, options)
133 return arvados.Container{}, as.Error
135 func (as *APIStub) ContainerLock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
136 as.appendCall(ctx, as.ContainerLock, options)
137 return arvados.Container{}, as.Error
139 func (as *APIStub) ContainerUnlock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
140 as.appendCall(ctx, as.ContainerUnlock, options)
141 return arvados.Container{}, as.Error
143 func (as *APIStub) ContainerSSH(ctx context.Context, options arvados.ContainerSSHOptions) (arvados.ConnectionResponse, error) {
144 as.appendCall(ctx, as.ContainerSSH, options)
145 return arvados.ConnectionResponse{}, as.Error
147 func (as *APIStub) ContainerGatewayTunnel(ctx context.Context, options arvados.ContainerGatewayTunnelOptions) (arvados.ConnectionResponse, error) {
148 as.appendCall(ctx, as.ContainerGatewayTunnel, options)
149 return arvados.ConnectionResponse{}, as.Error
151 func (as *APIStub) ContainerRequestCreate(ctx context.Context, options arvados.CreateOptions) (arvados.ContainerRequest, error) {
152 as.appendCall(ctx, as.ContainerRequestCreate, options)
153 return arvados.ContainerRequest{}, as.Error
155 func (as *APIStub) ContainerRequestUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.ContainerRequest, error) {
156 as.appendCall(ctx, as.ContainerRequestUpdate, options)
157 return arvados.ContainerRequest{}, as.Error
159 func (as *APIStub) ContainerRequestGet(ctx context.Context, options arvados.GetOptions) (arvados.ContainerRequest, error) {
160 as.appendCall(ctx, as.ContainerRequestGet, options)
161 return arvados.ContainerRequest{}, as.Error
163 func (as *APIStub) ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
164 as.appendCall(ctx, as.ContainerRequestList, options)
165 return arvados.ContainerRequestList{}, as.Error
167 func (as *APIStub) ContainerRequestDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.ContainerRequest, error) {
168 as.appendCall(ctx, as.ContainerRequestDelete, options)
169 return arvados.ContainerRequest{}, as.Error
171 func (as *APIStub) ContainerRequestContainerStatus(ctx context.Context, options arvados.GetOptions) (arvados.ContainerStatus, error) {
172 as.appendCall(ctx, as.ContainerRequestContainerStatus, options)
173 return arvados.ContainerStatus{}, as.Error
175 func (as *APIStub) ContainerRequestLog(ctx context.Context, options arvados.ContainerLogOptions) (http.Handler, error) {
176 as.appendCall(ctx, as.ContainerRequestLog, options)
177 // Return a handler that responds with the configured
178 // error/success status.
179 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
181 w.WriteHeader(http.StatusOK)
182 } else if err := httpserver.HTTPStatusError(nil); errors.As(as.Error, &err) {
183 w.WriteHeader(err.HTTPStatus())
184 io.WriteString(w, err.Error())
186 w.WriteHeader(http.StatusInternalServerError)
187 io.WriteString(w, err.Error())
191 func (as *APIStub) GroupCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Group, error) {
192 as.appendCall(ctx, as.GroupCreate, options)
193 return arvados.Group{}, as.Error
195 func (as *APIStub) GroupUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Group, error) {
196 as.appendCall(ctx, as.GroupUpdate, options)
197 return arvados.Group{}, as.Error
199 func (as *APIStub) GroupGet(ctx context.Context, options arvados.GetOptions) (arvados.Group, error) {
200 as.appendCall(ctx, as.GroupGet, options)
201 return arvados.Group{}, as.Error
203 func (as *APIStub) GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
204 as.appendCall(ctx, as.GroupList, options)
205 return arvados.GroupList{}, as.Error
207 func (as *APIStub) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
208 as.appendCall(ctx, as.GroupContents, options)
209 return arvados.ObjectList{}, as.Error
211 func (as *APIStub) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
212 as.appendCall(ctx, as.GroupShared, options)
213 return arvados.GroupList{}, as.Error
215 func (as *APIStub) GroupDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
216 as.appendCall(ctx, as.GroupDelete, options)
217 return arvados.Group{}, as.Error
219 func (as *APIStub) GroupTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
220 as.appendCall(ctx, as.GroupTrash, options)
221 return arvados.Group{}, as.Error
223 func (as *APIStub) GroupUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Group, error) {
224 as.appendCall(ctx, as.GroupUntrash, options)
225 return arvados.Group{}, as.Error
227 func (as *APIStub) LinkCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Link, error) {
228 as.appendCall(ctx, as.LinkCreate, options)
229 return arvados.Link{}, as.Error
231 func (as *APIStub) LinkUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Link, error) {
232 as.appendCall(ctx, as.LinkUpdate, options)
233 return arvados.Link{}, as.Error
235 func (as *APIStub) LinkGet(ctx context.Context, options arvados.GetOptions) (arvados.Link, error) {
236 as.appendCall(ctx, as.LinkGet, options)
237 return arvados.Link{}, as.Error
239 func (as *APIStub) LinkList(ctx context.Context, options arvados.ListOptions) (arvados.LinkList, error) {
240 as.appendCall(ctx, as.LinkList, options)
241 return arvados.LinkList{}, as.Error
243 func (as *APIStub) LinkDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Link, error) {
244 as.appendCall(ctx, as.LinkDelete, options)
245 return arvados.Link{}, as.Error
247 func (as *APIStub) LogCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Log, error) {
248 as.appendCall(ctx, as.LogCreate, options)
249 return arvados.Log{}, as.Error
251 func (as *APIStub) LogUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Log, error) {
252 as.appendCall(ctx, as.LogUpdate, options)
253 return arvados.Log{}, as.Error
255 func (as *APIStub) LogGet(ctx context.Context, options arvados.GetOptions) (arvados.Log, error) {
256 as.appendCall(ctx, as.LogGet, options)
257 return arvados.Log{}, as.Error
259 func (as *APIStub) LogList(ctx context.Context, options arvados.ListOptions) (arvados.LogList, error) {
260 as.appendCall(ctx, as.LogList, options)
261 return arvados.LogList{}, as.Error
263 func (as *APIStub) LogDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Log, error) {
264 as.appendCall(ctx, as.LogDelete, options)
265 return arvados.Log{}, as.Error
267 func (as *APIStub) SysTrashSweep(ctx context.Context, options struct{}) (struct{}, error) {
268 as.appendCall(ctx, as.SysTrashSweep, options)
269 return struct{}{}, as.Error
271 func (as *APIStub) UserCreate(ctx context.Context, options arvados.CreateOptions) (arvados.User, error) {
272 as.appendCall(ctx, as.UserCreate, options)
273 return arvados.User{}, as.Error
275 func (as *APIStub) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
276 as.appendCall(ctx, as.UserUpdate, options)
277 return arvados.User{}, as.Error
279 func (as *APIStub) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) {
280 as.appendCall(ctx, as.UserActivate, options)
281 return arvados.User{}, as.Error
283 func (as *APIStub) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
284 as.appendCall(ctx, as.UserSetup, options)
287 func (as *APIStub) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
288 as.appendCall(ctx, as.UserUnsetup, options)
289 return arvados.User{}, as.Error
291 func (as *APIStub) UserGet(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
292 as.appendCall(ctx, as.UserGet, options)
293 return arvados.User{}, as.Error
295 func (as *APIStub) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
296 as.appendCall(ctx, as.UserGetCurrent, options)
297 return arvados.User{}, as.Error
299 func (as *APIStub) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
300 as.appendCall(ctx, as.UserGetSystem, options)
301 return arvados.User{}, as.Error
303 func (as *APIStub) UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
304 as.appendCall(ctx, as.UserList, options)
305 return arvados.UserList{}, as.Error
307 func (as *APIStub) UserDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.User, error) {
308 as.appendCall(ctx, as.UserDelete, options)
309 return arvados.User{}, as.Error
311 func (as *APIStub) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) {
312 as.appendCall(ctx, as.UserMerge, options)
313 return arvados.User{}, as.Error
315 func (as *APIStub) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) {
316 as.appendCall(ctx, as.UserBatchUpdate, options)
317 return arvados.UserList{}, as.Error
319 func (as *APIStub) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
320 as.appendCall(ctx, as.UserAuthenticate, options)
321 return arvados.APIClientAuthorization{}, as.Error
323 func (as *APIStub) APIClientAuthorizationCurrent(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
324 as.appendCall(ctx, as.APIClientAuthorizationCurrent, options)
325 return arvados.APIClientAuthorization{}, as.Error
327 func (as *APIStub) APIClientAuthorizationCreate(ctx context.Context, options arvados.CreateOptions) (arvados.APIClientAuthorization, error) {
328 as.appendCall(ctx, as.APIClientAuthorizationCreate, options)
329 return arvados.APIClientAuthorization{}, as.Error
331 func (as *APIStub) APIClientAuthorizationUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.APIClientAuthorization, error) {
332 as.appendCall(ctx, as.APIClientAuthorizationUpdate, options)
333 return arvados.APIClientAuthorization{}, as.Error
335 func (as *APIStub) APIClientAuthorizationDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.APIClientAuthorization, error) {
336 as.appendCall(ctx, as.APIClientAuthorizationDelete, options)
337 return arvados.APIClientAuthorization{}, as.Error
339 func (as *APIStub) APIClientAuthorizationList(ctx context.Context, options arvados.ListOptions) (arvados.APIClientAuthorizationList, error) {
340 as.appendCall(ctx, as.APIClientAuthorizationList, options)
341 return arvados.APIClientAuthorizationList{}, as.Error
343 func (as *APIStub) APIClientAuthorizationGet(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
344 as.appendCall(ctx, as.APIClientAuthorizationGet, options)
345 return arvados.APIClientAuthorization{}, as.Error
347 func (as *APIStub) ReadAt(locator string, dst []byte, offset int) (int, error) {
348 as.appendCall(context.TODO(), as.ReadAt, struct {
352 }{locator, dst, offset})
355 func (as *APIStub) BlockRead(ctx context.Context, options arvados.BlockReadOptions) (int, error) {
356 as.appendCall(ctx, as.BlockRead, options)
359 func (as *APIStub) BlockWrite(ctx context.Context, options arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
360 as.appendCall(ctx, as.BlockWrite, options)
361 return arvados.BlockWriteResponse{}, as.Error
363 func (as *APIStub) LocalLocator(locator string) (int, error) {
364 as.appendCall(context.TODO(), as.LocalLocator, locator)
368 func (as *APIStub) appendCall(ctx context.Context, method interface{}, options interface{}) {
370 defer as.mtx.Unlock()
371 as.calls = append(as.calls, APIStubCall{method, ctx, options})
374 func (as *APIStub) Calls(method interface{}) []APIStubCall {
376 defer as.mtx.Unlock()
377 var calls []APIStubCall
378 for _, call := range as.calls {
379 if method == nil || (runtime.FuncForPC(reflect.ValueOf(call.Method).Pointer()).Name() ==
380 runtime.FuncForPC(reflect.ValueOf(method).Pointer()).Name()) {
381 calls = append(calls, call)
387 type APIStubCall struct {
389 Context context.Context