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) Login(ctx context.Context, options arvados.LoginOptions) (arvados.LoginResponse, error) {
44 as.appendCall(ctx, as.Login, options)
45 return arvados.LoginResponse{}, as.Error
47 func (as *APIStub) Logout(ctx context.Context, options arvados.LogoutOptions) (arvados.LogoutResponse, error) {
48 as.appendCall(ctx, as.Logout, options)
49 return arvados.LogoutResponse{}, as.Error
51 func (as *APIStub) AuthorizedKeyCreate(ctx context.Context, options arvados.CreateOptions) (arvados.AuthorizedKey, error) {
52 as.appendCall(ctx, as.AuthorizedKeyCreate, options)
53 return arvados.AuthorizedKey{}, as.Error
55 func (as *APIStub) AuthorizedKeyUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.AuthorizedKey, error) {
56 as.appendCall(ctx, as.AuthorizedKeyUpdate, options)
57 return arvados.AuthorizedKey{}, as.Error
59 func (as *APIStub) AuthorizedKeyGet(ctx context.Context, options arvados.GetOptions) (arvados.AuthorizedKey, error) {
60 as.appendCall(ctx, as.AuthorizedKeyGet, options)
61 return arvados.AuthorizedKey{}, as.Error
63 func (as *APIStub) AuthorizedKeyList(ctx context.Context, options arvados.ListOptions) (arvados.AuthorizedKeyList, error) {
64 as.appendCall(ctx, as.AuthorizedKeyList, options)
65 return arvados.AuthorizedKeyList{}, as.Error
67 func (as *APIStub) AuthorizedKeyDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.AuthorizedKey, error) {
68 as.appendCall(ctx, as.AuthorizedKeyDelete, options)
69 return arvados.AuthorizedKey{}, as.Error
71 func (as *APIStub) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {
72 as.appendCall(ctx, as.CollectionCreate, options)
73 return arvados.Collection{}, as.Error
75 func (as *APIStub) CollectionUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Collection, error) {
76 as.appendCall(ctx, as.CollectionUpdate, options)
77 return arvados.Collection{}, as.Error
79 func (as *APIStub) CollectionGet(ctx context.Context, options arvados.GetOptions) (arvados.Collection, error) {
80 as.appendCall(ctx, as.CollectionGet, options)
81 return arvados.Collection{}, as.Error
83 func (as *APIStub) CollectionList(ctx context.Context, options arvados.ListOptions) (arvados.CollectionList, error) {
84 as.appendCall(ctx, as.CollectionList, options)
85 return arvados.CollectionList{}, as.Error
87 func (as *APIStub) CollectionProvenance(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
88 as.appendCall(ctx, as.CollectionProvenance, options)
91 func (as *APIStub) CollectionUsedBy(ctx context.Context, options arvados.GetOptions) (map[string]interface{}, error) {
92 as.appendCall(ctx, as.CollectionUsedBy, options)
95 func (as *APIStub) CollectionDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
96 as.appendCall(ctx, as.CollectionDelete, options)
97 return arvados.Collection{}, as.Error
99 func (as *APIStub) CollectionTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Collection, error) {
100 as.appendCall(ctx, as.CollectionTrash, options)
101 return arvados.Collection{}, as.Error
103 func (as *APIStub) CollectionUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Collection, error) {
104 as.appendCall(ctx, as.CollectionUntrash, options)
105 return arvados.Collection{}, as.Error
107 func (as *APIStub) ContainerCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Container, error) {
108 as.appendCall(ctx, as.ContainerCreate, options)
109 return arvados.Container{}, as.Error
111 func (as *APIStub) ContainerUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
112 as.appendCall(ctx, as.ContainerUpdate, options)
113 return arvados.Container{}, as.Error
115 func (as *APIStub) ContainerPriorityUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Container, error) {
116 as.appendCall(ctx, as.ContainerPriorityUpdate, options)
117 return arvados.Container{}, as.Error
119 func (as *APIStub) ContainerGet(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
120 as.appendCall(ctx, as.ContainerGet, options)
121 return arvados.Container{}, as.Error
123 func (as *APIStub) ContainerList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerList, error) {
124 as.appendCall(ctx, as.ContainerList, options)
125 return arvados.ContainerList{}, as.Error
127 func (as *APIStub) ContainerDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Container, error) {
128 as.appendCall(ctx, as.ContainerDelete, options)
129 return arvados.Container{}, as.Error
131 func (as *APIStub) ContainerLock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
132 as.appendCall(ctx, as.ContainerLock, options)
133 return arvados.Container{}, as.Error
135 func (as *APIStub) ContainerUnlock(ctx context.Context, options arvados.GetOptions) (arvados.Container, error) {
136 as.appendCall(ctx, as.ContainerUnlock, options)
137 return arvados.Container{}, as.Error
139 func (as *APIStub) ContainerSSH(ctx context.Context, options arvados.ContainerSSHOptions) (arvados.ConnectionResponse, error) {
140 as.appendCall(ctx, as.ContainerSSH, options)
141 return arvados.ConnectionResponse{}, as.Error
143 func (as *APIStub) ContainerGatewayTunnel(ctx context.Context, options arvados.ContainerGatewayTunnelOptions) (arvados.ConnectionResponse, error) {
144 as.appendCall(ctx, as.ContainerGatewayTunnel, options)
145 return arvados.ConnectionResponse{}, as.Error
147 func (as *APIStub) ContainerRequestCreate(ctx context.Context, options arvados.CreateOptions) (arvados.ContainerRequest, error) {
148 as.appendCall(ctx, as.ContainerRequestCreate, options)
149 return arvados.ContainerRequest{}, as.Error
151 func (as *APIStub) ContainerRequestUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.ContainerRequest, error) {
152 as.appendCall(ctx, as.ContainerRequestUpdate, options)
153 return arvados.ContainerRequest{}, as.Error
155 func (as *APIStub) ContainerRequestGet(ctx context.Context, options arvados.GetOptions) (arvados.ContainerRequest, error) {
156 as.appendCall(ctx, as.ContainerRequestGet, options)
157 return arvados.ContainerRequest{}, as.Error
159 func (as *APIStub) ContainerRequestList(ctx context.Context, options arvados.ListOptions) (arvados.ContainerRequestList, error) {
160 as.appendCall(ctx, as.ContainerRequestList, options)
161 return arvados.ContainerRequestList{}, as.Error
163 func (as *APIStub) ContainerRequestDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.ContainerRequest, error) {
164 as.appendCall(ctx, as.ContainerRequestDelete, options)
165 return arvados.ContainerRequest{}, as.Error
167 func (as *APIStub) ContainerRequestLog(ctx context.Context, options arvados.ContainerLogOptions) (http.Handler, error) {
168 as.appendCall(ctx, as.ContainerRequestLog, options)
169 // Return a handler that responds with the configured
170 // error/success status.
171 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
173 w.WriteHeader(http.StatusOK)
174 } else if err := httpserver.HTTPStatusError(nil); errors.As(as.Error, &err) {
175 w.WriteHeader(err.HTTPStatus())
176 io.WriteString(w, err.Error())
178 w.WriteHeader(http.StatusInternalServerError)
179 io.WriteString(w, err.Error())
183 func (as *APIStub) GroupCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Group, error) {
184 as.appendCall(ctx, as.GroupCreate, options)
185 return arvados.Group{}, as.Error
187 func (as *APIStub) GroupUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Group, error) {
188 as.appendCall(ctx, as.GroupUpdate, options)
189 return arvados.Group{}, as.Error
191 func (as *APIStub) GroupGet(ctx context.Context, options arvados.GetOptions) (arvados.Group, error) {
192 as.appendCall(ctx, as.GroupGet, options)
193 return arvados.Group{}, as.Error
195 func (as *APIStub) GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
196 as.appendCall(ctx, as.GroupList, options)
197 return arvados.GroupList{}, as.Error
199 func (as *APIStub) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
200 as.appendCall(ctx, as.GroupContents, options)
201 return arvados.ObjectList{}, as.Error
203 func (as *APIStub) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
204 as.appendCall(ctx, as.GroupShared, options)
205 return arvados.GroupList{}, as.Error
207 func (as *APIStub) GroupDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
208 as.appendCall(ctx, as.GroupDelete, options)
209 return arvados.Group{}, as.Error
211 func (as *APIStub) GroupTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
212 as.appendCall(ctx, as.GroupTrash, options)
213 return arvados.Group{}, as.Error
215 func (as *APIStub) GroupUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Group, error) {
216 as.appendCall(ctx, as.GroupUntrash, options)
217 return arvados.Group{}, as.Error
219 func (as *APIStub) LinkCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Link, error) {
220 as.appendCall(ctx, as.LinkCreate, options)
221 return arvados.Link{}, as.Error
223 func (as *APIStub) LinkUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Link, error) {
224 as.appendCall(ctx, as.LinkUpdate, options)
225 return arvados.Link{}, as.Error
227 func (as *APIStub) LinkGet(ctx context.Context, options arvados.GetOptions) (arvados.Link, error) {
228 as.appendCall(ctx, as.LinkGet, options)
229 return arvados.Link{}, as.Error
231 func (as *APIStub) LinkList(ctx context.Context, options arvados.ListOptions) (arvados.LinkList, error) {
232 as.appendCall(ctx, as.LinkList, options)
233 return arvados.LinkList{}, as.Error
235 func (as *APIStub) LinkDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Link, error) {
236 as.appendCall(ctx, as.LinkDelete, options)
237 return arvados.Link{}, as.Error
239 func (as *APIStub) LogCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Log, error) {
240 as.appendCall(ctx, as.LogCreate, options)
241 return arvados.Log{}, as.Error
243 func (as *APIStub) LogUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Log, error) {
244 as.appendCall(ctx, as.LogUpdate, options)
245 return arvados.Log{}, as.Error
247 func (as *APIStub) LogGet(ctx context.Context, options arvados.GetOptions) (arvados.Log, error) {
248 as.appendCall(ctx, as.LogGet, options)
249 return arvados.Log{}, as.Error
251 func (as *APIStub) LogList(ctx context.Context, options arvados.ListOptions) (arvados.LogList, error) {
252 as.appendCall(ctx, as.LogList, options)
253 return arvados.LogList{}, as.Error
255 func (as *APIStub) LogDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Log, error) {
256 as.appendCall(ctx, as.LogDelete, options)
257 return arvados.Log{}, as.Error
259 func (as *APIStub) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
260 as.appendCall(ctx, as.SpecimenCreate, options)
261 return arvados.Specimen{}, as.Error
263 func (as *APIStub) SpecimenUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Specimen, error) {
264 as.appendCall(ctx, as.SpecimenUpdate, options)
265 return arvados.Specimen{}, as.Error
267 func (as *APIStub) SpecimenGet(ctx context.Context, options arvados.GetOptions) (arvados.Specimen, error) {
268 as.appendCall(ctx, as.SpecimenGet, options)
269 return arvados.Specimen{}, as.Error
271 func (as *APIStub) SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
272 as.appendCall(ctx, as.SpecimenList, options)
273 return arvados.SpecimenList{}, as.Error
275 func (as *APIStub) SpecimenDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Specimen, error) {
276 as.appendCall(ctx, as.SpecimenDelete, options)
277 return arvados.Specimen{}, as.Error
279 func (as *APIStub) SysTrashSweep(ctx context.Context, options struct{}) (struct{}, error) {
280 as.appendCall(ctx, as.SysTrashSweep, options)
281 return struct{}{}, as.Error
283 func (as *APIStub) UserCreate(ctx context.Context, options arvados.CreateOptions) (arvados.User, error) {
284 as.appendCall(ctx, as.UserCreate, options)
285 return arvados.User{}, as.Error
287 func (as *APIStub) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
288 as.appendCall(ctx, as.UserUpdate, options)
289 return arvados.User{}, as.Error
291 func (as *APIStub) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) {
292 as.appendCall(ctx, as.UserActivate, options)
293 return arvados.User{}, as.Error
295 func (as *APIStub) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
296 as.appendCall(ctx, as.UserSetup, options)
299 func (as *APIStub) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
300 as.appendCall(ctx, as.UserUnsetup, options)
301 return arvados.User{}, as.Error
303 func (as *APIStub) UserGet(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
304 as.appendCall(ctx, as.UserGet, options)
305 return arvados.User{}, as.Error
307 func (as *APIStub) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
308 as.appendCall(ctx, as.UserGetCurrent, options)
309 return arvados.User{}, as.Error
311 func (as *APIStub) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
312 as.appendCall(ctx, as.UserGetSystem, options)
313 return arvados.User{}, as.Error
315 func (as *APIStub) UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
316 as.appendCall(ctx, as.UserList, options)
317 return arvados.UserList{}, as.Error
319 func (as *APIStub) UserDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.User, error) {
320 as.appendCall(ctx, as.UserDelete, options)
321 return arvados.User{}, as.Error
323 func (as *APIStub) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) {
324 as.appendCall(ctx, as.UserMerge, options)
325 return arvados.User{}, as.Error
327 func (as *APIStub) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) {
328 as.appendCall(ctx, as.UserBatchUpdate, options)
329 return arvados.UserList{}, as.Error
331 func (as *APIStub) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
332 as.appendCall(ctx, as.UserAuthenticate, options)
333 return arvados.APIClientAuthorization{}, as.Error
335 func (as *APIStub) APIClientAuthorizationCurrent(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
336 as.appendCall(ctx, as.APIClientAuthorizationCurrent, options)
337 return arvados.APIClientAuthorization{}, as.Error
339 func (as *APIStub) APIClientAuthorizationCreate(ctx context.Context, options arvados.CreateOptions) (arvados.APIClientAuthorization, error) {
340 as.appendCall(ctx, as.APIClientAuthorizationCreate, options)
341 return arvados.APIClientAuthorization{}, as.Error
343 func (as *APIStub) APIClientAuthorizationUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.APIClientAuthorization, error) {
344 as.appendCall(ctx, as.APIClientAuthorizationUpdate, options)
345 return arvados.APIClientAuthorization{}, as.Error
347 func (as *APIStub) APIClientAuthorizationDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.APIClientAuthorization, error) {
348 as.appendCall(ctx, as.APIClientAuthorizationDelete, options)
349 return arvados.APIClientAuthorization{}, as.Error
351 func (as *APIStub) APIClientAuthorizationList(ctx context.Context, options arvados.ListOptions) (arvados.APIClientAuthorizationList, error) {
352 as.appendCall(ctx, as.APIClientAuthorizationList, options)
353 return arvados.APIClientAuthorizationList{}, as.Error
355 func (as *APIStub) APIClientAuthorizationGet(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
356 as.appendCall(ctx, as.APIClientAuthorizationGet, options)
357 return arvados.APIClientAuthorization{}, as.Error
360 func (as *APIStub) appendCall(ctx context.Context, method interface{}, options interface{}) {
362 defer as.mtx.Unlock()
363 as.calls = append(as.calls, APIStubCall{method, ctx, options})
366 func (as *APIStub) Calls(method interface{}) []APIStubCall {
368 defer as.mtx.Unlock()
369 var calls []APIStubCall
370 for _, call := range as.calls {
371 if method == nil || (runtime.FuncForPC(reflect.ValueOf(call.Method).Pointer()).Name() ==
372 runtime.FuncForPC(reflect.ValueOf(method).Pointer()).Name()) {
373 calls = append(calls, call)
379 type APIStubCall struct {
381 Context context.Context