Skip to content

Commit 15c1a75

Browse files
committed
fix all scenario
1 parent fbb093c commit 15c1a75

11 files changed

Lines changed: 267 additions & 131 deletions

File tree

handwritten/storage/conformance-test/conformanceCommon.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,30 +201,17 @@ export function executeScenario(testCase: RetryTestCase) {
201201
},
202202
});
203203

204-
if (storageMethodString.includes('InstancePrecondition')) {
205-
bucket = await createBucketForTest(
206-
storage,
207-
testCase.preconditionProvided &&
208-
!storageMethodString.includes('combine'),
209-
storageMethodString,
210-
);
211-
file = await createFileForTest(
212-
testCase.preconditionProvided,
213-
storageMethodString,
214-
bucket,
215-
);
216-
} else {
217-
bucket = await createBucketForTest(
218-
storage,
219-
false,
220-
storageMethodString,
221-
);
222-
file = await createFileForTest(
223-
false,
224-
storageMethodString,
225-
bucket,
226-
);
227-
}
204+
bucket = await createBucketForTest(
205+
storage,
206+
testCase.preconditionProvided &&
207+
!storageMethodString.includes('combine'),
208+
storageMethodString,
209+
);
210+
file = await createFileForTest(
211+
testCase.preconditionProvided,
212+
storageMethodString,
213+
bucket,
214+
);
228215
notification = bucket.notification(TESTS_PREFIX);
229216
await notification.create();
230217

@@ -242,10 +229,8 @@ export function executeScenario(testCase: RetryTestCase) {
242229
notification: notification,
243230
hmacKey: hmacKey,
244231
projectId: CONF_TEST_PROJECT_ID,
232+
preconditionRequired: testCase.preconditionProvided,
245233
};
246-
if (testCase.preconditionProvided) {
247-
methodParameters.preconditionRequired = true;
248-
}
249234

