|
15 | 15 | import {Bucket, File, Notification, Storage, HmacKey, Policy} from '../src'; |
16 | 16 | import * as path from 'path'; |
17 | 17 | import {ApiError} from '../src/nodejs-common'; |
| 18 | +import { |
| 19 | + createTestBuffer, |
| 20 | + createTestFileFromBuffer, |
| 21 | + deleteTestFile, |
| 22 | +} from './testBenchUtil'; |
| 23 | +import * as uuid from 'uuid'; |
| 24 | + |
| 25 | +const FILE_SIZE_BYTES = 9 * 1024 * 1024; |
| 26 | +const CHUNK_SIZE_BYTES = 2 * 1024 * 1024; |
18 | 27 |
|
19 | 28 | export interface ConformanceTestOptions { |
20 | 29 | bucket?: Bucket; |
@@ -375,35 +384,38 @@ export async function bucketSetStorageClass(options: ConformanceTestOptions) { |
375 | 384 | export async function bucketUploadResumableInstancePrecondition( |
376 | 385 | options: ConformanceTestOptions |
377 | 386 | ) { |
| 387 | + const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`); |
| 388 | + createTestFileFromBuffer(FILE_SIZE_BYTES, filePath); |
378 | 389 | if (options.bucket!.instancePreconditionOpts) { |
379 | 390 | options.bucket!.instancePreconditionOpts.ifGenerationMatch = 0; |
| 391 | + delete options.bucket!.instancePreconditionOpts.ifMetagenerationMatch; |
380 | 392 | } |
381 | | - await options.bucket!.upload( |
382 | | - path.join( |
383 | | - __dirname, |
384 | | - '../../conformance-test/test-data/retryStrategyTestData.json' |
385 | | - ), |
386 | | - {resumable: true} |
387 | | - ); |
| 393 | + await options.bucket!.upload(filePath, { |
| 394 | + resumable: true, |
| 395 | + chunkSize: CHUNK_SIZE_BYTES, |
| 396 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
| 397 | + }); |
| 398 | + deleteTestFile(filePath); |
388 | 399 | } |
389 | 400 |
|
390 | 401 | export async function bucketUploadResumable(options: ConformanceTestOptions) { |
| 402 | + const filePath = path.join(__dirname, `test-data/tmp-${uuid.v4()}.txt`); |
| 403 | + createTestFileFromBuffer(FILE_SIZE_BYTES, filePath); |
391 | 404 | if (options.preconditionRequired) { |
392 | | - await options.bucket!.upload( |
393 | | - path.join( |
394 | | - __dirname, |
395 | | - '../../conformance-test/test-data/retryStrategyTestData.json' |
396 | | - ), |
397 | | - {preconditionOpts: {ifMetagenerationMatch: 2, ifGenerationMatch: 0}} |
398 | | - ); |
| 405 | + await options.bucket!.upload(filePath, { |
| 406 | + resumable: true, |
| 407 | + chunkSize: CHUNK_SIZE_BYTES, |
| 408 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
| 409 | + preconditionOpts: {ifGenerationMatch: 0}, |
| 410 | + }); |
399 | 411 | } else { |
400 | | - await options.bucket!.upload( |
401 | | - path.join( |
402 | | - __dirname, |
403 | | - '../../conformance-test/test-data/retryStrategyTestData.json' |
404 | | - ) |
405 | | - ); |
| 412 | + await options.bucket!.upload(filePath, { |
| 413 | + resumable: true, |
| 414 | + chunkSize: CHUNK_SIZE_BYTES, |
| 415 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
| 416 | + }); |
406 | 417 | } |
| 418 | + deleteTestFile(filePath); |
407 | 419 | } |
408 | 420 |
|
409 | 421 | export async function bucketUploadMultipartInstancePrecondition( |
@@ -590,21 +602,31 @@ export async function rotateEncryptionKey(options: ConformanceTestOptions) { |
590 | 602 | export async function saveResumableInstancePrecondition( |
591 | 603 | options: ConformanceTestOptions |
592 | 604 | ) { |
593 | | - await options.file!.save('testdata', {resumable: true}); |
| 605 | + const buf = createTestBuffer(FILE_SIZE_BYTES); |
| 606 | + await options.file!.save(buf, { |
| 607 | + resumable: true, |
| 608 | + chunkSize: CHUNK_SIZE_BYTES, |
| 609 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
| 610 | + }); |
594 | 611 | } |
595 | 612 |
|
596 | 613 | export async function saveResumable(options: ConformanceTestOptions) { |
| 614 | + const buf = createTestBuffer(FILE_SIZE_BYTES); |
597 | 615 | if (options.preconditionRequired) { |
598 | | - await options.file!.save('testdata', { |
| 616 | + await options.file!.save(buf, { |
599 | 617 | resumable: true, |
| 618 | + chunkSize: CHUNK_SIZE_BYTES, |
| 619 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
600 | 620 | preconditionOpts: { |
601 | 621 | ifGenerationMatch: options.file!.metadata.generation, |
602 | 622 | ifMetagenerationMatch: options.file!.metadata.metageneration, |
603 | 623 | }, |
604 | 624 | }); |
605 | 625 | } else { |
606 | | - await options.file!.save('testdata', { |
| 626 | + await options.file!.save(buf, { |
607 | 627 | resumable: true, |
| 628 | + chunkSize: CHUNK_SIZE_BYTES, |
| 629 | + metadata: {contentLength: FILE_SIZE_BYTES}, |
608 | 630 | }); |
609 | 631 | } |
610 | 632 | } |
|
0 commit comments