diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-12 15:37:30 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-12 15:37:30 +0200 |
commit | d41b27f43335cfb1a8ff49aeb121f992332429cf (patch) | |
tree | 93b6e1ec9b292c3d80ee1a538d0e729612148052 /test | |
parent | 30f0b2ee1f494be1786280040fb47ec18bde8a6d (diff) |
Cleaned up the settings implementation & renamed base_dir project-wide to git_dir
Diffstat (limited to 'test')
-rw-r--r-- | test/int/api.int.test.ts | 11 | ||||
-rw-r--r-- | test/setup.ts | 10 | ||||
-rw-r--r-- | test/teardown.ts | 2 | ||||
-rw-r--r-- | test/test.env | 2 | ||||
-rw-r--r-- | test/unit/blob.unit.test.ts | 4 | ||||
-rw-r--r-- | test/unit/branch.unit.test.ts | 8 | ||||
-rw-r--r-- | test/unit/commit.unit.test.ts | 2 | ||||
-rw-r--r-- | test/unit/diff.unit.test.ts | 2 | ||||
-rw-r--r-- | test/unit/misc.unit.test.ts | 8 | ||||
-rw-r--r-- | test/unit/patch.unit.test.ts | 6 | ||||
-rw-r--r-- | test/unit/repository.unit.test.ts | 12 | ||||
-rw-r--r-- | test/unit/tag.unit.test.ts | 4 | ||||
-rw-r--r-- | test/unit/tree.unit.test.ts | 4 | ||||
-rw-r--r-- | test/unit/tree_entry.unit.test.ts | 8 | ||||
-rw-r--r-- | test/util.ts | 2 |
15 files changed, 43 insertions, 42 deletions
diff --git a/test/int/api.int.test.ts b/test/int/api.int.test.ts index 202aa88..70cf263 100644 --- a/test/int/api.int.test.ts +++ b/test/int/api.int.test.ts @@ -19,12 +19,13 @@ describe("API", () => { app = buildApp({ host: host, port: port, - dev_port: 0, title: "Bob's cool projects", about: "All of my personal projects. Completely FOSS.", - base_dir: env.BASE_DIR, - production: false - }, ""); + git_dir: env.GIT_DIR, + dev: { + port: 0 + } + }); await app.listen(port); @@ -265,7 +266,7 @@ describe("API", () => { beforeAll(async() => { const body = new Readable({ read: () => null }); - let head = (await readFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString(); + let head = (await readFile(`${env.GIT_DIR}/${env.AVAIL_REPO}/FETCH_HEAD`)).toString(); const find_head = /^[a-f0-9]+/.exec(head); diff --git a/test/setup.ts b/test/setup.ts index d446296..764c07a 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -8,17 +8,17 @@ config({ path: "test/test.env" }); const env = process.env as EnvironmentVariables; export default async function(): Promise<void> { - const can_access = await access(env.BASE_DIR) + const can_access = await access(env.GIT_DIR) .then(() => true) .catch(() => false); if(can_access) { - await remove(env.BASE_DIR); + await remove(env.GIT_DIR); } - await mkdir(env.BASE_DIR); + await mkdir(env.GIT_DIR); - const repository = await Clone.clone(env.AVAIL_REPO_URL, `${env.BASE_DIR}/${env.AVAIL_REPO}`, { bare: 1 }); + const repository = await Clone.clone(env.AVAIL_REPO_URL, `${env.GIT_DIR}/${env.AVAIL_REPO}`, { bare: 1 }); const config = await repository.config(); await config.setString("user.name", "BobDylan"); @@ -27,5 +27,5 @@ export default async function(): Promise<void> { await repository.fetchAll(); await repository.createTag((await repository.getMasterCommit()).id(), "1.2", "Fixed stuff"); - await writeFile(`${env.BASE_DIR}/${env.AVAIL_REPO}/owner`, "Bob"); + await writeFile(`${env.GIT_DIR}/${env.AVAIL_REPO}/owner`, "Bob"); }
\ No newline at end of file diff --git a/test/teardown.ts b/test/teardown.ts index c5b49e3..a78bede 100644 --- a/test/teardown.ts +++ b/test/teardown.ts @@ -4,5 +4,5 @@ import { EnvironmentVariables } from "./util"; const env = process.env as EnvironmentVariables; export default async function(): Promise<void> { - await remove(env.BASE_DIR); + await remove(env.GIT_DIR); }
\ No newline at end of file diff --git a/test/test.env b/test/test.env index 3017693..98c7588 100644 --- a/test/test.env +++ b/test/test.env @@ -1,4 +1,4 @@ -BASE_DIR=/tmp/githermit_test +GIT_DIR=/tmp/githermit_test AVAIL_REPO=githermit.git AVAIL_REPO_URL=https://gitlab.com/HampusMat/githermit.git UNAVAIL_REPO=angular diff --git a/test/unit/blob.unit.test.ts b/test/unit/blob.unit.test.ts index 1771255..308245a 100644 --- a/test/unit/blob.unit.test.ts +++ b/test/unit/blob.unit.test.ts @@ -10,7 +10,7 @@ describe("Blob", () => { it("Should the get a blob from a path in a tree", async() => { expect.assertions(2); - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); const blob = await Blob.fromPath(tree, "packages/client/src/main.ts"); expect(blob).toBeDefined(); @@ -22,7 +22,7 @@ describe("Blob", () => { let blob: Blob; beforeAll(async() => { - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); blob = await Blob.fromPath(tree, "packages/client/src/main.ts"); }); diff --git a/test/unit/branch.unit.test.ts b/test/unit/branch.unit.test.ts index 3f067a8..cf37fb5 100644 --- a/test/unit/branch.unit.test.ts +++ b/test/unit/branch.unit.test.ts @@ -9,7 +9,7 @@ describe("Branch", () => { it("Should lookup a branch", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch = await Branch.lookup(repository, "master"); expect(branch).toBeDefined(); @@ -19,7 +19,7 @@ describe("Branch", () => { it("Should lookup if an existent branch exists and respond true", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch_exists = await Branch.lookupExists(repository.ng_repository, "master"); expect(branch_exists).toBeDefined(); @@ -29,7 +29,7 @@ describe("Branch", () => { it("Should lookup if an nonexistent branch exists and respond false", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const branch_exists = await Branch.lookupExists(repository.ng_repository, "wubbalubbadubdub"); expect(branch_exists).toBeDefined(); @@ -41,7 +41,7 @@ describe("Branch", () => { let branch: Branch; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); branch = await Branch.lookup(repository, "master"); }); diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts index e9e0e0d..21c04db 100644 --- a/test/unit/commit.unit.test.ts +++ b/test/unit/commit.unit.test.ts @@ -10,7 +10,7 @@ describe("Commit", () => { let repository: Repository; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); }); describe("Class methods", () => { diff --git a/test/unit/diff.unit.test.ts b/test/unit/diff.unit.test.ts index ed4061b..2f88d29 100644 --- a/test/unit/diff.unit.test.ts +++ b/test/unit/diff.unit.test.ts @@ -9,7 +9,7 @@ describe("Diff", () => { let diff: Diff; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); diff = await (await repository.head()).diff(); }); diff --git a/test/unit/misc.unit.test.ts b/test/unit/misc.unit.test.ts index c45d8ba..38c69fd 100644 --- a/test/unit/misc.unit.test.ts +++ b/test/unit/misc.unit.test.ts @@ -44,7 +44,7 @@ describe("Miscellaneous functions", () => { it("Should return the content of a file in a bare git repository", async() => { expect.assertions(2); - const content = await getFile(env.BASE_DIR, env.AVAIL_REPO, "description"); + const content = await getFile(env.GIT_DIR, env.AVAIL_REPO, "description"); expect(content).toBeDefined(); expect(content).toEqual("Unnamed repository; edit this file 'description' to name the repository."); @@ -53,7 +53,7 @@ describe("Miscellaneous functions", () => { it("Should fail to return the content of a nonexistent file in a bare repository", async() => { expect.assertions(1); - await expect(getFile(env.BASE_DIR, env.AVAIL_REPO, "myselfasteem")).rejects.toBeInstanceOf(BaseError); + await expect(getFile(env.GIT_DIR, env.AVAIL_REPO, "myselfasteem")).rejects.toBeInstanceOf(BaseError); }); }); @@ -61,7 +61,7 @@ describe("Miscellaneous functions", () => { it("Should return the content of a directory", async() => { expect.assertions(3); - const dir = await getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/refs`); + const dir = await getDirectory(`${env.GIT_DIR}/${env.AVAIL_REPO}/refs`); expect(dir).toBeDefined(); expect(dir).toContain("heads"); @@ -71,7 +71,7 @@ describe("Miscellaneous functions", () => { it("Should fail to return the content of a nonexistent directory", async() => { expect.assertions(1); - await expect(getDirectory(`${env.BASE_DIR}/${env.AVAIL_REPO}/something`)).rejects.toBeInstanceOf(BaseError); + await expect(getDirectory(`${env.GIT_DIR}/${env.AVAIL_REPO}/something`)).rejects.toBeInstanceOf(BaseError); }); }); });
\ No newline at end of file diff --git a/test/unit/patch.unit.test.ts b/test/unit/patch.unit.test.ts index 3197059..d011825 100644 --- a/test/unit/patch.unit.test.ts +++ b/test/unit/patch.unit.test.ts @@ -10,7 +10,7 @@ describe("Patch", () => { it("Should get a patch from a diff", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "d856031c58e26992f3e0a481084a190a50b0bcf7"); const patch = await Patch.fromDiff(await commit.diff(), 1); @@ -22,7 +22,7 @@ describe("Patch", () => { it("Should get all patches from a diff", async() => { expect.hasAssertions(); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "7b3292af22a0496007e974b65cd2e34521c9c429"); const patches = await Patch.allFromDiff(await commit.diff()); @@ -42,7 +42,7 @@ describe("Patch", () => { let patch: Patch; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const commit = await Commit.lookup(repository, "7b3292af22a0496007e974b65cd2e34521c9c429"); patch = await Patch.fromDiff(await commit.diff(), 4); diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts index 66e32d4..b3d9a2d 100644 --- a/test/unit/repository.unit.test.ts +++ b/test/unit/repository.unit.test.ts @@ -9,7 +9,7 @@ import { BaseError } from "server/src/git/error"; const env = process.env as EnvironmentVariables; function expectRepositoryProperties(repository: Repository) { - expect(repository).toHaveProperty("base_dir"); + expect(repository).toHaveProperty("git_dir"); expect(repository).toHaveProperty("description"); expect(repository).toHaveProperty("name"); expect(repository).toHaveProperty("name.full"); @@ -22,7 +22,7 @@ describe("Repository", () => { it("Should open a repository", async() => { expect.assertions(8); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); expect(repository).toBeDefined(); expect(repository).toBeInstanceOf(Repository); @@ -33,19 +33,19 @@ describe("Repository", () => { it("Should fail to open a nonexistant repository", async() => { expect.assertions(1); - await expect(Repository.open(env.BASE_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError); + await expect(Repository.open(env.GIT_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError); }); it("Should fail to open a repository with a nonexistant branch", async() => { expect.assertions(1); - await expect(Repository.open(env.BASE_DIR, env.AVAIL_REPO, "wubbalubbadubdub")).rejects.toBeInstanceOf(BaseError); + await expect(Repository.open(env.GIT_DIR, env.AVAIL_REPO, "wubbalubbadubdub")).rejects.toBeInstanceOf(BaseError); }); it("Should open all repositories", async() => { expect.hasAssertions(); - const all_repositories = await Repository.openAll(env.BASE_DIR); + const all_repositories = await Repository.openAll(env.GIT_DIR); expect(all_repositories).toBeDefined(); @@ -62,7 +62,7 @@ describe("Repository", () => { let repository: Repository; beforeAll(async() => { - repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); }); it("Should get the description", async() => { diff --git a/test/unit/tag.unit.test.ts b/test/unit/tag.unit.test.ts index 8321092..76abc33 100644 --- a/test/unit/tag.unit.test.ts +++ b/test/unit/tag.unit.test.ts @@ -9,7 +9,7 @@ describe("Tag", () => { it("Should lookup a tag", async() => { expect.assertions(2); - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tag = await Tag.lookup(repository, "1.2"); @@ -22,7 +22,7 @@ describe("Tag", () => { let tag: Tag; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); tag = await Tag.lookup(repository, "1.2"); }); diff --git a/test/unit/tree.unit.test.ts b/test/unit/tree.unit.test.ts index 1cbc85a..1754e7a 100644 --- a/test/unit/tree.unit.test.ts +++ b/test/unit/tree.unit.test.ts @@ -12,7 +12,7 @@ describe("Tree", () => { it("Should get the tree of a repository", async() => { expect.assertions(2); - const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + const tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); expect(tree).toBeDefined(); expect(tree).toBeInstanceOf(Tree); @@ -23,7 +23,7 @@ describe("Tree", () => { let tree: Tree; beforeAll(async() => { - tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO)); + tree = await Tree.ofRepository(await Repository.open(env.GIT_DIR, env.AVAIL_REPO)); }); it("Should get the entries", () => { diff --git a/test/unit/tree_entry.unit.test.ts b/test/unit/tree_entry.unit.test.ts index de270c5..ca4fbc6 100644 --- a/test/unit/tree_entry.unit.test.ts +++ b/test/unit/tree_entry.unit.test.ts @@ -13,7 +13,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); tree_entry = tree.entries()[0]; }); @@ -63,7 +63,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); const entry = tree.entries().find(entry => entry.path === "test"); if(!entry) { @@ -91,7 +91,7 @@ describe("Tree entry", () => { let tree_entry: BaseTreeEntry; beforeAll(async() => { - const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO); const tree = await repository.tree(); tree_entry = tree.entries()[0]; }); @@ -108,4 +108,4 @@ describe("Tree entry", () => { }); }); }); -}); +});
\ No newline at end of file diff --git a/test/util.ts b/test/util.ts index 0079580..30a5c60 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1,7 +1,7 @@ import { Commit, CommitAuthor } from "server/src/git/commit"; export type EnvironmentVariables = { - BASE_DIR: string, + GIT_DIR: string, AVAIL_REPO: string, AVAIL_REPO_URL: string, UNAVAIL_REPO: string, |