Skip to content

Commit 21f173e

Browse files
shaffeeullahddelgrosso1gcf-owl-bot[bot]
authored
feat: add functionality for passing preconditions at the function level (#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 <[email protected]> * 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 <[email protected]> Co-authored-by: Denis DelGrosso <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 020c0eb commit 21f173e

17 files changed

+1646
-1069
lines changed

conformance-test/conformanceCommon.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,29 @@ export function executeScenario(testCase: RetryTestCase) {
9292
instructionSet.instructions,
9393
jsonMethod?.name.toString()
9494
);
95-
bucket = await createBucketForTest(
96-
storage,
97-
testCase.preconditionProvided,
98-
storageMethodString
99-
);
100-
file = await createFileForTest(
101-
testCase.preconditionProvided,
102-
storageMethodString,
103-
bucket
104-
);
95+
if (storageMethodString.includes('InstancePrecondition')) {
96+
bucket = await createBucketForTest(
97+
storage,
98+
testCase.preconditionProvided,
99+
storageMethodString
100+
);
101+
file = await createFileForTest(
102+
testCase.preconditionProvided,
103+
storageMethodString,
104+
bucket
105+
);
106+
} else {
107+
bucket = await createBucketForTest(
108+
storage,
109+
false,
110+
storageMethodString
111+
);
112+
file = await createFileForTest(
113+
false,
114+
storageMethodString,
115+
bucket
116+
);
117+
}
105118
notification = bucket.notification(`${TESTS_PREFIX}`);
106119
await notification.create();
107120

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

123136
it(`${instructionNumber}`, async () => {
137+
const methodParameters: libraryMethods.ConformanceTestOptions = {
138+
bucket: bucket,
139+
file: file,
140+
notification: notification,
141+
storage: storage,
142+
hmacKey: hmacKey,
143+
};
144+
if (testCase.preconditionProvided) {
145+
methodParameters.preconditionRequired = true;
146+
}
124147
if (testCase.expectSuccess) {
125-
assert.ifError(
126-
await storageMethodObject(
127-
bucket,
128-
file,
129-
notification,
130-
storage,
131-
hmacKey
132-
)
133-
);
148+
assert.ifError(await storageMethodObject(methodParameters));
134149
} else {
135-
try {
136-
await storageMethodObject(
137-
bucket,
138-
file,
139-
notification,
140-
storage,
141-
hmacKey
142-
);
143-
throw Error(`${storageMethodString} was supposed to throw.`);
144-
} catch (e) {
145-
assert.notStrictEqual(e, undefined);
146-
}
150+
await assert.rejects(storageMethodObject(methodParameters));
147151
}
148152
const testBenchResult = await getTestBenchRetryTest(
149153
creationResult.id
@@ -158,15 +162,15 @@ export function executeScenario(testCase: RetryTestCase) {
158162

159163
async function createBucketForTest(
160164
storage: Storage,
161-
preconditionProvided: boolean,
165+
preconditionShouldBeOnInstance: boolean,
162166
storageMethodString: String
163167
) {
164168
const name = generateName(storageMethodString, 'bucket');
165169
const bucket = storage.bucket(name);
166170
await bucket.create();
167171
await bucket.setRetentionPeriod(DURATION_SECONDS);
168172

169-
if (preconditionProvided) {
173+
if (preconditionShouldBeOnInstance) {
170174
return new Bucket(storage, bucket.name, {
171175
preconditionOpts: {
172176
ifMetagenerationMatch: 2,
@@ -177,14 +181,14 @@ async function createBucketForTest(
177181
}
178182

179183
async function createFileForTest(
180-
preconditionProvided: boolean,
184+
preconditionShouldBeOnInstance: boolean,
181185
storageMethodString: String,
182186
bucket: Bucket
183187
) {
184188
const name = generateName(storageMethodString, 'file');
185189
const file = bucket.file(name);
186190
await file.save(name);
187-
if (preconditionProvided) {
191+
if (preconditionShouldBeOnInstance) {
188192
return new File(bucket, file.name, {
189193
preconditionOpts: {
190194
ifMetagenerationMatch: file.metadata.metageneration,

0 commit comments

Comments
 (0)