27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { test } from "node:test"
|
|
import { confirmWireguardImportRevision } from "./wireguard-import-revision.js"
|
|
import { captureAndAppendRevision } from "./config-revisions.js"
|
|
|
|
test("a new or unchanged revision confirms successful persistence", async () => {
|
|
for (const created of [true, false]) {
|
|
assert.equal(await confirmWireguardImportRevision(async () => ({ created, revision: { id: "existing-or-created" } })), true)
|
|
}
|
|
})
|
|
|
|
test("null and missing receipts do not confirm a revision", async () => {
|
|
for (const receipt of [null, undefined]) assert.equal(await confirmWireguardImportRevision(async () => receipt), false)
|
|
})
|
|
|
|
test("an exception does not confirm persistence", async () => {
|
|
assert.equal(await confirmWireguardImportRevision(async () => { throw new Error("Persistence unavailable") }), false)
|
|
})
|
|
|
|
test("real snapshot helper swallowing a capture error must fail revision confirmation", async () => {
|
|
let calls = 0
|
|
const capture = async () => { calls++; throw new Error("Snapshot unavailable") }
|
|
const receipt = () => captureAndAppendRevision({ serverId: 1, section: "wireguard", source: "copy", capture })
|
|
assert.equal(await confirmWireguardImportRevision(receipt), false)
|
|
assert.equal(calls, 1)
|
|
})
|