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) ContainerRequestLog(ctx context.Context, options arvados.ContainerLogOptions) (http.Handler, error) {
172 as.appendCall(ctx, as.ContainerRequestLog, options)
173 // Return a handler that responds with the configured
174 // error/success status.
175 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
177 w.WriteHeader(http.StatusOK)
178 } else if err := httpserver.HTTPStatusError(nil); errors.As(as.Error, &err) {
179 w.WriteHeader(err.HTTPStatus())
180 io.WriteString(w, err.Error())
182 w.WriteHeader(http.StatusInternalServerError)
183 io.WriteString(w, err.Error())
187 func (as *APIStub) GroupCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Group, error) {
188 as.appendCall(ctx, as.GroupCreate, options)
189 return arvados.Group{}, as.Error
191 func (as *APIStub) GroupUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Group, error) {
192 as.appendCall(ctx, as.GroupUpdate, options)
193 return arvados.Group{}, as.Error
195 func (as *APIStub) GroupGet(ctx context.Context, options arvados.GetOptions) (arvados.Group, error) {
196 as.appendCall(ctx, as.GroupGet, options)
197 return arvados.Group{}, as.Error
199 func (as *APIStub) GroupList(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
200 as.appendCall(ctx, as.GroupList, options)
201 return arvados.GroupList{}, as.Error
203 func (as *APIStub) GroupContents(ctx context.Context, options arvados.GroupContentsOptions) (arvados.ObjectList, error) {
204 as.appendCall(ctx, as.GroupContents, options)
205 return arvados.ObjectList{}, as.Error
207 func (as *APIStub) GroupShared(ctx context.Context, options arvados.ListOptions) (arvados.GroupList, error) {
208 as.appendCall(ctx, as.GroupShared, options)
209 return arvados.GroupList{}, as.Error
211 func (as *APIStub) GroupDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
212 as.appendCall(ctx, as.GroupDelete, options)
213 return arvados.Group{}, as.Error
215 func (as *APIStub) GroupTrash(ctx context.Context, options arvados.DeleteOptions) (arvados.Group, error) {
216 as.appendCall(ctx, as.GroupTrash, options)
217 return arvados.Group{}, as.Error
219 func (as *APIStub) GroupUntrash(ctx context.Context, options arvados.UntrashOptions) (arvados.Group, error) {
220 as.appendCall(ctx, as.GroupUntrash, options)
221 return arvados.Group{}, as.Error
223 func (as *APIStub) LinkCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Link, error) {
224 as.appendCall(ctx, as.LinkCreate, options)
225 return arvados.Link{}, as.Error
227 func (as *APIStub) LinkUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Link, error) {
228 as.appendCall(ctx, as.LinkUpdate, options)
229 return arvados.Link{}, as.Error
231 func (as *APIStub) LinkGet(ctx context.Context, options arvados.GetOptions) (arvados.Link, error) {
232 as.appendCall(ctx, as.LinkGet, options)
233 return arvados.Link{}, as.Error
235 func (as *APIStub) LinkList(ctx context.Context, options arvados.ListOptions) (arvados.LinkList, error) {
236 as.appendCall(ctx, as.LinkList, options)
237 return arvados.LinkList{}, as.Error
239 func (as *APIStub) LinkDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Link, error) {
240 as.appendCall(ctx, as.LinkDelete, options)
241 return arvados.Link{}, as.Error
243 func (as *APIStub) LogCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Log, error) {
244 as.appendCall(ctx, as.LogCreate, options)
245 return arvados.Log{}, as.Error
247 func (as *APIStub) LogUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Log, error) {
248 as.appendCall(ctx, as.LogUpdate, options)
249 return arvados.Log{}, as.Error
251 func (as *APIStub) LogGet(ctx context.Context, options arvados.GetOptions) (arvados.Log, error) {
252 as.appendCall(ctx, as.LogGet, options)
253 return arvados.Log{}, as.Error
255 func (as *APIStub) LogList(ctx context.Context, options arvados.ListOptions) (arvados.LogList, error) {
256 as.appendCall(ctx, as.LogList, options)
257 return arvados.LogList{}, as.Error
259 func (as *APIStub) LogDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Log, error) {
260 as.appendCall(ctx, as.LogDelete, options)
261 return arvados.Log{}, as.Error
263 func (as *APIStub) SpecimenCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Specimen, error) {
264 as.appendCall(ctx, as.SpecimenCreate, options)
265 return arvados.Specimen{}, as.Error
267 func (as *APIStub) SpecimenUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.Specimen, error) {
268 as.appendCall(ctx, as.SpecimenUpdate, options)
269 return arvados.Specimen{}, as.Error
271 func (as *APIStub) SpecimenGet(ctx context.Context, options arvados.GetOptions) (arvados.Specimen, error) {
272 as.appendCall(ctx, as.SpecimenGet, options)
273 return arvados.Specimen{}, as.Error
275 func (as *APIStub) SpecimenList(ctx context.Context, options arvados.ListOptions) (arvados.SpecimenList, error) {
276 as.appendCall(ctx, as.SpecimenList, options)
277 return arvados.SpecimenList{}, as.Error
279 func (as *APIStub) SpecimenDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.Specimen, error) {
280 as.appendCall(ctx, as.SpecimenDelete, options)
281 return arvados.Specimen{}, as.Error
283 func (as *APIStub) SysTrashSweep(ctx context.Context, options struct{}) (struct{}, error) {
284 as.appendCall(ctx, as.SysTrashSweep, options)
285 return struct{}{}, as.Error
287 func (as *APIStub) UserCreate(ctx context.Context, options arvados.CreateOptions) (arvados.User, error) {
288 as.appendCall(ctx, as.UserCreate, options)
289 return arvados.User{}, as.Error
291 func (as *APIStub) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
292 as.appendCall(ctx, as.UserUpdate, options)
293 return arvados.User{}, as.Error
295 func (as *APIStub) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) {
296 as.appendCall(ctx, as.UserActivate, options)
297 return arvados.User{}, as.Error
299 func (as *APIStub) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
300 as.appendCall(ctx, as.UserSetup, options)
303 func (as *APIStub) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
304 as.appendCall(ctx, as.UserUnsetup, options)
305 return arvados.User{}, as.Error
307 func (as *APIStub) UserGet(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
308 as.appendCall(ctx, as.UserGet, options)
309 return arvados.User{}, as.Error
311 func (as *APIStub) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
312 as.appendCall(ctx, as.UserGetCurrent, options)
313 return arvados.User{}, as.Error
315 func (as *APIStub) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
316 as.appendCall(ctx, as.UserGetSystem, options)
317 return arvados.User{}, as.Error
319 func (as *APIStub) UserList(ctx context.Context, options arvados.ListOptions) (arvados.UserList, error) {
320 as.appendCall(ctx, as.UserList, options)
321 return arvados.UserList{}, as.Error
323 func (as *APIStub) UserDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.User, error) {
324 as.appendCall(ctx, as.UserDelete, options)
325 return arvados.User{}, as.Error
327 func (as *APIStub) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) {
328 as.appendCall(ctx, as.UserMerge, options)
329 return arvados.User{}, as.Error
331 func (as *APIStub) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) {
332 as.appendCall(ctx, as.UserBatchUpdate, options)
333 return arvados.UserList{}, as.Error
335 func (as *APIStub) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) {
336 as.appendCall(ctx, as.UserAuthenticate, options)
337 return arvados.APIClientAuthorization{}, as.Error
339 func (as *APIStub) APIClientAuthorizationCurrent(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
340 as.appendCall(ctx, as.APIClientAuthorizationCurrent, options)
341 return arvados.APIClientAuthorization{}, as.Error
343 func (as *APIStub) APIClientAuthorizationCreate(ctx context.Context, options arvados.CreateOptions) (arvados.APIClientAuthorization, error) {
344 as.appendCall(ctx, as.APIClientAuthorizationCreate, options)
345 return arvados.APIClientAuthorization{}, as.Error
347 func (as *APIStub) APIClientAuthorizationUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.APIClientAuthorization, error) {
348 as.appendCall(ctx, as.APIClientAuthorizationUpdate, options)
349 return arvados.APIClientAuthorization{}, as.Error
351 func (as *APIStub) APIClientAuthorizationDelete(ctx context.Context, options arvados.DeleteOptions) (arvados.APIClientAuthorization, error) {
352 as.appendCall(ctx, as.APIClientAuthorizationDelete, options)
353 return arvados.APIClientAuthorization{}, as.Error
355 func (as *APIStub) APIClientAuthorizationList(ctx context.Context, options arvados.ListOptions) (arvados.APIClientAuthorizationList, error) {
356 as.appendCall(ctx, as.APIClientAuthorizationList, options)
357 return arvados.APIClientAuthorizationList{}, as.Error
359 func (as *APIStub) APIClientAuthorizationGet(ctx context.Context, options arvados.GetOptions) (arvados.APIClientAuthorization, error) {
360 as.appendCall(ctx, as.APIClientAuthorizationGet, options)
361 return arvados.APIClientAuthorization{}, as.Error
364 func (as *APIStub) appendCall(ctx context.Context, method interface{}, options interface{}) {
366 defer as.mtx.Unlock()
367 as.calls = append(as.calls, APIStubCall{method, ctx, options})
370 func (as *APIStub) Calls(method interface{}) []APIStubCall {
372 defer as.mtx.Unlock()
373 var calls []APIStubCall
374 for _, call := range as.calls {
375 if method == nil || (runtime.FuncForPC(reflect.ValueOf(call.Method).Pointer()).Name() ==
376 runtime.FuncForPC(reflect.ValueOf(method).Pointer()).Name()) {
377 calls = append(calls, call)
383 type APIStubCall struct {
385 Context context.Context