|
| 1 | +nextflow_function { |
| 2 | + name "SeqeraApi helper functions" |
| 3 | + |
| 4 | + test("apiGetAllTasks paginates until the final short page") { |
| 5 | + function "SeqeraApi.apiGetAllTasks" |
| 6 | + |
| 7 | + when { |
| 8 | + function { |
| 9 | + """ |
| 10 | + SeqeraApi.metaClass.'static'.apiGet = { String url, Map headers -> |
| 11 | + if (url.contains('offset=0')) { |
| 12 | + return [tasks: (1..100).collect { [taskId: it] }] |
| 13 | + } |
| 14 | + if (url.contains('offset=100')) { |
| 15 | + return [tasks: [[taskId: 101], [taskId: 102]]] |
| 16 | + } |
| 17 | + throw new RuntimeException("Unexpected URL: \${url}") |
| 18 | + } |
| 19 | + |
| 20 | + input[0] = 'https://example.com/tasks?workspaceId=55' |
| 21 | + input[1] = [Authorization: 'Bearer test-token'] |
| 22 | + """ |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + then { |
| 27 | + assert function.success |
| 28 | + assert function.result*.taskId == (1..102).toList() |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + test("resolveWorkspaceId returns the matching workspace id") { |
| 33 | + function "SeqeraApi.resolveWorkspaceId" |
| 34 | + |
| 35 | + when { |
| 36 | + function { |
| 37 | + """ |
| 38 | + SeqeraApi.metaClass.'static'.apiGet = { String url, Map headers -> |
| 39 | + if (url == 'https://api.example.com/orgs') { |
| 40 | + return [organizations: [[name: 'acme', orgId: 7], [name: 'other', orgId: 8]]] |
| 41 | + } |
| 42 | + if (url == 'https://api.example.com/orgs/7/workspaces') { |
| 43 | + return [workspaces: [[name: 'workspace-a', id: 11], [name: 'workspace-b', id: 42]]] |
| 44 | + } |
| 45 | + throw new RuntimeException("Unexpected URL: \${url}") |
| 46 | + } |
| 47 | + |
| 48 | + input[0] = 'acme/workspace-b' |
| 49 | + input[1] = 'https://api.example.com' |
| 50 | + input[2] = [Authorization: 'Bearer test-token'] |
| 51 | + """ |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + then { |
| 56 | + assert function.success |
| 57 | + assert function.result == 42L |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + test("resolveWorkspaceId fails when the workspace is missing") { |
| 62 | + function "SeqeraApi.resolveWorkspaceId" |
| 63 | + |
| 64 | + when { |
| 65 | + function { |
| 66 | + """ |
| 67 | + SeqeraApi.metaClass.'static'.apiGet = { String url, Map headers -> |
| 68 | + if (url == 'https://api.example.com/orgs') { |
| 69 | + return [organizations: [[name: 'acme', orgId: 7]]] |
| 70 | + } |
| 71 | + if (url == 'https://api.example.com/orgs/7/workspaces') { |
| 72 | + return [workspaces: [[name: 'workspace-a', id: 11]]] |
| 73 | + } |
| 74 | + throw new RuntimeException("Unexpected URL: \${url}") |
| 75 | + } |
| 76 | + |
| 77 | + input[0] = 'acme/workspace-b' |
| 78 | + input[1] = 'https://api.example.com' |
| 79 | + input[2] = [Authorization: 'Bearer test-token'] |
| 80 | + """ |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + then { |
| 85 | + assert function.failed |
| 86 | + assert function.stdout.any { it.contains("Workspace 'workspace-b' not found in org 'acme'") } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments