Skip to content

Update Cloud Functions GCS hello world sample. #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions functions/helloworld/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions functions/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 20 additions & 1 deletion functions/helloworld/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
39 changes: 24 additions & 15 deletions functions/helloworld/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
source-map "^0.5.1"
split "^1.0.0"

"@google-cloud/[email protected].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/[email protected].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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected]beta.12:
version "2.0.0-beta.12"
resolved "https://registry.yarnpkg.com/pug/-/pug-2.0.0-beta.12.tgz#493037cbfbd97817ce0a4b3190f341cd556874bc"
[email protected]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"
Expand Down Expand Up @@ -3079,6 +3079,19 @@ [email protected]:
text-encoding "0.6.4"
type-detect "^4.0.0"

[email protected]:
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"
Expand Down Expand Up @@ -3519,14 +3532,10 @@ with@^5.0.0:
acorn "^3.1.0"
acorn-globals "^3.0.0"

[email protected]:
[email protected], 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"
Expand Down