diff --git a/service-directory/snippets/package.json b/service-directory/snippets/package.json new file mode 100644 index 0000000000..50ec20c06d --- /dev/null +++ b/service-directory/snippets/package.json @@ -0,0 +1,23 @@ +{ + "name": "nodejs-service-directory", + "private": true, + "license": "Apache-2.0", + "author": "Google LLC", + "engines": { + "node": ">=10" + }, + "files": [ + "*.js" + ], + "scripts": { + "test": "c8 mocha --timeout 600000 test/*.js" + }, + "dependencies": { + "@google-cloud/service-directory": "^0.1.0" + }, + "devDependencies": { + "c8": "^5.0.1", + "chai": "^4.2.0", + "mocha": "^6.1.4" + } +} diff --git a/service-directory/snippets/quickstart.js b/service-directory/snippets/quickstart.js new file mode 100644 index 0000000000..a9506c7806 --- /dev/null +++ b/service-directory/snippets/quickstart.js @@ -0,0 +1,31 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +'use strict'; + +async function quickstart() { + // [START service_directory_quickstart] + // Imports the Google Cloud client library + const {LookupServiceClient} = require('@google-cloud/service-directory'); + + // Creates a client + const ls = new LookupServiceClient(); + + console.info(ls); + // [END service_directory_quickstart] +} + +const args = process.argv.slice(2); +quickstart(...args).catch(console.error); diff --git a/service-directory/snippets/test/quickstart.js b/service-directory/snippets/test/quickstart.js new file mode 100644 index 0000000000..db59b6c03f --- /dev/null +++ b/service-directory/snippets/test/quickstart.js @@ -0,0 +1,35 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +'use strict'; + +const path = require('path'); +const {assert} = require('chai'); +const cp = require('child_process'); +const {describe, it} = require('mocha'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const cwd = path.join(__dirname, '..'); + +describe('Sample Integration Tests', () => { + it('should run quickstart.js', async () => { + const stdout = execSync('node ./quickstart.js', { + cwd, + }); + // build should have exited with success status. + assert(stdout); + }); +});