1 files changed, 23 insertions, 0 deletions
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'
+ );
+});
|