11const assert = require ( 'assert' ) ;
2- const async = require ( 'async' ) ;
32const stream = require ( 'stream' ) ;
3+ const sinon = require ( 'sinon' ) ;
44const { promisify } = require ( 'util' ) ;
55
66const AwsClient = require ( '../../../../../lib/storage/data/external/AwsClient' ) ;
@@ -50,11 +50,21 @@ const backendClients = [
5050 } ,
5151] ;
5252const log = new DummyRequestLogger ( ) ;
53+ let sandbox ;
5354
5455describe ( 'external backend clients' , ( ) => {
56+ beforeEach ( ( ) => {
57+ sandbox = sinon . createSandbox ( ) ;
58+ } ) ;
59+
60+ afterEach ( ( ) => {
61+ sandbox . restore ( ) ;
62+ } ) ;
63+
5564 backendClients . forEach ( backend => {
5665 let testClient ;
57- let headAsync , getAsync , objectPutTaggingAsync , objectDeleteTaggingAsync ;
66+ let headAsync , getAsync , deleteAsync , objectPutTaggingAsync , objectDeleteTaggingAsync ,
67+ createMPUAsync , uploadPartAsync , abortMPUAsync , listPartsAsync ;
5868
5969 beforeAll ( ( ) => {
6070 testClient = new backend . Class ( backend . config ) ;
@@ -63,10 +73,17 @@ describe('external backend clients', () => {
6373 // Promisify the client methods
6474 headAsync = promisify ( testClient . head . bind ( testClient ) ) ;
6575 getAsync = promisify ( testClient . get . bind ( testClient ) ) ;
76+ deleteAsync = promisify ( testClient . delete . bind ( testClient ) ) ;
6677 if ( backend . config . type !== 'azure' ) {
78+ createMPUAsync = promisify ( testClient . createMPU . bind ( testClient ) ) ;
79+ uploadPartAsync = promisify ( testClient . uploadPart . bind ( testClient ) ) ;
80+ abortMPUAsync = promisify ( testClient . abortMPU . bind ( testClient ) ) ;
6781 objectPutTaggingAsync = promisify ( testClient . objectPutTagging . bind ( testClient ) ) ;
6882 objectDeleteTaggingAsync = promisify ( testClient . objectDeleteTagging . bind ( testClient ) ) ;
6983 }
84+ if ( backend . config . type === 'aws' ) {
85+ listPartsAsync = promisify ( testClient . listParts . bind ( testClient ) ) ;
86+ }
7087 } ) ;
7188
7289 if ( backend . config . type !== 'azure' ) {
@@ -174,6 +191,16 @@ describe('external backend clients', () => {
174191 assert . strictEqual ( errorHandled , true ) ;
175192 } ) ;
176193
194+ it ( `${ backend . name } delete() should delete the requested key without error` , async ( ) => {
195+ const key = 'externalBackendTestKey' ;
196+ const bucketName = 'externalBackendTestBucket' ;
197+ const objectInfo = Object . assign ( {
198+ deleteVersion : false ,
199+ } , testClient . toObjectGetInfo ( key , bucketName ) ) ;
200+ const result = await deleteAsync ( objectInfo , '' ) ;
201+ assert . strictEqual ( result , undefined ) ;
202+ } ) ;
203+
177204 if ( backend . config . type !== 'azure' ) {
178205 it ( `${ backend . name } should set tags and then delete it` , async ( ) => {
179206 const key = 'externalBackendTestKey' ;
@@ -228,7 +255,93 @@ describe('external backend clients', () => {
228255 assert ( err . is . ServiceUnavailable ) ;
229256 }
230257 } ) ;
258+
259+ it ( `${ backend . name } uploadPart() should return sanitized data retrieval info` , async ( ) => {
260+ const key = 'externalBackendTestKey' ;
261+ const bucketName = 'externalBackendTestBucket' ;
262+ const result = await uploadPartAsync ( null , null ,
263+ stream . Readable . from ( [ 'part data' ] ) ,
264+ 9 , key , 'uploadId-123' , 1 , bucketName , log ) ;
265+
266+ assert . strictEqual ( result . key , `${ bucketName } /${ key } ` ) ;
267+ assert . strictEqual ( result . dataStoreName , backend . config . dataStoreName ) ;
268+ assert ( result . dataStoreETag ) ;
269+ assert . strictEqual ( result . dataStoreETag . includes ( '"' ) , false ) ;
270+ } ) ;
271+
272+ it ( `${ backend . name } abortMPU() should resolve without error` , async ( ) => {
273+ const key = 'externalBackendTestKey' ;
274+ const bucketName = 'externalBackendTestBucket' ;
275+
276+ const result = await abortMPUAsync ( key , 'uploadId-123' , bucketName , log ) ;
277+ assert . strictEqual ( result , undefined ) ;
278+ } ) ;
279+
280+ if ( backend . config . type === 'aws' ) {
281+ it ( `${ backend . name } listParts() should map result parts` , async ( ) => {
282+ const key = 'externalBackendTestKey' ;
283+ const bucketName = 'externalBackendTestBucket' ;
284+
285+ const storedParts = await listPartsAsync ( key , 'uploadId-123' , bucketName , 0 , 1000 , log ) ;
286+
287+ assert ( Array . isArray ( storedParts . Contents ) ) ;
288+ assert ( storedParts . Contents . length > 0 ) ;
289+ const firstPart = storedParts . Contents [ 0 ] ;
290+ assert . strictEqual ( typeof firstPart . partNumber , 'number' ) ;
291+ assert ( firstPart . value ) ;
292+ assert . strictEqual ( firstPart . value . ETag . includes ( '"' ) , false ) ;
293+ } ) ;
294+ }
295+
296+ it ( `${ backend . name } createMPU() should trim metadata and forward tagging` , async ( ) => {
297+ const key = 'externalBackendTestKey' ;
298+ const bucketName = 'externalBackendTestBucket' ;
299+ const metaHeaders = {
300+ 'x-amz-meta-custom-key' : 'customValue' ,
301+ 'x-amz-meta-second-key' : 'secondValue' ,
302+ ignored : 'shouldBeDropped' ,
303+ } ;
304+ const args = [
305+ key ,
306+ metaHeaders ,
307+ bucketName ,
308+ 'http://redirect' ,
309+ 'text/plain' ,
310+ 'max-age=3600' ,
311+ 'attachment' ,
312+ 'gzip' ,
313+ 'k1=v1&k2=v2' ,
314+ log ,
315+ ] ;
316+
317+ if ( backend . config . type === 'aws' ) {
318+ const sendSpy = sandbox . spy ( testClient . _client , 'send' ) ;
319+ const result = await createMPUAsync ( ...args ) ;
320+ assert ( result ) ;
321+ assert ( result . UploadId ) ;
322+ assert ( sendSpy . calledOnce ) ;
323+ const command = sendSpy . firstCall . args [ 0 ] ;
324+ assert . strictEqual ( command . constructor . name , 'CreateMultipartUploadCommand' ) ;
325+ assert . deepStrictEqual ( command . input . Metadata , {
326+ 'custom-key' : 'customValue' ,
327+ 'second-key' : 'secondValue' ,
328+ } ) ;
329+ assert . strictEqual ( command . input . Tagging , 'k1=v1&k2=v2' ) ;
330+ } else {
331+ const createSpy = sandbox . spy ( testClient . _client , 'createMultipartUpload' ) ;
332+ const result = await createMPUAsync ( ...args ) ;
333+ assert ( result ) ;
334+ assert ( result . UploadId ) ;
335+ assert ( createSpy . calledOnce ) ;
336+ const capturedParams = createSpy . firstCall . args [ 0 ] ;
337+ assert . strictEqual ( capturedParams . Bucket , backend . config . mpuBucket ) ;
338+ assert . deepStrictEqual ( capturedParams . Metadata , {
339+ 'custom-key' : 'customValue' ,
340+ 'second-key' : 'secondValue' ,
341+ } ) ;
342+ assert . strictEqual ( capturedParams . Tagging , 'k1=v1&k2=v2' ) ;
343+ }
344+ } ) ;
231345 }
232- // To-Do: test the other external client methods (delete, createMPU ...)
233346 } ) ;
234347} ) ;
0 commit comments