cli: basic-integrity test suite complete (ref. #66)

merge-requests/23/head
Michał 'rysiek' Woźniak 2022-12-13 23:43:42 +00:00
rodzic 78b37cb7f0
commit 1d8bcc0d39
2 zmienionych plików z 50 dodań i 2 usunięć

Wyświetl plik

@ -0,0 +1 @@
hello world

Wyświetl plik

@ -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')
});