Skip to content

Commit

Permalink
sample: Add quickstart sample code for BatchGetAsstesHistory. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-zheng-g authored and Ace Nassri committed Nov 17, 2022
1 parent dd0c739 commit 2836bd2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions asset/snippets/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
const assert = require('assert');
const path = require('path');
const tools = require('@google-cloud/nodejs-repo-tools');
const util = require('util');
const uuid = require('uuid');
const cwd = path.join(__dirname, '..');
const cmd = 'node quickstart.js';
Expand All @@ -29,20 +28,33 @@ const storage = new Storage();
const bucketName = `asset-nodejs-${uuid.v4()}`;
const bucket = storage.bucket(bucketName);

describe('Quickstart sample tests', () => {
describe('quickstart sample tests', () => {
before(tools.checkCredentials);
before(async () => {
tools.checkCredentials();
await bucket.create();
});

after(async () => await bucket.delete());
after(async () => {
await bucket.delete();
});

it('should export assets to specified path', async () => {
const dumpFilePath = util.format('gs://%s/my-assets.txt', bucketName);
const dumpFilePath = `gs://${bucketName}/my-assets.txt`;
await tools.runAsyncWithIO(`${cmd} export-assets ${dumpFilePath}`, cwd);
const file = await bucket.file('my-assets.txt');
const [exists] = await file.exists();
const exists = await file.exists();
assert.ok(exists);
await file.delete();
});

it('should get assets history successfully', async () => {
const assetName = `//storage.googleapis.com/${bucketName}`;
const output = await tools.runAsyncWithIO(
`${cmd} batch-get-history ${assetName}`,
cwd
);
if (output.stdout) {
assert.ok(output.stdout.includes(assetName));
}
});
});

0 comments on commit 2836bd2

Please sign in to comment.