1
1
var expect = require ( 'expect.js' ) ,
2
2
S3Provider = require ( ".." ) ,
3
- S3Options = { bucket : "<name>" , key : "<S3_KEY>" , secret : "<S3_SECRET>" } ,
4
- guid = require ( "../util" ) . guid ;
5
-
6
- if ( ! S3Provider . isSupported ) {
7
- console . log ( "Skipping Filer.FileSystem.providers.S3 tests, since S3 isn't supported." ) ;
8
- return ;
9
- }
3
+ S3Options = { bucket : "<bucket_name>" , key : "<S3_KEY>" , secret : "<S3_SECRET>" } ,
4
+ guid = require ( "../lib/utils" ) . guid ,
5
+ randomName ,
6
+ randomKeyPrefix ;
10
7
11
8
describe ( "Filer.FileSystem.providers.S3" , function ( ) {
12
9
it ( "is supported -- if it isn't, none of these tests can run." , function ( ) {
@@ -24,24 +21,35 @@ describe("Filer.FileSystem.providers.S3", function() {
24
21
var _provider ;
25
22
26
23
beforeEach ( function ( ) {
27
- _provider = new S3Provider ( { name : guid ( ) , keyPrefix : guid ( ) } ) ;
24
+ randomName = guid ( ) ;
25
+ randomKeyPrefix = guid ( ) ;
26
+ _provider = new S3Provider ( { name : randomName , keyPrefix : randomKeyPrefix } ) ;
28
27
} ) ;
29
28
30
29
afterEach ( function ( done ) {
31
- provider = _provider ;
32
- provider . open ( S3Options , function ( error , firstAccess ) {
33
- if ( error ) {
34
- throw error ;
35
- }
36
- var context = provider . getReadWriteContext ( ) ;
37
- context . clear ( function ( error ) {
38
- if ( error ) {
39
- throw error ;
40
- }
41
- expect ( error ) . not . to . exist ;
42
- done ( ) ;
30
+ var s3 = require ( "knox" ) . createClient ( S3Options ) ;
31
+ var options = {
32
+ prefix : randomKeyPrefix
33
+ } ;
34
+ getAllObjects ( options , [ ] ) ;
35
+
36
+ function getAllObjects ( options , aggregate ) {
37
+ s3 . list ( options , function ( err , data ) {
38
+ aggregate = aggregate . concat ( data . Contents . map ( function ( content ) {
39
+ return content . Key ;
40
+ } ) ) ;
41
+ if ( data . IsTruncated ) {
42
+ options . marker = data . Contents [ data . Contents . length - 1 ] . Key ;
43
+ getAllObjects ( options , aggregate ) ;
44
+ }
45
+ s3 . deleteMultiple ( aggregate , function ( err , res ) {
46
+ if ( res . statusCode === 403 ) {
47
+ return callback ( "Error 403: Permission deined." + err ) ;
48
+ }
49
+ done ( ) ;
50
+ } ) ;
43
51
} ) ;
44
- } ) ;
52
+ }
45
53
} ) ;
46
54
47
55
it ( "should open a new S3" , function ( done ) {
@@ -67,6 +75,7 @@ describe("Filer.FileSystem.providers.S3", function() {
67
75
if ( error ) {
68
76
throw error ;
69
77
}
78
+ expect ( firstAccess ) . to . be . true ;
70
79
var context = provider . getReadWriteContext ( ) ;
71
80
context . clear ( function ( error ) {
72
81
if ( error ) {
@@ -85,14 +94,16 @@ describe("Filer.FileSystem.providers.S3", function() {
85
94
if ( error ) {
86
95
throw error ;
87
96
}
97
+ expect ( firstAccess ) . to . be . true ;
88
98
var context = provider . getReadWriteContext ( ) ;
89
- context . put ( "key" , " data" , function ( error , result ) {
99
+ context . put ( "key" , data , function ( error ) {
90
100
if ( error ) {
91
101
throw error ;
92
102
}
93
103
context . get ( "key" , function ( error , result ) {
94
104
expect ( error ) . not . to . exist ;
95
- expect ( result ) . to . equal ( "data" ) ;
105
+ expect ( result ) . to . exist ;
106
+ expect ( result ) . to . eql ( data ) ;
96
107
done ( ) ;
97
108
} ) ;
98
109
} ) ;
@@ -105,13 +116,13 @@ describe("Filer.FileSystem.providers.S3", function() {
105
116
if ( error ) {
106
117
throw error ;
107
118
}
108
-
119
+ expect ( firstAccess ) . to . be . true ;
109
120
var context = provider . getReadWriteContext ( ) ;
110
- context . put ( "key" , "value" , function ( error , result ) {
121
+ context . put ( "key" , "value" , function ( error ) {
111
122
if ( error ) {
112
123
throw error ;
113
124
}
114
- context . delete ( "key" , function ( error , result ) {
125
+ context . delete ( "key" , function ( error ) {
115
126
if ( error ) {
116
127
throw error ;
117
128
}
@@ -134,16 +145,19 @@ describe("Filer.FileSystem.providers.S3", function() {
134
145
if ( error ) {
135
146
throw error ;
136
147
}
148
+ expect ( firstAccess ) . to . be . true ;
137
149
var context = provider . getReadWriteContext ( ) ;
138
- context . put ( "key1" , data1 , function ( error , result ) {
150
+ context . put ( "key1" , data1 , function ( error ) {
139
151
if ( error ) {
140
152
throw error ;
141
153
}
142
- context . put ( "key2" , data2 , function ( error , result ) {
154
+ expect ( error ) . not . to . exist ;
155
+ context . put ( "key2" , data2 , function ( error ) {
143
156
if ( error ) {
144
157
throw error ;
145
158
}
146
- context . clear ( function ( err ) {
159
+ expect ( error ) . not . to . exist ;
160
+ context . clear ( function ( error ) {
147
161
if ( error ) {
148
162
throw error ;
149
163
}
@@ -170,10 +184,10 @@ describe("Filer.FileSystem.providers.S3", function() {
170
184
if ( error ) {
171
185
throw error ;
172
186
}
187
+ expect ( firstAccess ) . to . be . true ;
173
188
var context = provider . getReadOnlyContext ( ) ;
174
- context . put ( "key1" , data1 , function ( error , result ) {
189
+ context . put ( "key1" , data1 , function ( error ) {
175
190
expect ( error ) . to . exist ;
176
- expect ( result ) . not . to . exist ;
177
191
done ( ) ;
178
192
} ) ;
179
193
} ) ;
0 commit comments