diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 345ab6db6e..dd0246f1be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,12 @@ jobs: entrypoint: sh args: ci/run-python-example.sh + - name: test-node-example + uses: docker://node:12-alpine + with: + entrypoint: sh + args: ci/run-node-example.sh + - name: test-go-example uses: docker://golang:1.14-alpine env: diff --git a/ci/run-go-example.sh b/ci/run-go-example.sh index 3f8a07a36a..745e6be859 100644 --- a/ci/run-go-example.sh +++ b/ci/run-go-example.sh @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +set -e + ./fake-gcs-server -backend memory -data $PWD/examples/data -public-host storage.gcs.127.0.0.1.nip.io:4443 & ( diff --git a/ci/run-node-example.sh b/ci/run-node-example.sh new file mode 100644 index 0000000000..6064df35f3 --- /dev/null +++ b/ci/run-node-example.sh @@ -0,0 +1,13 @@ +# Copyright 2019 Francisco Souza. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +set -e + +./fake-gcs-server -backend memory -data $PWD/examples/data & + +( + cd examples/node + npm ci + node index.js +) diff --git a/ci/run-python-example.sh b/ci/run-python-example.sh index 315ee2017a..983f8a83b7 100644 --- a/ci/run-python-example.sh +++ b/ci/run-python-example.sh @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +set -e + ./fake-gcs-server -backend memory -data $PWD/examples/data & pip install -r examples/python/requirements.txt diff --git a/examples/node/index.js b/examples/node/index.js index 70430e999b..0a9f494dc0 100644 --- a/examples/node/index.js +++ b/examples/node/index.js @@ -1,10 +1,9 @@ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; -process.on("unhandledRejection", err => {throw err}); async function listBuckets() { // [START storage_list_buckets] // Imports the Google Cloud client library - const {Storage} = require("@google-cloud/storage"); + const { Storage } = require("@google-cloud/storage"); // Creates a client const storage = new Storage({ @@ -15,10 +14,13 @@ async function listBuckets() { // Lists all buckets in the current project const [buckets] = await storage.getBuckets(); console.log("Buckets:"); - buckets.forEach(bucket => { + buckets.forEach((bucket) => { console.log(bucket.id); }); // [END storage_list_buckets] } -listBuckets().then(console.log); +listBuckets().catch((err) => { + console.error(err); + process.exit(1); +});