250235
if (testCase.expectSuccess) {
251236
await storageMethodObject(methodParameters);
@@ -295,6 +280,7 @@ async function createFileForTest(
295280
const file = bucket.file(name);
296281
await file.save(name);
297282
if (preconditionShouldBeOnInstance) {
283+
await file.getMetadata();
298284
return new File(bucket, file.name, {
299285
preconditionOpts: {
300286
ifMetagenerationMatch: file.metadata.metageneration,

handwritten/storage/conformance-test/libraryMethods.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,21 @@ export async function bucketUploadResumable(options: ConformanceTestOptions) {
590590
// eslint-disable-next-line @typescript-eslint/no-explicit-any
591591
const response: any =
592592
await options.storageTransport!.makeRequest(initiateOptions);
593-
const sessionUri = response.headers?.location || response.headers?.Location;
593+
594+
let sessionUri: string | null = null;
595+
596+
if (response.headers) {
597+
if (typeof response.headers.get === 'function') {
598+
sessionUri = response.headers.get('location');
599+
}
600+
if (!sessionUri) {
601+
sessionUri = response.headers.location || response.headers.Location;
602+
}
603+
}
604+
605+
if (!sessionUri && response.data && typeof response.data === 'object') {
606+
sessionUri = response.data.location;
607+
}
594608

595609
if (!sessionUri) {
596610
throw new Error(
@@ -828,16 +842,23 @@ export async function fileMakePrivateInstancePrecondition(
828842
}
829843

830844
export async function fileMakePrivate(options: ConformanceTestOptions) {
845+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
846+
const retryId = (options as any).headers?.['x-retry-test-id'];
847+
831848
const requestOptions: StorageRequestOptions = {
832849
method: 'PATCH',
833850
url: `storage/v1/b/${encodeURIComponent(options.bucket!.name)}/o/${encodeURIComponent(options.file!.name)}`,
834851
body: JSON.stringify({acl: []}),
835852
queryParameters: {},
853+
headers: {
854+
'Content-Type': 'application/json',
855+
...(retryId ? {'x-retry-test-id': retryId} : {}),
856+
},
836857
};
837858

838859
if (options.preconditionRequired) {
839860
requestOptions.queryParameters!.ifMetagenerationMatch =
840-
options.file!.metadata.metageneration;
861+
options.file!.metadata.metageneration ?? 1;
841862
}
842863

843864
return await options.storageTransport!.makeRequest(requestOptions);
@@ -949,14 +970,27 @@ export async function saveResumable(options: ConformanceTestOptions) {
949970
// eslint-disable-next-line @typescript-eslint/no-explicit-any
950971
const response: any =
951972
await options.storageTransport!.makeRequest(initiateOptions);
952-
const sessionUri = response.headers?.location || response.location;
973+
let sessionUri: string | null = null;
974+
if (response.headers) {
975+
if (typeof response.headers.get === 'function') {
976+
sessionUri = response.headers.get('location');
977+
}
978+
if (!sessionUri) {
979+
sessionUri = response.headers.location || response.headers.Location;
980+
}
981+
}
982+
983+
if (!sessionUri && response.data && typeof response.data === 'object') {
984+
sessionUri = response.data.location;
985+
}
953986

954987
if (!sessionUri) throw new Error('Failed to get session URI');
955988

956989
return await options.storageTransport!.makeRequest({
957990
method: 'PUT',
958991
url: sessionUri,
959992
body: dataBuffer,
993+
queryParameters: undefined,
960994
headers: {
961995
'Content-Type': 'application/octet-stream',
962996
'Content-Length': dataBuffer.length.toString(),
@@ -1152,6 +1186,8 @@ export async function iamGetPolicy(options: ConformanceTestOptions) {
11521186
}
11531187

11541188
export async function iamSetPolicy(options: ConformanceTestOptions) {
1189+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1190+
const retryId = (options as any).headers?.['x-retry-test-id'];
11551191
const body: Policy = {
11561192
bindings: [
11571193
{
@@ -1166,6 +1202,7 @@ export async function iamSetPolicy(options: ConformanceTestOptions) {
11661202
method: 'GET',
11671203
url: `storage/v1/b/${encodeURIComponent(options.bucket!.name)}/iam`,
11681204
queryParameters: {optionsRequestedPolicyVersion: 1},
1205+
headers: retryId ? {'x-retry-test-id': retryId} : {},
11691206
});
11701207

11711208
const currentPolicy = getResponse as Policy;
@@ -1180,7 +1217,10 @@ export async function iamSetPolicy(options: ConformanceTestOptions) {
11801217
method: 'PUT',
11811218
url: `storage/v1/b/${encodeURIComponent(options.bucket!.name)}/iam`,
11821219
body: JSON.stringify(body),
1183-
headers: {'Content-Type': 'application/json'},
1220+
headers: {
1221+
'Content-Type': 'application/json',
1222+
...(retryId ? {'x-retry-test-id': retryId} : {}),
1223+
},
11841224
});
11851225
}
11861226

handwritten/storage/src/acl.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,10 @@ class Acl extends AclRoleAccessorMethods {
528528
if (this.parent instanceof File) {
529529
const file = this.parent as File;
530530
const bucket = file.parent;
531-
url = `${bucket.baseUrl}/${bucket.name}/${file.baseUrl}/${file.name}${url}`;
531+
url = `/storage/v1/b/${bucket.name}/o/${encodeURIComponent(file.name)}${url}`;
532532
} else if (this.parent instanceof Bucket) {
533533
const bucket = this.parent as Bucket;
534-
url = `${bucket.baseUrl}/${bucket.name}${url}`;
534+
url = `/storage/v1/b/${bucket.name}${url}`;
535535
}
536536

537537
this.storageTransport
@@ -644,14 +644,14 @@ class Acl extends AclRoleAccessorMethods {
644644
query.userProject = options.userProject;
645645
}
646646

647-
let url = `${this.pathPrefix}/${options.entity}`;
647+
let url = `${this.pathPrefix}/${encodeURIComponent(options.entity)}`;
648648
if (this.parent instanceof File) {
649649
const file = this.parent as File;
650650
const bucket = file.parent;
651-
url = `${bucket.baseUrl}/${bucket.name}/${file.baseUrl}/${file.name}${url}`;
651+
url = `/storage/v1/b/${bucket.name}/o/${encodeURIComponent(file.name)}${url}`;
652652
} else if (this.parent instanceof Bucket) {
653653
const bucket = this.parent as Bucket;
654-
url = `${bucket.baseUrl}/${bucket.name}${url}`;
654+
url = `/storage/v1/b/${bucket.name}${url}`;
655655
}
656656

657657
this.storageTransport
@@ -768,7 +768,7 @@ class Acl extends AclRoleAccessorMethods {
768768

769769
let url = `${this.pathPrefix}`;
770770
if (options) {
771-
url = `${url}/${options.entity}`;
771+
url = `${url}/${encodeURIComponent(options.entity)}`;
772772
if (options.generation) {
773773
query.generation = options.generation;
774774
}
@@ -781,10 +781,10 @@ class Acl extends AclRoleAccessorMethods {
781781
if (this.parent instanceof File) {
782782
const file = this.parent as File;
783783
const bucket = file.parent;
784-
url = `${bucket.baseUrl}/${bucket.name}/${file.baseUrl}/${file.name}${url}`;
784+
url = `/storage/v1/b/${bucket.name}/o/${encodeURIComponent(file.name)}${url}`;
785785
} else if (this.parent instanceof Bucket) {
786786
const bucket = this.parent as Bucket;
787-
url = `${bucket.baseUrl}/${bucket.name}${url}`;
787+
url = `/storage/v1/b/${bucket.name}${url}`;
788788
}
789789

790790
this.storageTransport
@@ -888,14 +888,14 @@ class Acl extends AclRoleAccessorMethods {
888888
query.userProject = options.userProject;
889889
}
890890

891-
let url = `${this.pathPrefix}/${options.entity}`;
891+
let url = `${this.pathPrefix}/${encodeURIComponent(options.entity)}`;
892892
if (this.parent instanceof File) {
893893
const file = this.parent as File;
894894
const bucket = file.parent;
895-
url = `${bucket.baseUrl}/${bucket.name}/${file.baseUrl}/${file.name}${url}`;
895+
url = `/storage/v1/b/${bucket.name}/o/${encodeURIComponent(file.name)}${url}`;
896896
} else if (this.parent instanceof Bucket) {
897897
const bucket = this.parent as Bucket;
898-
url = `${bucket.baseUrl}/${bucket.name}${url}`;
898+
url = `/storage/v1/b/${bucket.name}${url}`;
899899
}
900900

901901
this.storageTransport

handwritten/storage/src/bucket.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
12321232
super({
12331233
storageTransport: storage.storageTransport,
12341234
parent: storage,
1235-
baseUrl: '/b',
1235+
baseUrl: '/storage/v1/b',
12361236
id: name,
12371237
createMethod: storage.createBucket.bind(storage),
12381238
methods,
@@ -1688,7 +1688,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
16881688
.makeRequest(
16891689
{
16901690
method: 'POST',
1691-
url: '/compose',
1691+
url: '/storage/v1/b/${this.name}/o/${encodeURIComponent(destinationFile.name)}/compose',
16921692
maxRetries,
16931693
body: JSON.stringify({
16941694
destination: {
@@ -1709,6 +1709,9 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
17091709
return sourceObject;
17101710
}),
17111711
}),
1712+
headers: {
1713+
'Content-Type': 'application/json',
1714+
},
17121715
queryParameters: options as unknown as StorageQueryParameters,
17131716
},
17141717
(err, resp) => {
@@ -2050,6 +2053,9 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
20502053
body: JSON.stringify(convertObjKeysToSnakeCase(body)),
20512054
queryParameters: query as unknown as StorageQueryParameters,
20522055
retry: false,
2056+
headers: {
2057+
'Content-Type': 'application/json',
2058+
},
20532059
},
20542060
(err, data, resp) => {
20552061
if (err) {

handwritten/storage/src/channel.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Channel extends ServiceObject<Channel, BaseMetadata> {
4343
const config = {
4444
parent: storage,
4545
storageTransport: storage.storageTransport,
46-
baseUrl: '/channels',
46+
baseUrl: '/storage/v1/channels',
4747
id: '',
4848
methods: {},
4949
};
@@ -89,6 +89,9 @@ class Channel extends ServiceObject<Channel, BaseMetadata> {
8989
method: 'POST',
9090
url: `${this.baseUrl}/stop`,
9191
body: JSON.stringify(this.metadata),
92+
headers: {
93+
'Content-Type': 'application/json',
94+
},
9295
responseType: 'json',
9396
},
9497
(err, data, resp) => {

0 commit comments

Comments
 (0)