mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
test(fs-safe): cover writeFileAtomic failure cleanup and default mode
This commit is contained in:
1 parent
bda123b6e1
commit
0b76b6d3c7
1 file changed
+12
-1
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, readdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import { mkdir, mkdtemp, readdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
@@ -86,6 +86,17 @@ describe('writeFileAtomic', () => {
|
||||
await writeFileAtomic(target, bytes)
|
||||
|
||||
expect(await readFile(target)).toEqual(bytes)
|
||||
expect((await stat(target)).mode & 0o777).toBe(0o600)
|
||||
await expect(readdir(workDir)).resolves.toEqual(['audio.mp3'])
|
||||
})
|
||||
|
||||
it('removes the temp file and rethrows when the rename fails', async () => {
|
||||
const target = path.join(workDir, 'target')
|
||||
await mkdir(target)
|
||||
await writeFile(path.join(target, 'blocker'), 'x')
|
||||
|
||||
await expect(writeFileAtomic(target, 'content')).rejects.toThrow()
|
||||
|
||||
await expect(readdir(workDir)).resolves.toEqual(['target'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user