I am using the firebase emulator suite to test cloud functions that perform crud operations in cloud storage. I am using the Node.js admin SDKs for all cloud functions. See below for sample code that uploads a file into cloud storage.
exports.bucketTest = onCall(
async (request, response) => {
const testFile = 'TEST_FILE.txt';
const filePath = `../${testFile}`;
const destFileName = 'this/is/a/TEST_FILE.txt';
async function uploadFile() {
const options = {
destination: destFileName,
preconditionOpts: {ifGenerationMatch: 0}
};
await defaultBucket.upload(filePath, options);
console.log(`${filePath} uploaded to ${destFileName}`);
}
await uploadFile().catch(console.error);
}
);
The precondition seems to be ignored. I have it set to 0 which, as i understand it, should mean that the file should only be created if no file already exist. No matter what i set the precondition to, the upload always works even when that file already exist at the destination.
I asked a similar question on github under googles node.js for storage repo and it was confirmed that the above code works outside of the emulator.
Does anyone know if preconditions are suppose to work inside the firebase storage emulator and, if not, where this is documented?