From 99220d73469210f94493ef92a9edc64ab50eb0d9 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 1 Jun 2025 01:03:40 +0200 Subject: Add some tests --- src/util/secretUtils.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/util/secretUtils.test.js (limited to 'src/util/secretUtils.test.js') diff --git a/src/util/secretUtils.test.js b/src/util/secretUtils.test.js new file mode 100644 index 0000000..d95d56f --- /dev/null +++ b/src/util/secretUtils.test.js @@ -0,0 +1,23 @@ +import { it } from 'node:test'; +import * as dotenv from 'dotenv'; +import { tmpdir } from 'node:os'; +import * as assert from 'node:assert'; +import { readSecret } from '#util/secretUtils.js'; +import { writeFile, mkdtemp } from 'node:fs/promises'; + +dotenv.config(); + +await it('Should fail on nonexistant secret', async () => { + const secretPath = (await mkdtemp(tmpdir())) + '/secret'; + await assert.rejects(readSecret('Nonexistant secret', secretPath)); +}); + +await it('Should read secret from file', async () => { + const secretPath = (await mkdtemp(tmpdir())) + '/secret'; + await writeFile(secretPath, 'testsecret'); + await assert.doesNotReject(readSecret('Test secret', secretPath)); + await assert.equal( + await readSecret('Test secret', secretPath), + 'testsecret' + ); +}); -- cgit 1.5.1