Skip to content

Commit aced754

Browse files
committed
fmt
1 parent 36fa871 commit aced754

File tree

3 files changed

+77
-56
lines changed

3 files changed

+77
-56
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To create a new module, clone this repository and run:
1010

1111
A suite of test-helpers exists to run `terraform apply` on modules with variables, and test script output against containers.
1212

13-
The testing suite must be able to run docker containers with the `--network=host` flag, which typically requires running the tests on linux as this flag does not apply to Docker Desktop for MacOS and Windows. MacOS users can work around this by using something like [Orbstack](https://orbstack.dev/) instead of Docker Desktop.
13+
The testing suite must be able to run docker containers with the `--network=host` flag, which typically requires running the tests on linux as this flag does not apply to Docker Desktop for MacOS and Windows. MacOS users can work around this by using something like [Orbstack](https://orbstack.dev/) instead of Docker Desktop.
1414

1515
Reference existing `*.test.ts` files for implementation.
1616

github-upload-public-key/main.test.ts

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { describe, expect, it } from "bun:test";
2-
import { createJSONResponse, execContainer, findResourceInstance, runContainer, runTerraformApply, runTerraformInit, testRequiredVariables, writeCoder } from "../test";
2+
import {
3+
createJSONResponse,
4+
execContainer,
5+
findResourceInstance,
6+
runContainer,
7+
runTerraformApply,
8+
runTerraformInit,
9+
testRequiredVariables,
10+
writeCoder,
11+
} from "../test";
312
import { Server, serve } from "bun";
413

514
describe("github-upload-public-key", async () => {
@@ -13,77 +22,89 @@ describe("github-upload-public-key", async () => {
1322
const { instance, id } = await setupContainer();
1423
await writeCoder(id, "echo foo");
1524
let exec = await execContainer(id, ["bash", "-c", instance.script]);
16-
expect(exec.stdout).toContain("Coder public SSH key uploaded to GitHub!")
25+
expect(exec.stdout).toContain("Coder public SSH key uploaded to GitHub!");
1726
expect(exec.exitCode).toBe(0);
1827
});
1928

2029
it("does nothing if one already exists", async () => {
2130
const { instance, id } = await setupContainer();
2231
await writeCoder(id, "echo findkey");
2332
let exec = await execContainer(id, ["bash", "-c", instance.script]);
24-
expect(exec.stdout).toContain("Coder public SSH key is already uploaded to GitHub!")
33+
expect(exec.stdout).toContain(
34+
"Coder public SSH key is already uploaded to GitHub!",
35+
);
2536
expect(exec.exitCode).toBe(0);
2637
});
2738
});
2839

2940
const setupContainer = async (
30-
image = "lorello/alpine-bash",
31-
vars: Record<string, string> = {},
32-
) => {
33-
const server = await setupServer();
34-
const state = await runTerraformApply(import.meta.dir, {
35-
agent_id: "foo",
36-
// trim the trailing slash on the URL
37-
access_url: server.url.toString().slice(0, -1),
38-
owner_session_token: "bar",
39-
github_api_url: server.url.toString().slice(0, -1),
40-
...vars,
41-
});
42-
const instance = findResourceInstance(state, "coder_script");
43-
const id = await runContainer(image);
44-
return { id, instance };
41+
image = "lorello/alpine-bash",
42+
vars: Record<string, string> = {},
43+
) => {
44+
const server = await setupServer();
45+
const state = await runTerraformApply(import.meta.dir, {
46+
agent_id: "foo",
47+
// trim the trailing slash on the URL
48+
access_url: server.url.toString().slice(0, -1),
49+
owner_session_token: "bar",
50+
github_api_url: server.url.toString().slice(0, -1),
51+
...vars,
52+
});
53+
const instance = findResourceInstance(state, "coder_script");
54+
const id = await runContainer(image);
55+
return { id, instance };
4556
};
4657

4758
const setupServer = async (): Promise<Server> => {
48-
let url: URL;
49-
const fakeSlackHost = serve({
50-
fetch: (req) => {
51-
url = new URL(req.url);
52-
if (url.pathname === "/api/v2/users/me/gitsshkey") {
53-
return createJSONResponse({
54-
public_key: "exists",
55-
});
56-
}
57-
58-
if (url.pathname === "/user/keys") {
59-
if (req.method === "POST") {
60-
return createJSONResponse({
61-
key: "created",
62-
}, 201);
63-
}
59+
let url: URL;
60+
const fakeSlackHost = serve({
61+
fetch: (req) => {
62+
url = new URL(req.url);
63+
if (url.pathname === "/api/v2/users/me/gitsshkey") {
64+
return createJSONResponse({
65+
public_key: "exists",
66+
});
67+
}
6468

65-
// case: key already exists
66-
if (req.headers.get("Authorization") == "Bearer findkey") {
67-
return createJSONResponse([{
68-
key: "foo",
69-
}, {
70-
key: "exists",
71-
}]);
72-
}
69+
if (url.pathname === "/user/keys") {
70+
if (req.method === "POST") {
71+
return createJSONResponse(
72+
{
73+
key: "created",
74+
},
75+
201,
76+
);
77+
}
7378

74-
// case: key does not exist
75-
return createJSONResponse([{
76-
key: "foo",
77-
}]);
79+
// case: key already exists
80+
if (req.headers.get("Authorization") == "Bearer findkey") {
81+
return createJSONResponse([
82+
{
83+
key: "foo",
84+
},
85+
{
86+
key: "exists",
87+
},
88+
]);
7889
}
7990

91+
// case: key does not exist
92+
return createJSONResponse([
93+
{
94+
key: "foo",
95+
},
96+
]);
97+
}
8098

81-
return createJSONResponse({
82-
error: "not_found"
83-
}, 404);
84-
},
85-
port: 0,
86-
});
99+
return createJSONResponse(
100+
{
101+
error: "not_found",
102+
},
103+
404,
104+
);
105+
},
106+
port: 0,
107+
});
87108

88-
return fakeSlackHost;
89-
}
109+
return fakeSlackHost;
110+
};

github-upload-public-key/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ variable "external_auth_id" {
2323
variable "github_api_url" {
2424
type = string
2525
description = "The URL of the GitHub instance."
26-
default = "https://api.github.com"
26+
default = "https://api.github.com"
2727
}
2828

2929
// Optional variables mostly for testing purposes, will normally come from data.coder_workspace.me

0 commit comments

Comments
 (0)