Skip to content

Commit 53db6ba

Browse files
thiyaguk09gcf-owl-bot[bot]harsha-accenture
authored
feat: adds integration tests for Universe Domain configuration (#2538)
* feature added * fix * Added system test and sample test cases * copyright fix * build: fix path-to-regexp to older version due to node 14 requirement * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Remove unnecessary sample code * Manually modify README regards remove unnecessary sample code * added 'skipIfExists' option for downloadMany Node Transfer Manager: add support for 'skipIfExists' option for downloadMany * feat: adds integration tests for Universe Domain configuration * feat: adds integration tests for Universe Domain configuration with kokoro feat: adds integration tests for Universe Domain configuration with kokoro changes * remove only test lint fix * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix after hook error * added delete bucket * use existing deleteBucketAsync * Add environment variables validation * added kokoro changes * fix environment variables to correct path --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: harsha-accenture <harshavardhan.s.r@accenture.com>
1 parent 9e44593 commit 53db6ba

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

.kokoro/continuous/node14/system-test.cfg

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.kokoro/presubmit/node14/system-test.cfg

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.kokoro/release/publish.cfg

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.kokoro/system-test.sh

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-test/storage.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,6 +3866,68 @@ describe('storage', function () {
38663866
});
38673867
});
38683868

3869+
describe('universeDomainTests', () => {
3870+
let universeDomainStorage: Storage;
3871+
const bucketName = generateName();
3872+
const localFile = fs.readFileSync(FILES.logo.path);
3873+
let file: File;
3874+
3875+
before(async () => {
3876+
const TEST_UNIVERSE_DOMAIN = isNullOrUndefined('TEST_UNIVERSE_DOMAIN');
3877+
const TEST_PROJECT_ID = isNullOrUndefined('TEST_UNIVERSE_PROJECT_ID');
3878+
const TEST_UNIVERSE_LOCATION = isNullOrUndefined(
3879+
'TEST_UNIVERSE_LOCATION'
3880+
);
3881+
const CREDENTIAL_PATH = isNullOrUndefined(
3882+
'TEST_UNIVERSE_DOMAIN_CREDENTIAL'
3883+
);
3884+
// Create a client with universe domain credentials
3885+
universeDomainStorage = new Storage({
3886+
projectId: TEST_PROJECT_ID,
3887+
keyFilename: CREDENTIAL_PATH,
3888+
universeDomain: TEST_UNIVERSE_DOMAIN,
3889+
});
3890+
3891+
const [bucket] = await universeDomainStorage.createBucket(bucketName, {
3892+
location: TEST_UNIVERSE_LOCATION,
3893+
});
3894+
3895+
file = bucket.file('LogoToSign.jpg');
3896+
fs.createReadStream(FILES.logo.path).pipe(file.createWriteStream());
3897+
});
3898+
3899+
after(async () => {
3900+
await deleteFileAsync(file);
3901+
await deleteBucketAsync(bucket);
3902+
});
3903+
3904+
it('should get bucket', async () => {
3905+
const [buckets] = await universeDomainStorage.getBuckets();
3906+
const getBucket = buckets.filter(item => item.name === bucketName);
3907+
assert.strictEqual(getBucket[0].name, bucketName);
3908+
});
3909+
3910+
it('should get files', async () => {
3911+
const fileName = await universeDomainStorage
3912+
.bucket(bucketName)
3913+
.file(file.name).name;
3914+
assert.strictEqual(fileName, file.name);
3915+
});
3916+
3917+
it('should create a signed read url', async () => {
3918+
const [signedReadUrl] = await file.getSignedUrl({
3919+
version: 'v2',
3920+
action: 'read',
3921+
expires: Date.now() + 5000,
3922+
virtualHostedStyle: true,
3923+
});
3924+
3925+
const res = await fetch(signedReadUrl);
3926+
const body = await res.text();
3927+
assert.strictEqual(body, localFile.toString());
3928+
});
3929+
});
3930+
38693931
async function deleteBucketAsync(bucket: Bucket, options?: {}) {
38703932
// After files are deleted, eventual consistency may require a bit of a
38713933
// delay to ensure that the bucket recognizes that the files don't exist
@@ -4015,4 +4077,12 @@ describe('storage', function () {
40154077
function createFileWithContentPromise(content: string) {
40164078
return bucket.file(`${generateName()}.txt`).save(content);
40174079
}
4080+
4081+
function isNullOrUndefined(envVarName: string) {
4082+
const value = process.env[envVarName];
4083+
if (value === undefined || value === null) {
4084+
throw new Error(`Please set the ${envVarName} environment variable.`);
4085+
}
4086+
return value;
4087+
}
40184088
});

0 commit comments

Comments
 (0)