|
| 1 | +/** |
| 2 | + * Copyright 2019, Google, LLC. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +const path = require('path'); |
| 19 | +const {assert} = require('chai'); |
| 20 | +const cp = require('child_process'); |
| 21 | + |
| 22 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 23 | + |
| 24 | +const cwd = path.join(__dirname, '..'); |
| 25 | + |
| 26 | +const PROJECT_ID = process.env.GCLOUD_PROJECT; |
| 27 | +// Use list-build-triggers.js to figure out the ID of the trigger |
| 28 | +// you would like to execute. |
| 29 | +const TRIGGER_ID = |
| 30 | + process.env.TRIGGER || 'c9033094-51a9-44c5-b3a0-1d882deb4464'; |
| 31 | + |
| 32 | +const {CloudBuildClient} = require('@google-cloud/cloudbuild'); |
| 33 | +const cb = new CloudBuildClient(); |
| 34 | + |
| 35 | +describe('Sample Integration Tests', () => { |
| 36 | + it('should run quickstart.js', async () => { |
| 37 | + execSync( |
| 38 | + `node ./samples/quickstart.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, |
| 39 | + {cwd} |
| 40 | + ); |
| 41 | + // confirm that a build has just been kicked off. |
| 42 | + const [builds] = await cb.listBuilds({ |
| 43 | + projectId: PROJECT_ID, |
| 44 | + }); |
| 45 | + const createTime = builds[0].createTime.seconds * 1000; |
| 46 | + const delta = Date.now() - createTime; |
| 47 | + const maxDelta = 20000; // last build was within 20s. |
| 48 | + assert.ok(delta < maxDelta, `delta ${delta} was > ${maxDelta}`); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should run list-build-triggers.js', async () => { |
| 52 | + const stdout = execSync( |
| 53 | + `node ./samples/list-build-triggers.js ${PROJECT_ID} ${TRIGGER_ID} cloud-build-mvp`, |
| 54 | + {cwd} |
| 55 | + ); |
| 56 | + assert.include(stdout, 'Push-to-any-branch'); |
| 57 | + }); |
| 58 | +}); |
0 commit comments