|
1 | | -import { mkdir, mkdtemp, readdir, readFile, rm, stat } from 'node:fs/promises' |
| 1 | +import { mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises' |
2 | 2 | import { tmpdir } from 'node:os' |
3 | 3 | import path from 'node:path' |
4 | 4 |
|
@@ -257,12 +257,37 @@ describe('claimBackupDestination', () => { |
257 | 257 | } |
258 | 258 | }) |
259 | 259 |
|
260 | | - it('lets a non-permission failure through undisguised — an existing bundle is still EEXIST', async () => { |
| 260 | + it('refuses an occupied path with the remedy, not a bare errno (MEI-149)', async () => { |
261 | 261 | const dir = await mkdtemp(path.join(tmpdir(), 'meith-backup-test-')) |
262 | 262 | try { |
263 | 263 | const destination = path.join(dir, 'board.tar.gz') |
264 | 264 | await claimBackupDestination(destination) |
265 | | - await expect(claimBackupDestination(destination)).rejects.toMatchObject({ code: 'EEXIST' }) |
| 265 | + |
| 266 | + let caught: unknown |
| 267 | + try { |
| 268 | + await claimBackupDestination(destination) |
| 269 | + } catch (error) { |
| 270 | + caught = error |
| 271 | + } |
| 272 | + |
| 273 | + const message = (caught as Error).message |
| 274 | + expect(message).toContain(destination) |
| 275 | + expect(message).toContain('something is already there') |
| 276 | + expect(message).toContain('--out') |
| 277 | + expect(message).not.toContain('EEXIST') |
| 278 | + } finally { |
| 279 | + await rm(dir, { recursive: true, force: true }) |
| 280 | + } |
| 281 | + }) |
| 282 | + |
| 283 | + it("leaves the occupying file alone — refusing is not deleting somebody's bundle", async () => { |
| 284 | + const dir = await mkdtemp(path.join(tmpdir(), 'meith-backup-test-')) |
| 285 | + try { |
| 286 | + const destination = path.join(dir, 'board.tar.gz') |
| 287 | + await writeFile(destination, 'an earlier bundle') |
| 288 | + |
| 289 | + await expect(claimBackupDestination(destination)).rejects.toThrow() |
| 290 | + expect(await readFile(destination, 'utf8')).toBe('an earlier bundle') |
266 | 291 | } finally { |
267 | 292 | await rm(dir, { recursive: true, force: true }) |
268 | 293 | } |
|
0 commit comments