(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'already-exists' | 'fail'; webUrl?: string } = {})
| 33 | let glabCallLog: string; |
| 34 | |
| 35 | function makeFakeGh(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'already-exists' | 'fail'; webUrl?: string } = {}) { |
| 36 | const authStatus = opts.authStatus ?? 'ok'; |
| 37 | const repoCreate = opts.repoCreate ?? 'success'; |
| 38 | const webUrl = opts.webUrl ?? `https://github.com/testuser/gstack-artifacts-testuser`; |
| 39 | const script = `#!/bin/bash |
| 40 | echo "gh $@" >> "${ghCallLog}" |
| 41 | case "$1" in |
| 42 | auth) ${authStatus === 'ok' ? 'exit 0' : 'exit 1'} ;; |
| 43 | repo) |
| 44 | shift |
| 45 | case "$1" in |
| 46 | create) |
| 47 | ${ |
| 48 | repoCreate === 'success' |
| 49 | ? 'exit 0' |
| 50 | : repoCreate === 'already-exists' |
| 51 | ? 'echo "GraphQL: Name already exists on this account" >&2; exit 1' |
| 52 | : 'echo "network error" >&2; exit 1' |
| 53 | } |
| 54 | ;; |
| 55 | view) |
| 56 | # gh repo view <name> --json url -q .url |
| 57 | echo "${webUrl}" |
| 58 | exit 0 |
| 59 | ;; |
| 60 | esac |
| 61 | ;; |
| 62 | esac |
| 63 | exit 0 |
| 64 | `; |
| 65 | fs.writeFileSync(path.join(fakeBinDir, 'gh'), script, { mode: 0o755 }); |
| 66 | } |
| 67 | |
| 68 | function makeFakeGlab(opts: { authStatus?: 'ok' | 'fail'; repoCreate?: 'success' | 'fail'; webUrl?: string } = {}) { |
| 69 | const authStatus = opts.authStatus ?? 'ok'; |
no outgoing calls
no test coverage detected