Merge pull request #21375 from overleaf/jpa-if-none-match

[object-persistor] add support for ifNoneMatch=* in sendStream

GitOrigin-RevId: 268f054ac1b6452105b02757cdec32bad00702fd
This commit is contained in:
Jakob Ackermann
2024-11-01 09:05:11 +00:00
committed by Copybot
parent a551a0e9f7
commit 7b3e39f63f
8 changed files with 122 additions and 9 deletions
@@ -32,6 +32,10 @@ process.on('unhandledRejection', e => {
// store settings for multiple backends, so that we can test each one.
// fs will always be available - add others if they are configured
const { BackendSettings, s3Config } = require('./TestConfig')
const {
AlreadyWrittenError,
NotImplementedError,
} = require('@overleaf/object-persistor/src/Errors')
describe('Filestore', function () {
this.timeout(1000 * 10)
@@ -273,6 +277,40 @@ describe('Filestore', function () {
expect(body).to.equal(newContent)
})
describe('IfNoneMatch', function () {
if (backendSettings.backend === 'fs') {
it('should refuse to handle IfNoneMatch', async function () {
await expect(
app.persistor.sendStream(
Settings.filestore.stores.user_files,
`${projectId}/${fileId}`,
fs.createReadStream(localFileReadPath),
{ ifNoneMatch: '*' }
)
).to.be.rejectedWith(NotImplementedError)
})
} else {
it('should reject sendStream on the same key with IfNoneMatch', async function () {
await expect(
app.persistor.sendStream(
Settings.filestore.stores.user_files,
`${projectId}/${fileId}`,
fs.createReadStream(localFileReadPath),
{ ifNoneMatch: '*' }
)
).to.be.rejectedWith(AlreadyWrittenError)
})
it('should allow sendStream on a different key with IfNoneMatch', async function () {
await app.persistor.sendStream(
Settings.filestore.stores.user_files,
`${projectId}/${fileId}-other`,
fs.createReadStream(localFileReadPath),
{ ifNoneMatch: '*' }
)
})
}
})
if (backendSettings.backend !== 'fs') {
it('should record an egress metric for the upload', async function () {
const metric = await TestHelper.getMetric(