diff --git a/__denotests__/mocks/hello.txt b/__denotests__/mocks/hello.txt new file mode 100644 index 0000000..95d09f2 --- /dev/null +++ b/__denotests__/mocks/hello.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/__denotests__/plugins/basic-integrity.test.js b/__denotests__/plugins/basic-integrity.test.js index ce81405..1893f70 100644 --- a/__denotests__/plugins/basic-integrity.test.js +++ b/__denotests__/plugins/basic-integrity.test.js @@ -1,4 +1,9 @@ -import { assert } from "https://deno.land/std@0.167.0/testing/asserts.ts"; +import { + assert, + assertThrows, + assertRejects, + assertEquals +} from "https://deno.land/std@0.167.0/testing/asserts.ts"; Deno.test("plugin load", async () => { const bi = await import('../../plugins/basic-integrity/cli.js') @@ -43,4 +48,46 @@ Deno.test("get-integrity action defaults", async () => { assert(gia.output.default == "json") }); -//TODO cont. +Deno.test("get-integrity verifies arguments are sane", async () => { + const bi = await import('../../plugins/basic-integrity/cli.js') + const gi = bi.actions["get-integrity"] + assertRejects(gi.run, Error, "Expected non-empty list of files to generate digests of.") + assertRejects(async ()=>{ + await gi.run(['no-such-file']) + }, Error, "No such file or directory") + assertRejects(async ()=>{ + await gi.run(['irrelevant'], []) + }, Error, "Expected non-empty list of algorithms to use.") + assertRejects(async ()=>{ + await gi.run(['irrelevant'], ['SHA-384'], false) + }, Error, "Expected either 'json' or 'text' as output type to generate.") +}); + +Deno.test("get-integrity handles paths in a sane way", async () => { + const bi = await import('../../plugins/basic-integrity/cli.js') + const gi = bi.actions["get-integrity"] + assertEquals(await gi.run(['./']), '{}') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt']), '{"./__denotests__/mocks/hello.txt":["sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="]}') + assertEquals(await gi.run(['./', './__denotests__/mocks/hello.txt']), '{"./__denotests__/mocks/hello.txt":["sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="]}') +}); + +Deno.test("get-integrity handles algos argument in a sane way", async () => { + const bi = await import('../../plugins/basic-integrity/cli.js') + const gi = bi.actions["get-integrity"] + assertRejects(async ()=>{ + await gi.run(['./__denotests__/mocks/hello.txt'], ['BAD-ALG']) + }, Error, 'Unrecognized algorithm name') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-256']), '{"./__denotests__/mocks/hello.txt":["sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="]}') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-384']), '{"./__denotests__/mocks/hello.txt":["sha384-/b2OdaZ/KfcBpOBAOF4uI5hjA+oQI5IRr5B/y7g1eLPkF8txzmRu/QgZ3YwIjeG9"]}') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-512']), '{"./__denotests__/mocks/hello.txt":["sha512-MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw=="]}') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-256', 'SHA-384', 'SHA-512']), '{"./__denotests__/mocks/hello.txt":["sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=","sha384-/b2OdaZ/KfcBpOBAOF4uI5hjA+oQI5IRr5B/y7g1eLPkF8txzmRu/QgZ3YwIjeG9","sha512-MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw=="]}') +}); + +Deno.test("get-integrity handles output argument in a sane way", async () => { + const bi = await import('../../plugins/basic-integrity/cli.js') + const gi = bi.actions["get-integrity"] + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-256'], 'text'), './__denotests__/mocks/hello.txt: sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=\n') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-384'], 'text'), './__denotests__/mocks/hello.txt: sha384-/b2OdaZ/KfcBpOBAOF4uI5hjA+oQI5IRr5B/y7g1eLPkF8txzmRu/QgZ3YwIjeG9\n') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-512'], 'text'), './__denotests__/mocks/hello.txt: sha512-MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw==\n') + assertEquals(await gi.run(['./__denotests__/mocks/hello.txt'], ['SHA-256', 'SHA-384', 'SHA-512'], 'text'), './__denotests__/mocks/hello.txt: sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek= sha384-/b2OdaZ/KfcBpOBAOF4uI5hjA+oQI5IRr5B/y7g1eLPkF8txzmRu/QgZ3YwIjeG9 sha512-MJ7MSJwS1utMxA9QyQLytNDtd+5RGnx6m808qG1M2G+YndNbxf9JlnDaNCVbRbDP2DDoH2Bdz33FVC6TrpzXbw==\n') +});