Skip to content

Commit

Permalink
feat: adds integration tests for Universe Domain configuration (#2538)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2024
1 parent 9e44593 commit 53db6ba
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .kokoro/continuous/node14/system-test.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .kokoro/presubmit/node14/system-test.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .kokoro/release/publish.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .kokoro/system-test.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,68 @@ describe('storage', function () {
});
});

describe('universeDomainTests', () => {
let universeDomainStorage: Storage;
const bucketName = generateName();
const localFile = fs.readFileSync(FILES.logo.path);
let file: File;

before(async () => {
const TEST_UNIVERSE_DOMAIN = isNullOrUndefined('TEST_UNIVERSE_DOMAIN');
const TEST_PROJECT_ID = isNullOrUndefined('TEST_UNIVERSE_PROJECT_ID');
const TEST_UNIVERSE_LOCATION = isNullOrUndefined(
'TEST_UNIVERSE_LOCATION'
);
const CREDENTIAL_PATH = isNullOrUndefined(
'TEST_UNIVERSE_DOMAIN_CREDENTIAL'
);
// Create a client with universe domain credentials
universeDomainStorage = new Storage({
projectId: TEST_PROJECT_ID,
keyFilename: CREDENTIAL_PATH,
universeDomain: TEST_UNIVERSE_DOMAIN,
});

const [bucket] = await universeDomainStorage.createBucket(bucketName, {
location: TEST_UNIVERSE_LOCATION,
});

file = bucket.file('LogoToSign.jpg');
fs.createReadStream(FILES.logo.path).pipe(file.createWriteStream());
});

after(async () => {
await deleteFileAsync(file);
await deleteBucketAsync(bucket);
});

it('should get bucket', async () => {
const [buckets] = await universeDomainStorage.getBuckets();
const getBucket = buckets.filter(item => item.name === bucketName);
assert.strictEqual(getBucket[0].name, bucketName);
});

it('should get files', async () => {
const fileName = await universeDomainStorage
.bucket(bucketName)
.file(file.name).name;
assert.strictEqual(fileName, file.name);
});

it('should create a signed read url', async () => {
const [signedReadUrl] = await file.getSignedUrl({
version: 'v2',
action: 'read',
expires: Date.now() + 5000,
virtualHostedStyle: true,
});

const res = await fetch(signedReadUrl);
const body = await res.text();
assert.strictEqual(body, localFile.toString());
});
});

async function deleteBucketAsync(bucket: Bucket, options?: {}) {
// After files are deleted, eventual consistency may require a bit of a
// delay to ensure that the bucket recognizes that the files don't exist
Expand Down Expand Up @@ -4015,4 +4077,12 @@ describe('storage', function () {
function createFileWithContentPromise(content: string) {
return bucket.file(`${generateName()}.txt`).save(content);
}

function isNullOrUndefined(envVarName: string) {
const value = process.env[envVarName];
if (value === undefined || value === null) {
throw new Error(`Please set the ${envVarName} environment variable.`);
}
return value;
}
});

0 comments on commit 53db6ba

Please sign in to comment.