Skip to content

Commit 30f8fba

Browse files
committed
Add tests for getCredentials with multiple goproxy_servers and maven_repositories
1 parent d6d1743 commit 30f8fba

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/start-proxy.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,47 @@ test("getCredentials returns all for a language when specified", async (t) => {
252252
t.assert(credentialsTypes.includes("git_source"));
253253
});
254254

255+
test("getCredentials returns all goproxy_servers for a language when specified", async (t) => {
256+
const multipleGoproxyServers = [
257+
{ type: "goproxy_server", host: "goproxy1.example.com", token: "token1" },
258+
{ type: "goproxy_server", host: "goproxy2.example.com", token: "token2" },
259+
{ type: "git_source", host: "github.com/github", token: "mno" },
260+
];
261+
262+
const credentials = startProxyExports.getCredentials(
263+
getRunnerLogger(true),
264+
undefined,
265+
toEncodedJSON(multipleGoproxyServers),
266+
KnownLanguage.go,
267+
);
268+
t.is(credentials.length, 3);
269+
270+
const goproxyServers = credentials.filter((c) => c.type === "goproxy_server");
271+
t.is(goproxyServers.length, 2);
272+
t.assert(goproxyServers.some((c) => c.host === "goproxy1.example.com"));
273+
t.assert(goproxyServers.some((c) => c.host === "goproxy2.example.com"));
274+
});
275+
276+
test("getCredentials returns all maven_repositories for a language when specified", async (t) => {
277+
const multipleMavenRepositories = [
278+
{ type: "maven_repository", host: "maven1.pkg.github.com", token: "token1" },
279+
{ type: "maven_repository", host: "maven2.pkg.github.com", token: "token2" },
280+
{ type: "git_source", host: "github.com/github", token: "mno" },
281+
];
282+
283+
const credentials = startProxyExports.getCredentials(
284+
getRunnerLogger(true),
285+
undefined,
286+
toEncodedJSON(multipleMavenRepositories),
287+
KnownLanguage.java,
288+
);
289+
t.is(credentials.length, 2);
290+
291+
const mavenRepositories = credentials.filter((c) => c.type === "maven_repository");
292+
t.assert(mavenRepositories.some((c) => c.host === "maven1.pkg.github.com"));
293+
t.assert(mavenRepositories.some((c) => c.host === "maven2.pkg.github.com"));
294+
});
295+
255296
test("getCredentials returns all credentials when no language specified", async (t) => {
256297
const credentialsInput = toEncodedJSON(mixedCredentials);
257298

0 commit comments

Comments
 (0)