diff --git a/functions/helloworld/index.js b/functions/helloworld/index.js index 978ab21a4d..e7dd86fff9 100644 --- a/functions/helloworld/index.js +++ b/functions/helloworld/index.js @@ -96,12 +96,15 @@ exports.helloPubSub = function (event, callback) { */ exports.helloGCS = function (event, callback) { const file = event.data; - const isDelete = file.resourceState === 'not_exists'; - if (isDelete) { + if (file.resourceState === 'not_exists') { console.log(`File ${file.name} deleted.`); - } else { + } else if (file.metageneration === 1) { + // metageneration attribute is updated on metadata changes. + // on create value is 1 console.log(`File ${file.name} uploaded.`); + } else { + console.log(`File ${file.name} metadata updated.`); } callback(); diff --git a/functions/helloworld/package.json b/functions/helloworld/package.json index c27e869b16..3208d423db 100644 --- a/functions/helloworld/package.json +++ b/functions/helloworld/package.json @@ -18,14 +18,14 @@ }, "dependencies": { "@google-cloud/debug-agent": "1.0.0", - "pug": "2.0.0-beta.12", + "pug": "2.0.0-rc.1", "safe-buffer": "5.0.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.7", + "@google-cloud/nodejs-repo-tools": "1.4.12", "ava": "0.19.1", "proxyquire": "1.7.11", - "sinon": "2.1.0" + "sinon": "2.2.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/helloworld/test/index.test.js b/functions/helloworld/test/index.test.js index 653913a56f..4812fb7928 100644 --- a/functions/helloworld/test/index.test.js +++ b/functions/helloworld/test/index.test.js @@ -142,7 +142,26 @@ test.serial(`helloGCS: should print uploaded message`, (t) => { program.helloGCS({ data: { name: `foo`, - resourceState: `exists` + resourceState: `exists`, + metageneration: 1 + } + }, callback); + + t.deepEqual(console.log.callCount, 1); + t.deepEqual(console.log.firstCall.args, [expectedMsg]); + t.deepEqual(callback.callCount, 1); + t.deepEqual(callback.firstCall.args, []); +}); + +test.serial(`helloGCS: should print metadata updated message`, (t) => { + const expectedMsg = `File foo metadata updated.`; + const callback = sinon.stub(); + + program.helloGCS({ + data: { + name: `foo`, + resourceState: `exists`, + metageneration: 2 } }, callback); diff --git a/functions/helloworld/yarn.lock b/functions/helloworld/yarn.lock index ce0c241944..8296512fa4 100644 --- a/functions/helloworld/yarn.lock +++ b/functions/helloworld/yarn.lock @@ -76,9 +76,9 @@ source-map "^0.5.1" split "^1.0.0" -"@google-cloud/nodejs-repo-tools@1.4.7": - version "1.4.7" - resolved "https://registry.yarnpkg.com/@google-cloud/nodejs-repo-tools/-/nodejs-repo-tools-1.4.7.tgz#1e3838af75386d99317f892ff1288e217a4a4b11" +"@google-cloud/nodejs-repo-tools@1.4.12": + version "1.4.12" + resolved "https://registry.yarnpkg.com/@google-cloud/nodejs-repo-tools/-/nodejs-repo-tools-1.4.12.tgz#41b9dc143daeb0e2714e884a7f56fd0730159735" dependencies: ava "0.19.1" colors "1.1.2" @@ -2728,9 +2728,9 @@ pug-lexer@^3.1.0: is-expression "^3.0.0" pug-error "^1.3.2" -pug-linker@^2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/pug-linker/-/pug-linker-2.0.3.tgz#b331ffa25737dde69c127b56c10ff17fae766dca" +pug-linker@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pug-linker/-/pug-linker-3.0.0.tgz#2416f06aaa1a9720e3b3261d1e8ca72f6f5123d2" dependencies: pug-error "^1.3.2" pug-walk "^1.1.2" @@ -2763,14 +2763,14 @@ pug-walk@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/pug-walk/-/pug-walk-1.1.2.tgz#debb24c070a95d5fc2aebf3589261833d2332e3b" -pug@2.0.0-beta.12: - version "2.0.0-beta.12" - resolved "https://registry.yarnpkg.com/pug/-/pug-2.0.0-beta.12.tgz#493037cbfbd97817ce0a4b3190f341cd556874bc" +pug@2.0.0-rc.1: + version "2.0.0-rc.1" + resolved "https://registry.yarnpkg.com/pug/-/pug-2.0.0-rc.1.tgz#723c08b3349bb9b96865b9ed7d3e379e247cd984" dependencies: pug-code-gen "^1.1.1" pug-filters "^2.1.2" pug-lexer "^3.1.0" - pug-linker "^2.0.3" + pug-linker "^3.0.0" pug-load "^2.0.6" pug-parser "^2.0.2" pug-runtime "^2.0.3" @@ -3079,6 +3079,19 @@ sinon@2.1.0: text-encoding "0.6.4" type-detect "^4.0.0" +sinon@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-2.2.0.tgz#3b1b42ff5defcbf51a52a62aca6d61171b9fd262" + dependencies: + diff "^3.1.0" + formatio "1.2.0" + lolex "^1.6.0" + native-promise-only "^0.8.1" + path-to-regexp "^1.7.0" + samsam "^1.1.3" + text-encoding "0.6.4" + type-detect "^4.0.0" + slash@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" @@ -3519,14 +3532,10 @@ with@^5.0.0: acorn "^3.1.0" acorn-globals "^3.0.0" -wordwrap@0.0.2: +wordwrap@0.0.2, wordwrap@~0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" -wordwrap@~0.0.2: - version "0.0.3" - resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" - wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"