aboutsummaryrefslogtreecommitdiff
path: root/test/unit/git-http.unit.test.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-25 14:56:58 +0200
committerHampusM <hampus@hampusmat.com>2021-07-25 14:56:58 +0200
commit7b3292af22a0496007e974b65cd2e34521c9c429 (patch)
tree8205726e27fa7e5f80cd2a7ffb6c7354a11b6dea /test/unit/git-http.unit.test.ts
parent4f5771726aa8c7b6d4e288df2a79f1ffef55c3a3 (diff)
Reformated unit tests & the setup and teardown scripts
Diffstat (limited to 'test/unit/git-http.unit.test.ts')
-rw-r--r--test/unit/git-http.unit.test.ts50
1 files changed, 25 insertions, 25 deletions
diff --git a/test/unit/git-http.unit.test.ts b/test/unit/git-http.unit.test.ts
index b8a0917..418f32d 100644
--- a/test/unit/git-http.unit.test.ts
+++ b/test/unit/git-http.unit.test.ts
@@ -16,20 +16,20 @@ describe("Git HTTP backend", () => {
app = buildApp({
host: host,
port: port,
- dev_port: 0, // Doesn't matter
+ dev_port: 0,
title: "",
about: "",
base_dir: env.BASE_DIR,
production: false
}, "");
});
-
- afterAll(async () => {
+
+ afterAll(async() => {
await app.close();
- })
+ });
describe("info/refs", () => {
- it("Should make a valid response when the service is git-upload-pack", async () => {
+ it("Should make a valid response when the service is git-upload-pack", async() => {
expect.assertions(7);
const res = await app.inject({
@@ -49,7 +49,7 @@ describe("Git HTTP backend", () => {
expect(payload_lines[payload_lines.length - 1]).toEqual("0000");
});
- it("Should respond with 403 when the service is git-receive-pack", async () => {
+ it("Should respond with 403 when the service is git-receive-pack", async() => {
expect.assertions(3);
const res = await app.inject({
@@ -64,18 +64,18 @@ describe("Git HTTP backend", () => {
});
describe("git-upload-pack", () => {
- it("Should make a valid response", async () => {
+ it("Should make a valid response", async() => {
expect.hasAssertions();
await app.listen(port);
-
+
const head = /^[a-f0-9]+/.exec((await readFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString())[0];
const data = `0098want ${head} multi_ack_detailed no-done side-band-64k thin-pack ofs-delta deepen-since deepen-not agent=git/2.32.0\n00000009done`;
- // Send a post request to git-upload-pack with curl
- //
- // I did it this way because i just couldn't get chunked responses
- // to work with LightMyRequest or Supertest
+ /* Send a post request to git-upload-pack with curl
+
+ I did it this way because i just couldn't get chunked responses
+ to work with LightMyRequest or Supertest */
const res = new Promise((resolve: (value: Record<string, Buffer>) => void, reject: (value: ExecException) => void) => {
const curl_params = [
"-X POST",
@@ -118,33 +118,33 @@ describe("Git HTTP backend", () => {
readable_stdout[readable_stdout.length - 1] = readable_stdout[readable_stdout.length - 1].replace(/.*[\x01]/, "");
expect(readable_stdout[0]).toEqual("0008NAK");
- expect(readable_stdout[1]).toMatch(/Enumerating\ objects:\ \d+,\ done\.$/);
+ expect(readable_stdout[1]).toMatch(/Enumerating objects: \d+, done\.$/);
// Make sure the progress output for counting objects is fine and dandy
const counting_objects = readable_stdout[2].split("###");
for(const progress of counting_objects.slice(0, -1)) {
- expect(progress).toMatch(/^Counting\ objects:\s+\d+%\s\(\d+\/\d+\)/);
+ expect(progress).toMatch(/^Counting objects:\s+\d+%\s\(\d+\/\d+\)/);
}
-
- expect(counting_objects[counting_objects.length - 1]).toMatch(/^Counting\ objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
+
+ expect(counting_objects[counting_objects.length - 1]).toMatch(/^Counting objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
// Make sure the progress output for compressing objects is fine and dandy
const compressing_objects = readable_stdout[3].split("###");
-
+
for(const progress of compressing_objects.slice(0, -1)) {
- expect(progress).toMatch(/^Compressing\ objects:\s+\d+%\s\(\d+\/\d+\)/);
+ expect(progress).toMatch(/^Compressing objects:\s+\d+%\s\(\d+\/\d+\)/);
}
-
- expect(compressing_objects[counting_objects.length - 1]).toMatch(/^Compressing\ objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
-
- //Just to be sure
- expect(readable_stdout[readable_stdout.length - 1]).toMatch(/^A?0{4}/);
+
+ expect(compressing_objects[counting_objects.length - 1]).toMatch(/^Compressing objects:\s+\d+%\s\(\d+\/\d+\),\sdone\./);
+
+ // Just to be sure
+ expect(readable_stdout[readable_stdout.length - 1]).toMatch(/^.?0{4}/);
});
});
describe("git-receive-pack", () => {
- it("Should respond with 403", async () => {
+ it("Should respond with 403", async() => {
expect.assertions(3);
const res = await app.inject({
@@ -154,7 +154,7 @@ describe("Git HTTP backend", () => {
"content-type": "application/x-git-receive-pack-request"
}
});
-
+
expect(res).toBeDefined();
expect(res).toHaveProperty("statusCode");
expect(res.statusCode).toEqual(403);