Skip to content

Commit 1a0eca3

Browse files
committed
Validate proxy argument in tests
1 parent d705aa3 commit 1a0eca3

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/config/file.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => {
8686
.stub(client.rest.repos, "getContent")
8787
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8888
.resolves(response as any);
89-
sinon.stub(api, "getApiClientWithExternalAuth").value(() => client);
89+
90+
// We stub `getApiClientWithExternalAuth` so that it throws if no
91+
// proxy is provided and returns the client otherwise. This allows us
92+
// to verify the result in the following test cases.
93+
const errorMessage = "No `proxy` was provided by the caller.";
94+
sinon
95+
.stub(api, "getApiClientWithExternalAuth")
96+
.callsFake((_details, proxy) => {
97+
// Throw if proxy isn't defined.
98+
if (proxy === undefined) {
99+
throw new Error(errorMessage);
100+
}
101+
// Otherwise return the client object.
102+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
103+
return client as unknown as any;
104+
});
90105

91106
const target = callee(getRemoteConfig)
92107
.withDefaultActionsEnv()
@@ -110,11 +125,11 @@ test.serial("getRemoteConfig uses proxy when it is supposed to", async (t) => {
110125
env.set(RegistryProxyVars.PROXY_PORT, "1234");
111126
})
112127
.notLogs(t, "Using private registry proxy at 'http://localhost:1234'")
113-
.passes(t.truthy);
128+
.throws(t, { message: errorMessage });
114129

115130
// And not when the environment variables aren't set.
116131
await target
117132
.withFeatures([Feature.ProxyApiRequests, Feature.NewRemoteFileAddresses])
118133
.notLogs(t, "Using private registry proxy at 'http://localhost:1234'")
119-
.passes(t.truthy);
134+
.throws(t, { message: errorMessage });
120135
});

0 commit comments

Comments
 (0)