From d815de814553a13bd146cdd85fcccc60b28224ac Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Thu, 31 Oct 2019 11:24:52 -0700 Subject: [PATCH] feat: moves library to TypeScript code generation (#10) --- .../listBuildTriggers.js | 2 +- .../package.json | 5 +- .../quickstart.js | 52 ++++++++++++------- .../system-test/samples.js | 19 ++----- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/generated,README.md,.eslintrc.yml/listBuildTriggers.js b/generated,README.md,.eslintrc.yml/listBuildTriggers.js index 60d967b870..9c1ba85e39 100644 --- a/generated,README.md,.eslintrc.yml/listBuildTriggers.js +++ b/generated,README.md,.eslintrc.yml/listBuildTriggers.js @@ -37,7 +37,7 @@ async function listBuildTriggers( }; const [result] = await cb.listBuildTriggers(request); - console.info(JSON.stringify(result.triggers, null, 2)); + console.info(JSON.stringify(result, null, 2)); } // [END cloudbuild_list_build_triggers] diff --git a/generated,README.md,.eslintrc.yml/package.json b/generated,README.md,.eslintrc.yml/package.json index e83a7b66ff..f595a78f01 100644 --- a/generated,README.md,.eslintrc.yml/package.json +++ b/generated,README.md,.eslintrc.yml/package.json @@ -12,13 +12,14 @@ "node": ">=8" }, "scripts": { - "test": "mocha system-test --timeout=800000" + "test": "c8 mocha system-test --timeout=800000" }, "dependencies": { "@google-cloud/cloudbuild": "^0.1.0" }, "devDependencies": { + "c8": "^6.0.1", "chai": "^4.2.0", "mocha": "^6.0.0" } -} \ No newline at end of file +} diff --git a/generated,README.md,.eslintrc.yml/quickstart.js b/generated,README.md,.eslintrc.yml/quickstart.js index cfd906973e..a844a63304 100644 --- a/generated,README.md,.eslintrc.yml/quickstart.js +++ b/generated,README.md,.eslintrc.yml/quickstart.js @@ -1,17 +1,17 @@ -/** - * Copyright 2019, 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 - * - * http://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. - */ +// Copyright 2019 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'; @@ -28,17 +28,33 @@ async function quickstart( const cb = new CloudBuildClient(); // Starts a build against the branch provided. - const request = { + const [resp] = await cb.runBuildTrigger({ projectId, triggerId, source: { - projectId: projectId, + projectId, dir: './', branchName, }, - }; - await cb.runBuildTrigger(request); + }); console.info(`triggered build for ${triggerId}`); + const [build] = await resp.promise(); + + const STATUS_LOOKUP = [ + 'UNKNOWN', + 'Queued', + 'Working', + 'Success', + 'Failure', + 'Error', + 'Timeout', + 'Cancelled', + ]; + for (const step of build.steps) { + console.info( + `step:\n\tname: ${step.name}\n\tstatus: ${STATUS_LOOKUP[build.status]}` + ); + } } // [END cloudbuild_quickstart] diff --git a/generated,README.md,.eslintrc.yml/system-test/samples.js b/generated,README.md,.eslintrc.yml/system-test/samples.js index c5f7d7e2c6..db2c6c5d15 100644 --- a/generated,README.md,.eslintrc.yml/system-test/samples.js +++ b/generated,README.md,.eslintrc.yml/system-test/samples.js @@ -30,28 +30,19 @@ const PROJECT_ID = process.env.GCLOUD_PROJECT; const TRIGGER_ID = process.env.TRIGGER || 'c9033094-51a9-44c5-b3a0-1d882deb4464'; -const {CloudBuildClient} = require('@google-cloud/cloudbuild'); -const cb = new CloudBuildClient(); - describe('Sample Integration Tests', () => { it('should run quickstart.js', async () => { - execSync( - `node ./samples/quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, + const stdout = execSync( + `node ./quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, {cwd} ); - // confirm that a build has just been kicked off. - const [builds] = await cb.listBuilds({ - projectId: PROJECT_ID, - }); - const createTime = builds[0].createTime.seconds * 1000; - const delta = Date.now() - createTime; - const maxDelta = 20000; // last build was within 20s. - assert.ok(delta < maxDelta, `delta ${delta} was > ${maxDelta}`); + // build should have exited with success status. + assert.include(stdout, 'status: Success'); }); it('should run list-build-triggers.js', async () => { const stdout = execSync( - `node ./samples/listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, + `node ./listBuildTriggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, {cwd} ); assert.include(stdout, 'Push-to-any-branch');