Skip to content

Commit a1c676d

Browse files
committed
Test proxy usage for getRemoteConfig
1 parent 47e9c29 commit a1c676d

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

‎src/config/file.test.ts‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import * as github from "@actions/github";
12
import test from "ava";
23
import sinon from "sinon";
34

5+
import * as api from "../api-client";
6+
import { RegistryProxyVars } from "../environment";
47
import { Feature } from "../feature-flags";
58
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";
714

8-
import { getConfigFileInput } from "./file";
15+
import { getConfigFileInput, getRemoteConfig } from "./file";
916

1017
setupTests(test);
1118

@@ -67,3 +74,47 @@ test("getConfigFileInput ignores repository property value when FF is off", asyn
6774
)
6875
.passes(t.is, undefined);
6976
});
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

Comments
 (0)