diff --git a/storagetransfer/package.json b/storagetransfer/package.json new file mode 100644 index 0000000000..c41b75b8b2 --- /dev/null +++ b/storagetransfer/package.json @@ -0,0 +1,22 @@ +{ + "name": "nodejs-storage-transfer", + "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/storage-transfer": "^0.1.0" + }, + "devDependencies": { + "c8": "^7.1.0", + "mocha": "^8.0.0" + } +} diff --git a/storagetransfer/quickstart.js b/storagetransfer/quickstart.js new file mode 100644 index 0000000000..b42bd8e0b1 --- /dev/null +++ b/storagetransfer/quickstart.js @@ -0,0 +1,54 @@ +// 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 main(projectId = 'my-project') { + // [START nodejs_storage_transfer_quickstart] + // Imports the Google Cloud client library + + // remove this line after package is released + const { + StorageTransferServiceClient, + } = require('@google-cloud/storage-transfer'); + + // TODO(developer): replace with your prefered project ID. + // const projectId = 'my-project' + + // Creates a client + const client = new StorageTransferServiceClient(); + + async function listTransferJobs() { + const iterable = client.listTransferJobsAsync({ + filter: JSON.stringify({ + projectId, + jobNames: ['transferJobs/*'], + }), + }); + for await (const response of iterable) { + // process response + console.info(response); + } + } + listTransferJobs(); + // [END nodejs_storage_transfer_quickstart] +} + +main(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/storagetransfer/test/quickstart.js b/storagetransfer/test/quickstart.js new file mode 100644 index 0000000000..667413decb --- /dev/null +++ b/storagetransfer/test/quickstart.js @@ -0,0 +1,44 @@ +// +// 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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +'use strict'; + +const path = require('path'); +const cp = require('child_process'); +const {before, describe, it} = require('mocha'); +const { + StorageTransferServiceClient, +} = require('@google-cloud/storage-transfer'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const cwd = path.join(__dirname, '..'); + +const client = new StorageTransferServiceClient(); + +describe('Quickstart', () => { + //TODO: remove this if not using the projectId + let projectId; + + before(async () => { + projectId = await client.getProjectId(); + }); + + it('should run quickstart', async () => { + execSync(`node ./quickstart.js ${projectId}`, {cwd}); + }); +});