|
1 |
| -import { serve } from "bun"; |
2 |
| -import { describe } from "bun:test"; |
| 1 | +import { describe, expect, it } from "bun:test"; |
3 | 2 | import {
|
4 |
| - createJSONResponse, |
| 3 | + findResourceInstance, |
5 | 4 | runTerraformInit,
|
| 5 | + runTerraformApply, |
6 | 6 | testRequiredVariables,
|
7 | 7 | } from "../test";
|
8 | 8 |
|
9 | 9 | describe("jfrog-oauth", async () => {
|
| 10 | + type TestVariables = { |
| 11 | + agent_id: string; |
| 12 | + jfrog_url: string; |
| 13 | + package_managers: string; |
| 14 | + |
| 15 | + username_field?: string; |
| 16 | + jfrog_server_id?: string; |
| 17 | + external_auth_id?: string; |
| 18 | + configure_code_server?: boolean; |
| 19 | + }; |
| 20 | + |
10 | 21 | await runTerraformInit(import.meta.dir);
|
11 | 22 |
|
12 |
| - testRequiredVariables(import.meta.dir, { |
13 |
| - agent_id: "some-agent-id", |
14 |
| - jfrog_url: "http://localhost:8081", |
15 |
| - package_managers: "{}", |
| 23 | + const fakeFrogApi = "localhost:8081/artifactory/api"; |
| 24 | + const fakeFrogUrl = "http://localhost:8081"; |
| 25 | + const user = "default"; |
| 26 | + |
| 27 | + it("can run apply with required variables", async () => { |
| 28 | + testRequiredVariables<TestVariables>(import.meta.dir, { |
| 29 | + agent_id: "some-agent-id", |
| 30 | + jfrog_url: fakeFrogUrl, |
| 31 | + package_managers: "{}", |
| 32 | + }); |
16 | 33 | });
|
17 |
| -}); |
18 | 34 |
|
19 |
| -//TODO add more tests |
| 35 | + it("generates an npmrc with scoped repos", async () => { |
| 36 | + const state = await runTerraformApply<TestVariables>(import.meta.dir, { |
| 37 | + agent_id: "some-agent-id", |
| 38 | + jfrog_url: fakeFrogUrl, |
| 39 | + package_managers: JSON.stringify({ |
| 40 | + npm: ["global", "@foo:foo", "@bar:bar"], |
| 41 | + }), |
| 42 | + }); |
| 43 | + const coderScript = findResourceInstance(state, "coder_script"); |
| 44 | + const npmrcStanza = `cat << EOF > ~/.npmrc |
| 45 | +email=${user}@example.com |
| 46 | +registry=http://${fakeFrogApi}/npm/global |
| 47 | +//${fakeFrogApi}/npm/global/:_authToken= |
| 48 | +@foo:registry=http://${fakeFrogApi}/npm/foo |
| 49 | +//${fakeFrogApi}/npm/foo/:_authToken= |
| 50 | +@bar:registry=http://${fakeFrogApi}/npm/bar |
| 51 | +//${fakeFrogApi}/npm/bar/:_authToken= |
| 52 | +
|
| 53 | +EOF`; |
| 54 | + expect(coderScript.script).toContain(npmrcStanza); |
| 55 | + expect(coderScript.script).toContain( |
| 56 | + 'jf npmc --global --repo-resolve "global"', |
| 57 | + ); |
| 58 | + expect(coderScript.script).toContain( |
| 59 | + 'if [ -z "YES" ]; then\n not_configured npm', |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it("generates a pip config with extra-indexes", async () => { |
| 64 | + const state = await runTerraformApply<TestVariables>(import.meta.dir, { |
| 65 | + agent_id: "some-agent-id", |
| 66 | + jfrog_url: fakeFrogUrl, |
| 67 | + package_managers: JSON.stringify({ |
| 68 | + pypi: ["global", "foo", "bar"], |
| 69 | + }), |
| 70 | + }); |
| 71 | + const coderScript = findResourceInstance(state, "coder_script"); |
| 72 | + const pipStanza = `cat << EOF > ~/.pip/pip.conf |
| 73 | +[global] |
| 74 | +index-url = https://${user}:@${fakeFrogApi}/pypi/global/simple |
| 75 | +extra-index-url = |
| 76 | + https://${user}:@${fakeFrogApi}/pypi/foo/simple |
| 77 | + https://${user}:@${fakeFrogApi}/pypi/bar/simple |
| 78 | +
|
| 79 | +EOF`; |
| 80 | + expect(coderScript.script).toContain(pipStanza); |
| 81 | + expect(coderScript.script).toContain( |
| 82 | + 'jf pipc --global --repo-resolve "global"', |
| 83 | + ); |
| 84 | + expect(coderScript.script).toContain( |
| 85 | + 'if [ -z "YES" ]; then\n not_configured pypi', |
| 86 | + ); |
| 87 | + }); |
| 88 | + |
| 89 | + it("registers multiple docker repos", async () => { |
| 90 | + const state = await runTerraformApply<TestVariables>(import.meta.dir, { |
| 91 | + agent_id: "some-agent-id", |
| 92 | + jfrog_url: fakeFrogUrl, |
| 93 | + package_managers: JSON.stringify({ |
| 94 | + docker: ["foo.jfrog.io", "bar.jfrog.io", "baz.jfrog.io"], |
| 95 | + }), |
| 96 | + }); |
| 97 | + const coderScript = findResourceInstance(state, "coder_script"); |
| 98 | + const dockerStanza = ["foo", "bar", "baz"] |
| 99 | + .map((r) => `register_docker "${r}.jfrog.io"`) |
| 100 | + .join("\n"); |
| 101 | + expect(coderScript.script).toContain(dockerStanza); |
| 102 | + expect(coderScript.script).toContain( |
| 103 | + 'if [ -z "YES" ]; then\n not_configured docker', |
| 104 | + ); |
| 105 | + }); |
| 106 | + |
| 107 | + it("sets goproxy with multiple repos", async () => { |
| 108 | + const state = await runTerraformApply<TestVariables>(import.meta.dir, { |
| 109 | + agent_id: "some-agent-id", |
| 110 | + jfrog_url: fakeFrogUrl, |
| 111 | + package_managers: JSON.stringify({ |
| 112 | + go: ["foo", "bar", "baz"], |
| 113 | + }), |
| 114 | + }); |
| 115 | + const proxyEnv = findResourceInstance(state, "coder_env", "goproxy"); |
| 116 | + const proxies = ["foo", "bar", "baz"] |
| 117 | + .map((r) => `https://${user}:@${fakeFrogApi}/go/${r}`) |
| 118 | + .join(","); |
| 119 | + expect(proxyEnv["value"]).toEqual(proxies); |
| 120 | + |
| 121 | + const coderScript = findResourceInstance(state, "coder_script"); |
| 122 | + expect(coderScript.script).toContain( |
| 123 | + 'jf goc --global --repo-resolve "foo"', |
| 124 | + ); |
| 125 | + expect(coderScript.script).toContain( |
| 126 | + 'if [ -z "YES" ]; then\n not_configured go', |
| 127 | + ); |
| 128 | + }); |
| 129 | +}); |
0 commit comments