|
1 | 1 | import test from "ava"; |
2 | 2 |
|
| 3 | +import { ActionsEnvVars } from "./environment"; |
3 | 4 | import * as github from "./github"; |
4 | | -import { setupTests } from "./testing-utils"; |
| 5 | +import { getTestEnv, setupTests } from "./testing-utils"; |
5 | 6 |
|
6 | 7 | setupTests(test); |
7 | 8 |
|
@@ -67,3 +68,44 @@ test("parseGitHubUrl", (t) => { |
67 | 68 | message: '"http:///::::433" is not a valid URL', |
68 | 69 | }); |
69 | 70 | }); |
| 71 | + |
| 72 | +test("getCurrentInstance throws if required env vars aren't set", (t) => { |
| 73 | + t.throws(() => github.getCurrentInstance(getTestEnv())); |
| 74 | + t.throws(() => { |
| 75 | + const env = getTestEnv({ |
| 76 | + [ActionsEnvVars.GITHUB_SERVER_URL]: "https://localhost", |
| 77 | + }); |
| 78 | + github.getCurrentInstance(env); |
| 79 | + }); |
| 80 | + t.throws(() => { |
| 81 | + const env = getTestEnv({ |
| 82 | + [ActionsEnvVars.GITHUB_API_URL]: "https://api.localhost", |
| 83 | + }); |
| 84 | + github.getCurrentInstance(env); |
| 85 | + }); |
| 86 | +}); |
| 87 | + |
| 88 | +test("getCurrentInstance constructs instance from environment", (t) => { |
| 89 | + const url = "https://localhost"; |
| 90 | + const apiUrl = "https://api.localhost"; |
| 91 | + |
| 92 | + const env = getTestEnv({ |
| 93 | + [ActionsEnvVars.GITHUB_SERVER_URL]: url, |
| 94 | + [ActionsEnvVars.GITHUB_API_URL]: apiUrl, |
| 95 | + }); |
| 96 | + const instance = github.getCurrentInstance(env); |
| 97 | + |
| 98 | + t.is(instance.url, url); |
| 99 | + t.is(instance.apiURL, apiUrl); |
| 100 | +}); |
| 101 | + |
| 102 | +test("getCurrentInstance constructs dotcom instance with dotcom env vars", (t) => { |
| 103 | + const env = getTestEnv({ |
| 104 | + [ActionsEnvVars.GITHUB_SERVER_URL]: github.GITHUB_DOTCOM_URL, |
| 105 | + [ActionsEnvVars.GITHUB_API_URL]: github.GITHUB_DOTCOM_API_URL, |
| 106 | + }); |
| 107 | + const instance = github.getCurrentInstance(env); |
| 108 | + const dotcomInstance = github.getDotcomInstance(); |
| 109 | + |
| 110 | + t.deepEqual(dotcomInstance, instance); |
| 111 | +}); |
0 commit comments