aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-07 12:24:08 +0200
committerHampusM <hampus@hampusmat.com>2021-07-07 12:24:08 +0200
commit6e7365a8c47c89eaab93c73e4a0b4ce4e69d0cb1 (patch)
treefef884af0240dad25d96008ccb0590f47d4d134f /test
parent1ba1c1ffd03adbee82869dae9fdc75767719b287 (diff)
Added env variables for testing & fixed other test stuff
Diffstat (limited to 'test')
-rw-r--r--test/setup.ts34
-rw-r--r--test/test.env7
-rw-r--r--test/unit/commit.unit.test.ts23
-rw-r--r--test/unit/repository.unit.test.ts14
4 files changed, 53 insertions, 25 deletions
diff --git a/test/setup.ts b/test/setup.ts
new file mode 100644
index 0000000..d0b1410
--- /dev/null
+++ b/test/setup.ts
@@ -0,0 +1,34 @@
+import { access, mkdir, remove, copy } from "fs-extra";
+import { promisify } from "util";
+import { exec } from "child_process";
+import { config } from "dotenv";
+
+const promiseExec = promisify(exec);
+config({ path: "test/test.env" });
+
+export default async function init() {
+ const can_access = await access(process.env.BASE_DIR)
+ .then(() => true)
+ .catch(() => false);
+
+ console.log(can_access);
+
+ if(can_access) {
+ await remove(process.env.BASE_DIR);
+ }
+
+ await mkdir(process.env.BASE_DIR);
+ await mkdir(`${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`);
+
+ await copy(".git", `${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`);
+
+ process.chdir(`${process.env.BASE_DIR}/${process.env.AVAIL_REPO}`);
+
+ const { stdout, stderr } = await promiseExec("git config core.bare true");
+
+ if(stderr) {
+ throw(stderr);
+ }
+
+ process.chdir("../..");
+} \ No newline at end of file
diff --git a/test/test.env b/test/test.env
new file mode 100644
index 0000000..4ff13ac
--- /dev/null
+++ b/test/test.env
@@ -0,0 +1,7 @@
+BASE_DIR=git
+AVAIL_REPO=githermit.git
+UNAVAIL_REPO=angular
+AVAIL_OBJECT=16778756fb25808a1311403590cd7d36fbbeee6c
+UNAVAIL_OBJECT=601747563bff808a1d12403690cd7d36fbbeafcc
+AVAIL_COMMIT=d546492f4fd400ae61a6abbe1905fdbc67451c4d
+UNAVAIL_COMMIT=a546392f4fd440ae61a6afec1d25fdbc67251e2b \ No newline at end of file
diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts
index c4bb6f8..b8bd178 100644
--- a/test/unit/commit.unit.test.ts
+++ b/test/unit/commit.unit.test.ts
@@ -1,43 +1,32 @@
-
import { Repository } from "server/src/git/repository";
import { Commit } from "server/src/git/commit";
describe("Commit", () => {
- const base_dir = "/home/hampus/Projects";
-
let repository: Repository;
beforeAll(async () => {
- repository = await Repository.open(base_dir, "githermit");
+ repository = await Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO);
});
test("Lookup a existing commit by id", async () => {
- const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d";
-
- const lookupCommit = jest.fn(() => Commit.lookup(repository, id));
+ const lookupCommit = jest.fn(() => Commit.lookup(repository, process.env.AVAIL_COMMIT));
const commit = await lookupCommit();
expect(lookupCommit).toReturn();
- expect(commit.id).toBe(id);
+ expect(commit.id).toBe(process.env.AVAIL_COMMIT);
});
test("Lookup a nonexistant commit by id throws", async () => {
- const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b";
-
- expect(Commit.lookup(repository, id)).rejects.toThrow();
+ expect(Commit.lookup(repository, process.env.UNAVAIL_COMMIT)).rejects.toThrow();
});
test("Lookup if an existing commit exists by id", async () => {
- const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d";
-
- expect(Commit.lookupExists(repository, id)).resolves.toBeTruthy();
+ expect(Commit.lookupExists(repository, process.env.AVAIL_COMMIT)).resolves.toBeTruthy();
});
test("Lookup if an nonexistant commit exists by id", async () => {
- const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b";
-
- expect(Commit.lookupExists(repository, id)).resolves.toBeFalsy();
+ expect(Commit.lookupExists(repository, process.env.UNAVAIL_COMMIT)).resolves.toBeFalsy();
});
describe("Functions", () => {
diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts
index 0e13a2a..2a68a29 100644
--- a/test/unit/repository.unit.test.ts
+++ b/test/unit/repository.unit.test.ts
@@ -1,10 +1,8 @@
import { Repository } from "server/src/git/repository";
describe("Repository", () => {
- const base_dir = "/home/hampus/Projects";
-
test("Open existing repository", async () => {
- const openRepository = jest.fn(() => Repository.open(base_dir, "githermit"));
+ const openRepository = jest.fn(() => Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO));
await openRepository();
@@ -12,11 +10,11 @@ describe("Repository", () => {
});
test("Open nonexistant repository throws", async () => {
- expect(Repository.open(base_dir, "angular")).rejects.toThrow();
+ expect(Repository.open(process.env.BASE_DIR, process.env.UNAVAIL_REPO)).rejects.toThrow();
});
test("Open all repositories", async () => {
- const openAllRepositories = jest.fn(() => Repository.openAll(base_dir));
+ const openAllRepositories = jest.fn(() => Repository.openAll(process.env.BASE_DIR));
await openAllRepositories();
@@ -27,17 +25,17 @@ describe("Repository", () => {
let repository: Repository;
beforeAll(async () => {
- repository = await Repository.open(base_dir, "githermit");
+ repository = await Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO);
});
test("Lookup if an existing object exists", async () => {
- const exists = await repository.lookupExists("16778756fb25808a1311403590cd7d36fbbeee6c");
+ const exists = await repository.lookupExists(process.env.AVAIL_OBJECT);
expect(exists).toBeTruthy();
});
test("Lookup if an nonexistant object exists", async () => {
- const exists = await repository.lookupExists("601747563bff808a1d12403690cd7d36fbbeafcc");
+ const exists = await repository.lookupExists(process.env.UNAVAIL_OBJECT);
expect(exists).toBeFalsy();
});