Skip to content

Commit 9ac84a7

Browse files
committed
refactor
1 parent 8e4ec1e commit 9ac84a7

3 files changed

Lines changed: 18 additions & 43 deletions

File tree

src/github.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ describe("GitHub", () => {
6565
await using _gitConfig = await isolateGitConfig();
6666
const actionToken = "action-token";
6767
const checkoutToken = "checkout-token";
68-
await using remote = await createGitHttpRemote(
69-
getAuthorization(actionToken),
70-
{ "file.txt": "initial\n" },
71-
);
68+
await using remote = await createGitHttpRemote({
69+
"file.txt": "initial\n",
70+
});
7271
await using repositoryFixture = await shallowClone(remote.path);
7372
const repository = repositoryFixture.path;
7473

@@ -113,10 +112,9 @@ describe("GitHub", () => {
113112
it("uses github-token instead of credentials embedded in the CLI push URL", async () => {
114113
await using _gitConfig = await isolateGitConfig();
115114
const actionToken = "action-token";
116-
await using remote = await createGitHttpRemote(
117-
getAuthorization(actionToken),
118-
{ "file.txt": "initial\n" },
119-
);
115+
await using remote = await createGitHttpRemote({
116+
"file.txt": "initial\n",
117+
});
120118
await using repositoryFixture = await shallowClone(remote.path);
121119
const repository = repositoryFixture.path;
122120

src/test-utils/gitHttpServer.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ function recordRequest(request: IncomingMessage): RecordedRequest {
2323
}
2424

2525
async function runGitHttpBackend(
26+
cwd: string,
2627
request: IncomingMessage,
2728
response: ServerResponse,
28-
projectRoot: string,
2929
) {
3030
const requestUrl = new URL(
3131
request.url ?? "/",
@@ -36,7 +36,7 @@ async function runGitHttpBackend(
3636
CONTENT_LENGTH: request.headers["content-length"] ?? "0",
3737
GATEWAY_INTERFACE: "CGI/1.1",
3838
GIT_HTTP_EXPORT_ALL: "1",
39-
GIT_PROJECT_ROOT: projectRoot,
39+
GIT_PROJECT_ROOT: cwd,
4040
PATH_INFO: decodeURIComponent(requestUrl.pathname),
4141
QUERY_STRING: requestUrl.search.slice(1),
4242
REMOTE_ADDR: request.socket.remoteAddress ?? "",
@@ -115,36 +115,19 @@ async function listen(server: http.Server) {
115115
}
116116
}
117117

118-
export async function createGitHttpServer(options: {
119-
projectRoot: string;
120-
expectedAuthorization: string;
121-
}) {
118+
export async function createGitHttpServer(cwd: string) {
122119
const requests: RecordedRequest[] = [];
123120
const server = http.createServer((request, response) => {
124121
const recordedRequest = recordRequest(request);
125122
requests.push(recordedRequest);
126-
const authorizationHeaders = recordedRequest.headers.authorization ?? [];
127-
128-
if (
129-
authorizationHeaders.length !== 1 ||
130-
authorizationHeaders[0] !== options.expectedAuthorization
131-
) {
132-
response.writeHead(401, {
133-
"WWW-Authenticate": 'Basic realm="changesets-action-test"',
134-
});
135-
response.end();
136-
return;
137-
}
138123

139-
void runGitHttpBackend(request, response, options.projectRoot).catch(
140-
(error: unknown) => {
141-
response.destroy(
142-
Error.isError(error)
143-
? error
144-
: new Error("Server error", { cause: error }),
145-
);
146-
},
147-
);
124+
void runGitHttpBackend(cwd, request, response).catch((error: unknown) => {
125+
response.destroy(
126+
Error.isError(error)
127+
? error
128+
: new Error("Server error", { cause: error }),
129+
);
130+
});
148131
});
149132

150133
await listen(server);

src/test-utils/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,11 @@ async function createLocalRemote(dir: Fixture) {
109109
return moveDisposable(stack, fixture);
110110
}
111111

112-
export async function createGitHttpRemote(
113-
expectedAuthorization: string,
114-
files: Fixture,
115-
) {
112+
export async function createGitHttpRemote(files: Fixture) {
116113
await using stack = new AsyncDisposableStack();
117114
const fixture = stack.use(await createLocalRemote(files));
118115
const server = stack.use(
119-
await createGitHttpServer({
120-
projectRoot: path.dirname(fixture.path),
121-
expectedAuthorization,
122-
}),
116+
await createGitHttpServer(path.dirname(fixture.path)),
123117
);
124118

125119
return moveDisposable(stack, {

0 commit comments

Comments
 (0)