Fix temp file leaks in dumpFolder on both success and error paths (#31304)
GitOrigin-RevId: b5d8586a86030fb887cbd7dadd9bbb7cd64a788c
This commit is contained in:
@@ -263,6 +263,7 @@ describe('RestoreManager', function () {
|
||||
|
||||
afterEach(function () {
|
||||
tk.reset()
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
describe('restoreFileFromV2', function () {
|
||||
@@ -349,6 +350,35 @@ describe('RestoreManager', function () {
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when addEntity throws an error', function () {
|
||||
beforeEach(function (ctx) {
|
||||
ctx.pathname = 'foo.tex'
|
||||
ctx.FileSystemImportManager.promises.addEntity = sinon
|
||||
.stub()
|
||||
.rejects(new Error('Failed to add entity'))
|
||||
ctx.fsUnlink = sinon.stub().resolves()
|
||||
vi.doMock('node:fs', () => ({
|
||||
default: { promises: { unlink: ctx.fsUnlink } },
|
||||
}))
|
||||
})
|
||||
|
||||
it('should clean up the temporary file and propagate the error', async function (ctx) {
|
||||
let error
|
||||
try {
|
||||
await ctx.RestoreManager.promises.restoreFileFromV2(
|
||||
ctx.user_id,
|
||||
ctx.project_id,
|
||||
ctx.version,
|
||||
ctx.pathname
|
||||
)
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
expect(error).to.exist
|
||||
expect(error.message).to.equal('Failed to add entity')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('_findOrCreateFolder', function () {
|
||||
|
||||
Reference in New Issue
Block a user