Skip to content

Commit

Permalink
feat!: initial generation of nodejs-storage-transfer library (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 3, 2021
0 parents commit a58a5fa
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
22 changes: 22 additions & 0 deletions storagetransfer/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
54 changes: 54 additions & 0 deletions storagetransfer/quickstart.js
Original file line number Diff line number Diff line change
@@ -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;
});
44 changes: 44 additions & 0 deletions storagetransfer/test/quickstart.js
Original file line number Diff line number Diff line change
@@ -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});
});
});

0 comments on commit a58a5fa

Please sign in to comment.