From 535e2c3d83733416591c0c2c17828d20d850dbee Mon Sep 17 00:00:00 2001 From: Max Braun Date: Sun, 11 Jun 2017 12:56:18 -0700 Subject: [PATCH 1/2] Fix uploaded/updated logic for Cloud Storage. The metageneration attribute seems to be a string and not a number. The strict comparison with 1 in the if/else inverted the logic that separated file uploads from metadata updates. --- functions/helloworld/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index e7dd86fff9..f28776148e 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -99,7 +99,7 @@ exports.helloGCS = function (event, callback) { if (file.resourceState === 'not_exists') { console.log(`File ${file.name} deleted.`); - } else if (file.metageneration === 1) { + } else if (file.metageneration === '1') { // metageneration attribute is updated on metadata changes. // on create value is 1 console.log(`File ${file.name} uploaded.`); From b2449f4720bc5fe46eedee88ce4fd2e8cd836364 Mon Sep 17 00:00:00 2001 From: Max Braun Date: Fri, 16 Jun 2017 14:58:46 -0700 Subject: [PATCH 2/2] Change metageneration attribute type to string in tests Cloud Function invocations are receiving strings instead of numbers. --- functions/helloworld/test/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/helloworld/test/index.test.js b/functions/helloworld/test/index.test.js index 4812fb7928..66d0bf96ff 100644 --- a/functions/helloworld/test/index.test.js +++ b/functions/helloworld/test/index.test.js @@ -143,7 +143,7 @@ test.serial(`helloGCS: should print uploaded message`, (t) => { data: { name: `foo`, resourceState: `exists`, - metageneration: 1 + metageneration: `1` } }, callback); @@ -161,7 +161,7 @@ test.serial(`helloGCS: should print metadata updated message`, (t) => { data: { name: `foo`, resourceState: `exists`, - metageneration: 2 + metageneration: `2` } }, callback);