|
| 1 | +import * as github from "@actions/github"; |
1 | 2 | import test from "ava"; |
2 | 3 | import sinon from "sinon"; |
3 | 4 |
|
| 5 | +import * as api from "../api-client"; |
| 6 | +import { RegistryProxyVars } from "../environment"; |
4 | 7 | import { Feature } from "../feature-flags"; |
5 | 8 | import { RepositoryPropertyName } from "../feature-flags/properties"; |
6 | | -import { callee, setupTests } from "../testing-utils"; |
| 9 | +import { |
| 10 | + callee, |
| 11 | + SAMPLE_DOTCOM_API_DETAILS, |
| 12 | + setupTests, |
| 13 | +} from "../testing-utils"; |
7 | 14 |
|
8 | | -import { getConfigFileInput } from "./file"; |
| 15 | +import { getConfigFileInput, getRemoteConfig } from "./file"; |
9 | 16 |
|
10 | 17 | setupTests(test); |
11 | 18 |
|
@@ -67,3 +74,47 @@ test("getConfigFileInput ignores repository property value when FF is off", asyn |
67 | 74 | ) |
68 | 75 | .passes(t.is, undefined); |
69 | 76 | }); |
| 77 | + |
| 78 | +test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => { |
| 79 | + const client = github.getOctokit("123"); |
| 80 | + const response = { |
| 81 | + data: { |
| 82 | + content: Buffer.from("disable-default-queries: false").toString("base64"), |
| 83 | + }, |
| 84 | + }; |
| 85 | + sinon |
| 86 | + .stub(client.rest.repos, "getContent") |
| 87 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 88 | + .resolves(response as any); |
| 89 | + sinon.stub(api, "getApiClientWithExternalAuth").value(() => client); |
| 90 | + |
| 91 | + const target = callee(getRemoteConfig) |
| 92 | + .withDefaultActionsEnv() |
| 93 | + .withArgs("file.yml", SAMPLE_DOTCOM_API_DETAILS); |
| 94 | + |
| 95 | + // Should use it when the FF is enabled and the environment variables are set. |
| 96 | + await target |
| 97 | + .withFeatures([Feature.ProxyApiRequests, Feature.NewRemoteFileAddresses]) |
| 98 | + .withEnv((env) => { |
| 99 | + env.set(RegistryProxyVars.PROXY_HOST, "localhost"); |
| 100 | + env.set(RegistryProxyVars.PROXY_PORT, "1234"); |
| 101 | + }) |
| 102 | + .logs(t, "Using private registry proxy at 'http://localhost:1234'") |
| 103 | + .passes(t.truthy); |
| 104 | + |
| 105 | + // But not when the FF is not enabled. |
| 106 | + await target |
| 107 | + .withFeatures([Feature.NewRemoteFileAddresses]) |
| 108 | + .withEnv((env) => { |
| 109 | + env.set(RegistryProxyVars.PROXY_HOST, "localhost"); |
| 110 | + env.set(RegistryProxyVars.PROXY_PORT, "1234"); |
| 111 | + }) |
| 112 | + .notLogs(t, "Using private registry proxy at 'http://localhost:1234'") |
| 113 | + .passes(t.truthy); |
| 114 | + |
| 115 | + // And not when the environment variables aren't set. |
| 116 | + await target |
| 117 | + .withFeatures([Feature.ProxyApiRequests, Feature.NewRemoteFileAddresses]) |
| 118 | + .notLogs(t, "Using private registry proxy at 'http://localhost:1234'") |
| 119 | + .passes(t.truthy); |
| 120 | +}); |
0 commit comments