@@ -192,14 +192,74 @@ describe('S3Adapter tests', () => {
192192 } ) ;
193193 } ) ;
194194
195+ let s3 ;
195196
196197 if ( process . env . TEST_S3_ACCESS_KEY && process . env . TEST_S3_SECRET_KEY && process . env . TEST_S3_BUCKET ) {
197198 // Should be initialized from the env
198- let s3 = new S3Adapter ( {
199+ s3 = new S3Adapter ( {
199200 accessKey : process . env . TEST_S3_ACCESS_KEY ,
200201 secretKey : process . env . TEST_S3_SECRET_KEY ,
201202 bucket : process . env . TEST_S3_BUCKET
202203 } ) ;
203- filesAdapterTests . testAdapter ( "S3Adapter" , s3 ) ;
204+ } else {
205+ const bucket = 'FAKE_BUCKET' ;
206+
207+ s3 = new S3Adapter ( {
208+ accessKey : 'FAKE_ACCESS_KEY' ,
209+ secretKey : 'FAKE_SECRET_KEY' ,
210+ bucket,
211+ } ) ;
212+
213+ const objects = { } ;
214+
215+ s3 . _s3Client = {
216+ createBucket : callback => setTimeout ( callback , 100 ) ,
217+ upload : ( params , callback ) => setTimeout (
218+ ( ) => {
219+ const { Key, Body } = params ;
220+
221+ objects [ Key ] = Body ;
222+
223+ callback (
224+ null ,
225+ {
226+ Location : `https://${ bucket } .s3.amazonaws.com/${ Key } `
227+ }
228+ ) ;
229+ } ,
230+ 100
231+ ) ,
232+ deleteObject : ( params , callback ) => setTimeout (
233+ ( ) => {
234+ const { Key } = params ;
235+
236+ delete objects [ Key ] ;
237+
238+ callback ( null , { } ) ;
239+ } ,
240+ 100
241+ ) ,
242+ getObject : ( params , callback ) => setTimeout (
243+ ( ) => {
244+ const { Key } = params ;
245+
246+ if ( objects [ Key ] ) {
247+ callback (
248+ null ,
249+ {
250+ Body : Buffer . from ( objects [ Key ] , 'utf8' )
251+ }
252+ ) ;
253+ } else {
254+ callback (
255+ new Error ( 'Not found' )
256+ ) ;
257+ }
258+ } ,
259+ 100
260+ )
261+ } ;
204262 }
263+
264+ filesAdapterTests . testAdapter ( "S3Adapter" , s3 ) ;
205265} )
0 commit comments