Skip to content

Commit 5bc2aa4

Browse files
committed
Fix JetBrains Gateway tests for multiple IDEs
- Allow creation of links with multiple IDEs. - Ensure outputs handle arrays for identifying multiple IDEs. - Update runTerraformApply to handle array values as JSON strings.
1 parent 4452630 commit 5bc2aa4

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

jetbrains-gateway/main.test.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ describe("jetbrains-gateway", async () => {
1616

1717
it("should create a link with the default values", async () => {
1818
const state = await runTerraformApply(import.meta.dir, {
19-
// These are all required.
2019
agent_id: "foo",
2120
agent_name: "foo",
2221
folder: "/home/coder",
2322
});
24-
expect(state.outputs.url.value).toBe(
23+
expect(state.outputs.url.value).toEqual([
2524
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=241.14494.240&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.1.tar.gz",
26-
);
25+
]);
2726

2827
const coder_app = state.resources.find(
2928
(res) => res.type === "coder_app" && res.name === "gateway",
@@ -34,13 +33,31 @@ describe("jetbrains-gateway", async () => {
3433
expect(coder_app?.instances[0].attributes.order).toBeNull();
3534
});
3635

37-
it("default to first ide", async () => {
36+
it("default to first IDE", async () => {
37+
const state = await runTerraformApply(import.meta.dir, {
38+
agent_id: "foo",
39+
agent_name: "foo",
40+
folder: "/home/foo",
41+
jetbrains_ides: ["IU", "PY"],
42+
});
43+
expect(state.outputs.identifier.value).toEqual(["IU"]);
44+
expect(state.outputs.url.value).toEqual([
45+
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=241.14494.240&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.1.tar.gz",
46+
]);
47+
});
48+
49+
it("should create multiple IDEs", async () => {
3850
const state = await runTerraformApply(import.meta.dir, {
3951
agent_id: "foo",
4052
agent_name: "foo",
4153
folder: "/home/foo",
42-
jetbrains_ides: '["IU", "GO", "PY"]',
54+
default: ["GO", "IU", "PY"],
4355
});
44-
expect(state.outputs.identifier.value).toBe("IU");
56+
expect(state.outputs.identifier.value).toEqual(["GO", "IU", "PY"]);
57+
expect(state.outputs.url.value).toEqual([
58+
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=GO&ide_build_number=241.14494.238&ide_download_link=https://download.jetbrains.com/go/goland-2024.1.tar.gz",
59+
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=241.14494.240&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.1.tar.gz",
60+
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&agent=foo&folder=/home/foo&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=PY&ide_build_number=241.14494.241&ide_download_link=https://download.jetbrains.com/python/pycharm-professional-2024.1.tar.gz",
61+
]);
4562
});
4663
});

test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ export const runTerraformApply = async <TVars extends TerraformVariables>(
200200

201201
const combinedEnv = env === undefined ? {} : { ...env };
202202
for (const [key, value] of Object.entries(vars)) {
203-
combinedEnv[`TF_VAR_${key}`] = String(value);
203+
// Convert arrays to JSON strings
204+
combinedEnv[`TF_VAR_${key}`] = Array.isArray(value) ? JSON.stringify(value) : String(value);
204205
}
205206

206207
const proc = spawn(

0 commit comments

Comments
 (0)