|
15 | 15 | 'use strict';
|
16 | 16 |
|
17 | 17 | const {assert} = require('chai');
|
18 |
| -const cp = require('child_process'); |
| 18 | +const {execSync} = require('child_process'); |
19 | 19 | const uuid = require('uuid');
|
| 20 | +const {CloudTasksClient} = require('@google-cloud/tasks'); |
20 | 21 |
|
21 |
| -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
22 |
| - |
23 |
| -const PROJECT_ID = process.env.GCLOUD_PROJECT; |
| 22 | +const exec = cmd => execSync(cmd, {encoding: 'utf-8'}); |
24 | 23 | const queueName = `gcloud-${uuid.v4().split('-')[0]}`;
|
25 |
| -const URL = `https://${PROJECT_ID}.appspot.com/log_payload`; |
26 | 24 | const SERVICE_ACCOUNT =
|
27 | 25 |
|
28 | 26 |
|
29 | 27 | describe('Cloud Task Sample Tests', () => {
|
| 28 | + let url; |
| 29 | + let projectId; |
| 30 | + |
| 31 | + before(async () => { |
| 32 | + const client = new CloudTasksClient(); |
| 33 | + projectId = await client.getProjectId(); |
| 34 | + url = `https://${projectId}.appspot.com/log_payload`; |
| 35 | + }); |
| 36 | + |
30 | 37 | it('should create a queue', () => {
|
31 |
| - const stdout = execSync(`node createQueue ${PROJECT_ID} ${queueName}`); |
| 38 | + const stdout = exec(`node createQueue ${projectId} ${queueName}`); |
32 | 39 | assert.match(stdout, /Created queue/);
|
33 | 40 | });
|
34 | 41 |
|
35 | 42 | it('should create a task', () => {
|
36 |
| - const stdout = execSync( |
37 |
| - `node createTask ${PROJECT_ID} us-central1 ${queueName}` |
| 43 | + const stdout = exec( |
| 44 | + `node createTask ${projectId} us-central1 ${queueName}` |
38 | 45 | );
|
39 | 46 | assert.match(stdout, /Created task/);
|
40 | 47 | });
|
41 | 48 |
|
42 | 49 | it('quickstart sample should create a task', () => {
|
43 |
| - const stdout = execSync( |
44 |
| - `node quickstart ${PROJECT_ID} us-central1 ${queueName}` |
| 50 | + const stdout = exec( |
| 51 | + `node quickstart ${projectId} us-central1 ${queueName}` |
45 | 52 | );
|
46 | 53 | assert.match(stdout, /Created task/);
|
47 | 54 | });
|
48 | 55 |
|
49 | 56 | it('should create a HTTP task', () => {
|
50 |
| - const stdout = execSync( |
51 |
| - `node createHttpTask ${PROJECT_ID} us-central1 my-appengine-queue ${URL}` |
| 57 | + const stdout = exec( |
| 58 | + `node createHttpTask ${projectId} us-central1 my-appengine-queue ${url}` |
52 | 59 | );
|
53 | 60 | assert.match(stdout, /Created task/);
|
54 | 61 | });
|
55 | 62 |
|
56 | 63 | it('should create a HTTP task with token', () => {
|
57 |
| - const stdout = execSync( |
58 |
| - `node createHttpTaskWithToken ${PROJECT_ID} us-central1 my-appengine-queue ${URL} ${SERVICE_ACCOUNT}` |
| 64 | + const stdout = exec( |
| 65 | + `node createHttpTaskWithToken ${projectId} us-central1 my-appengine-queue ${url} ${SERVICE_ACCOUNT}` |
59 | 66 | );
|
60 | 67 | assert.match(stdout, /Created task/);
|
61 | 68 | });
|
62 | 69 |
|
63 | 70 | it('should delete a queue', () => {
|
64 |
| - const stdout = execSync(`node deleteQueue ${PROJECT_ID} ${queueName}`); |
| 71 | + const stdout = exec(`node deleteQueue ${projectId} ${queueName}`); |
65 | 72 | assert.match(stdout, /Deleted queue/);
|
66 | 73 | });
|
67 | 74 | });
|
0 commit comments