Skip to content

Commit fbfad3d

Browse files
committed
added test case
1 parent 6835410 commit fbfad3d

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

storagebatchoperations/listJobs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function main(projectId) {
4747

4848
// Run request
4949
const [response] = await client.listJobs(request);
50-
for (const jobs of response) {
51-
console.log(jobs.name);
50+
for (const job of response) {
51+
console.log(job.name);
5252
}
5353
}
5454

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2025 Google LLC
2+
//
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+
// https://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+
const {Storage, Bucket} = require('@google-cloud/storage');
16+
const cp = require('child_process');
17+
const {assert} = require('chai');
18+
const {describe, it, before, after} = require('mocha');
19+
const uuid = require('uuid');
20+
21+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
22+
const projectId = process.env.GCLOUD_PROJECT;
23+
const bucketPrefix = 'sbo-samples';
24+
const bucketName = `${bucketPrefix}-${uuid.v4()}`;
25+
const storage = new Storage();
26+
const bucket = new Bucket(storage, bucketName);
27+
const jobId = uuid.v4();
28+
const jobName = `projects/${projectId}/locations/global/jobs/${jobId}`;
29+
30+
describe('Batch Operations', () => {
31+
before(async () => {
32+
await storage.createBucket(bucketName, {
33+
iamConfiguration: {
34+
uniformBucketLevelAccess: {
35+
enabled: true,
36+
},
37+
},
38+
hierarchicalNamespace: {enabled: true},
39+
});
40+
});
41+
42+
after(async () => {
43+
await bucket.delete();
44+
});
45+
46+
it('should create a job', async () => {
47+
const output = execSync(
48+
`node createJob.js ${projectId} ${jobId} ${bucketName} objectPrefix`
49+
);
50+
assert.match(output, /Created job:/);
51+
assert.match(output, new RegExp(jobName));
52+
});
53+
54+
it('should list jobs', async () => {
55+
const output = execSync(`node listJobs.js ${projectId}`);
56+
assert.match(output, new RegExp(jobName));
57+
});
58+
59+
it('should run quickstart', async () => {
60+
const output = execSync(`node quickstart.js ${projectId} ${jobId}`);
61+
assert.match(output, /Got job:/);
62+
assert.match(output, new RegExp(jobName));
63+
});
64+
65+
it('should get a job', async () => {
66+
const output = execSync(`node getJob.js ${projectId} ${jobId}`);
67+
assert.match(output, /Got job:/);
68+
assert.match(output, new RegExp(jobName));
69+
});
70+
71+
it('should cancel a job', async () => {
72+
try {
73+
const output = execSync(`node cancelJob.js ${projectId} ${jobId}`);
74+
assert.match(output, /Cancelled job:/);
75+
assert.match(output, new RegExp(jobName));
76+
} catch (error) {
77+
// This might be expected if the job completed quickly or failed creation
78+
assert.match(error.message, /INFO: cancelJob threw: /);
79+
}
80+
});
81+
82+
it('should delete a job', async () => {
83+
const output = execSync(`node deleteJob.js ${projectId} ${jobId}`);
84+
assert.match(output, /Deleted job:/);
85+
assert.match(output, new RegExp(jobName));
86+
});
87+
});

0 commit comments

Comments
 (0)