diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-29 15:54:04 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-29 15:59:52 +0200 |
commit | 9d6d2ce8cf34af6e787dae901ee3e5914c4c0fa4 (patch) | |
tree | 97f522340e954fe4ae6a0da2f8801351740cb990 /test/unit | |
parent | 8d42b6f44ca5b0eeb54938e1cf9509d1f8294f00 (diff) |
Added tests & API tests uses Axios
Added a unit test for creating a archive & added a int test for downloading a tag tarball
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/tree.unit.test.ts | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/test/unit/tree.unit.test.ts b/test/unit/tree.unit.test.ts index 47a716d..d34c93e 100644 --- a/test/unit/tree.unit.test.ts +++ b/test/unit/tree.unit.test.ts @@ -1,8 +1,9 @@ import { Repository } from "server/src/git/repository"; import { Tree } from "server/src/git/tree"; -import { TreeEntry } from "server/src/git/tree_entry"; +import { BaseTreeEntry, BlobTreeEntry, TreeEntry } from "server/src/git/tree_entry"; import { BaseError } from "server/src/git/error"; import { EnvironmentVariables } from "../util"; +import { extract, Headers } from "tar-stream"; const env = process.env as EnvironmentVariables; @@ -34,7 +35,7 @@ describe("Tree", () => { for(const entry of entries) { expect(entry).toBeDefined(); - expect(entry).toBeInstanceOf(TreeEntry); + expect(entry).toBeInstanceOf(BaseTreeEntry); } }); @@ -64,5 +65,60 @@ describe("Tree", () => { await expect(tree.findExists("packages/core/main.js")).resolves.toBeFalsy(); }); + + it("Should create an archive", async() => { + const archive = await tree.createArchive(); + + expect(archive).toBeDefined(); + + const extract_archive = extract(); + + archive.pipe(extract_archive); + + type Entry = { + header: Headers, + content: Buffer[] + }; + + // Extract the archive entries to an array of entries + const entries = await new Promise((resolve: (value: Entry[]) => void) => { + const entries = []; + + extract_archive.on("finish", () => { + resolve(entries); + }); + + extract_archive.on("entry", (header, stream, next) => { + const content: Buffer[] = []; + + stream.on("data", (chunk: Buffer) => { + content.push(chunk); + }); + + stream.on("end", async() => { + entries.push({ header, content }); + next(); + }); + + stream.resume(); + }); + }); + + expect(entries).toBeDefined(); + expect(entries.length).toBeGreaterThan(1); + + for(const entry of entries) { + expect(entry).toBeDefined(); + expect(entry.content).toBeDefined(); + + const content = entry.content.join().toString(); + + // Get the file content directly + const tree_entry = await tree.find(entry.header.name.split("/").slice(1).join("/")) as BlobTreeEntry; + const file_content = await (await tree_entry.blob()).content(); + + expect(content).toEqual(file_content); + } + }); }); });
\ No newline at end of file |