1- var expect = require ( 'chai' ) . expect ,
2- fs = require ( 'fs' ) ,
3- Writable = require ( 'stream' ) . Writable ;
4-
5- // Define a stubbed out version of the AWS S3 Node.js client
6- var AWSstub = {
7- S3 : function ( ) {
8- this . createMultipartUpload = function ( details , callback ) {
9- // Make sure that this AWS function was called with the right parameters.
10- expect ( details ) . to . have . property ( 'Bucket' ) ;
11- expect ( details . Key ) . to . be . a ( 'string' ) ;
12-
13- expect ( details ) . to . have . property ( 'Key' ) ;
14- expect ( details . Key ) . to . be . a ( 'string' ) ;
15-
16- if ( details . Key == 'create-fail' ) {
17- // Trigger a simulated error when a magic file name is used.
18- callback ( 'Simulated failure from mocked API' ) ;
19- }
20- else {
21- callback ( null , {
22- UploadId : 'upload-id'
23- } ) ;
24- }
25- } ;
26-
27- this . uploadPart = function ( details , callback ) {
28- // Make sure that all the properties are there
29- expect ( details ) . to . have . property ( 'Body' ) ;
30- expect ( details . Body ) . to . be . instanceof ( Buffer ) ;
31-
32- expect ( details ) . to . have . property ( 'Bucket' ) ;
33- expect ( details . Bucket ) . to . equal ( 'test-bucket-name' ) ;
34-
35- expect ( details ) . to . have . property ( 'Key' ) ;
36- expect ( details . Key ) . to . be . a ( 'string' ) ;
37-
38- expect ( details ) . to . have . property ( 'UploadId' ) ;
39- expect ( details . UploadId ) . to . contain ( 'upload-id' ) ;
40-
41- expect ( details ) . to . have . property ( 'PartNumber' ) ;
42- expect ( details . PartNumber ) . to . be . an . integer ;
43-
44- if ( details . Key == 'upload-fail' ) {
45- callback ( 'Simulated failure from mocked API' ) ;
46- }
47- else {
48- // Return an ETag
49- callback ( null , {
50- ETag : 'etag'
51- } ) ;
52- }
53- } ;
54-
55- this . abortMultipartUpload = function ( details , callback ) {
56- // Make sure that all the properties are there
57- expect ( details ) . to . have . property ( 'Bucket' ) ;
58- expect ( details . Bucket ) . to . equal ( 'test-bucket-name' ) ;
1+ var expect = require ( 'chai' ) . expect ,
2+ fs = require ( 'fs' ) ,
3+ Writable = require ( 'stream' ) . Writable ,
4+ AWSstub = require ( '../lib/AWSstub' ) ,
5+ s3StreamClient = require ( '../lib/s3-upload-stream.js' ) ( new AWSstub . S3 ( ) ) ;
596
60- expect ( details ) . to . have . property ( 'Key' ) ;
61- expect ( details . Key ) . to . be . a ( 'string' ) ;
62-
63- expect ( details ) . to . have . property ( 'UploadId' ) ;
64- expect ( details . UploadId ) . to . contain ( 'upload-id' ) ;
65-
66- if ( details . Key == 'abort-fail' ) {
67- // Trigger a simulated error when a magic file name is used.
68- callback ( 'Simulated failure from mocked API' ) ;
69- }
70- else {
71- callback ( ) ;
72- }
73- } ;
74-
75- this . completeMultipartUpload = function ( details , callback ) {
76- // Make sure that all the properties are there
77- expect ( details ) . to . have . property ( 'Bucket' ) ;
78- expect ( details . Bucket ) . to . equal ( 'test-bucket-name' ) ;
79-
80- expect ( details ) . to . have . property ( 'Key' ) ;
81- expect ( details . Key ) . to . be . a ( 'string' ) ;
82-
83- expect ( details ) . to . have . property ( 'UploadId' ) ;
84- expect ( details . UploadId ) . to . contain ( 'upload-id' ) ;
85-
86- expect ( details ) . to . have . property ( 'MultipartUpload' ) ;
87- expect ( details . MultipartUpload ) . to . an . object ;
88-
89- expect ( details . MultipartUpload ) . to . have . property ( 'Parts' ) ;
90- expect ( details . MultipartUpload . Parts ) . to . an . array ;
91-
92- details . MultipartUpload . Parts . forEach ( function ( partNumber ) {
93- expect ( partNumber ) . to . be . an . integer ;
94- } ) ;
95-
96- if ( details . Key == 'complete-fail' || details . Key == 'abort-fail' ) {
97- // Trigger a simulated error when a magic file name is used.
98- callback ( 'Simulated failure from mocked API' ) ;
99- }
100- else {
101- callback ( null , {
102- ETag : 'etag'
103- } ) ;
104- }
105- } ;
106- }
107- } ;
108-
109- var s3StreamClient = require ( '../lib/s3-upload-stream.js' ) ( new AWSstub . S3 ( ) ) ;
1107
1118describe ( 'Creating upload client' , function ( ) {
1129 describe ( 'Without specifying an S3 client' , function ( ) {
@@ -120,7 +17,6 @@ describe('Creating upload client', function () {
12017 "Bucket" : "test-bucket-name" ,
12118 "Key" : "test-file-name"
12219 } ) ;
123-
12420 done ( ) ;
12521 }
12622 catch ( e ) {
0 commit comments