Skip to content

Commit

Permalink
feat: add functionality for passing preconditions at the function lev…
Browse files Browse the repository at this point in the history
…el (#1993)

* test: updated conformance tests for precondition updates

* fixed typo

* updated functions to pass preconditions

* removed IAM and HMAC test changes

* implemented local preconditions for bucketmakeprivate

* added preconditions to enableLogging

* linted files

* implemented more preconditions

* general cleanup

* implemented precondition on combine

* added preconditions for copy and move

* rename

* removed tests for instance precondition where instance precondition is not supported

* support preconditions for rotateencryptionkey

* support set storage class

* linted files

* fixed tests

* deleteLabels and setLabels

* more precondition implementations

* minor progress

* fix(refactor): Simplify logic around disabling autoretry for setmetadata

* setcorsconfiguration

* set retention period

* bucketSetStorageClass

* fileMakePrivate

* file set metadata

* bucket set metadata

* file delete

* more precondition updates

* precondition refactor

* removed log statement

* change delete labels signature

* fix delete labels

* fixed save multipart

* put docker code back

* linted files

* docs and cleanup

* refactored conformance tests

* remove iam test from being in the conformance tests

* linted files

* put docker commands back

* fixed combine retries

* added comments

* fix: implement setMetadata in HmacKey and fix associated tests (#2009)

* fix: implement setMetadata in HmacKey and fix associated tests

* fix merge problem, check idempotency strategy

* retry based on idempotency strategy

* linted file

* Revert "retry based on idempotency strategy"

This reverts commit 80909b5.

* don't retry acl adds

* changed HEAD request to GET request

* fix(refactor): Add a call from file.delete to the parent class delete (#2014)

* fix(refactor): Add a call from file.delete to the parent class delete

* add delete to checked methods for conditionally idempotent file ops

* fix: fix noResponseRetries so it respects reqOpts.maxRetries (#2015)

* fix: fix noResponseRetries so it respects reqOpts.maxRetries

* fix situation where err.code is actually a string during connection resets

* log error type

* removed passing functions

* restored retryInvocationMap

* added instance precondition back to insert

* restored scenario 2

* restored all scenarios

* linted files

* Revert "linted files"

This reverts commit d2cb27b.

* removed logs

Co-authored-by: Sameena Shaffeeullah <shaffeeullah@google.com>

* fix: pass appropriate preconditions from enableLogging to setMetadata (#2018)

* tests: remove callback waterfall from make bucket private system test (#2020)

* tests: remove callback waterfall from make bucket private system test

* cleaner implementation

* moved done()

* removed precondition from policyoptions

* added retries for setPolicy

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* removed unused import

Co-authored-by: Denis DelGrosso <ddelgrosso@google.com>
Co-authored-by: Denis DelGrosso <85250797+ddelgrosso1@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 10, 2022
1 parent 020c0eb commit 21f173e
Show file tree
Hide file tree
Showing 17 changed files with 1,646 additions and 1,069 deletions.
74 changes: 39 additions & 35 deletions conformance-test/conformanceCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,29 @@ export function executeScenario(testCase: RetryTestCase) {
instructionSet.instructions,
jsonMethod?.name.toString()
);
bucket = await createBucketForTest(
storage,
testCase.preconditionProvided,
storageMethodString
);
file = await createFileForTest(
testCase.preconditionProvided,
storageMethodString,
bucket
);
if (storageMethodString.includes('InstancePrecondition')) {
bucket = await createBucketForTest(
storage,
testCase.preconditionProvided,
storageMethodString
);
file = await createFileForTest(
testCase.preconditionProvided,
storageMethodString,
bucket
);
} else {
bucket = await createBucketForTest(
storage,
false,
storageMethodString
);
file = await createFileForTest(
false,
storageMethodString,
bucket
);
}
notification = bucket.notification(`${TESTS_PREFIX}`);
await notification.create();

Expand All @@ -121,29 +134,20 @@ export function executeScenario(testCase: RetryTestCase) {
});

it(`${instructionNumber}`, async () => {
const methodParameters: libraryMethods.ConformanceTestOptions = {
bucket: bucket,
file: file,
notification: notification,
storage: storage,
hmacKey: hmacKey,
};
if (testCase.preconditionProvided) {
methodParameters.preconditionRequired = true;
}
if (testCase.expectSuccess) {
assert.ifError(
await storageMethodObject(
bucket,
file,
notification,
storage,
hmacKey
)
);
assert.ifError(await storageMethodObject(methodParameters));
} else {
try {
await storageMethodObject(
bucket,
file,
notification,
storage,
hmacKey
);
throw Error(`${storageMethodString} was supposed to throw.`);
} catch (e) {
assert.notStrictEqual(e, undefined);
}
await assert.rejects(storageMethodObject(methodParameters));
}
const testBenchResult = await getTestBenchRetryTest(
creationResult.id
Expand All @@ -158,15 +162,15 @@ export function executeScenario(testCase: RetryTestCase) {

async function createBucketForTest(
storage: Storage,
preconditionProvided: boolean,
preconditionShouldBeOnInstance: boolean,
storageMethodString: String
) {
const name = generateName(storageMethodString, 'bucket');
const bucket = storage.bucket(name);
await bucket.create();
await bucket.setRetentionPeriod(DURATION_SECONDS);

if (preconditionProvided) {
if (preconditionShouldBeOnInstance) {
return new Bucket(storage, bucket.name, {
preconditionOpts: {
ifMetagenerationMatch: 2,
Expand All @@ -177,14 +181,14 @@ async function createBucketForTest(
}

async function createFileForTest(
preconditionProvided: boolean,
preconditionShouldBeOnInstance: boolean,
storageMethodString: String,
bucket: Bucket
) {
const name = generateName(storageMethodString, 'file');
const file = bucket.file(name);
await file.save(name);
if (preconditionProvided) {
if (preconditionShouldBeOnInstance) {
return new File(bucket, file.name, {
preconditionOpts: {
ifMetagenerationMatch: file.metadata.metageneration,
Expand Down
Loading

0 comments on commit 21f173e

Please sign in to comment.