@@ -57,7 +57,7 @@ var test = function (name, fn) {
57
57
} ;
58
58
var group = function ( name , fn ) {
59
59
describe ( name , function ( ) {
60
- this . timeout ( 120000 ) ;
60
+ this . timeout ( 2 * 60 * 1000 ) ;
61
61
fn . apply ( this , arguments ) ;
62
62
} ) ;
63
63
} ;
@@ -1075,12 +1075,11 @@ group('sliceUploadFile() ', function () {
1075
1075
Key : filename ,
1076
1076
} ,
1077
1077
function ( err , data ) {
1078
- console . log ( 'headObject' , err ? 'failed' : 'success' ) ;
1079
- assert . ok ( data && data . headers && data . headers . etag && data . headers . etag . length > 0 , '文件已上传成功' ) ;
1080
- assert . ok (
1081
- data && data . headers && parseInt ( data . headers [ 'content-length' ] || 0 ) === fileSize ,
1082
- '文件大小一致'
1083
- ) ;
1078
+ var hasEtag = data && data . headers && data . headers . etag && data . headers . etag . length > 0 ;
1079
+ var sizeEqual = data && data . headers && parseInt ( data . headers [ 'content-length' ] || 0 ) === fileSize ;
1080
+ var ok = hasEtag && sizeEqual ;
1081
+ console . log ( 'ok' , ok ) ;
1082
+ assert . ok ( ok ) ;
1084
1083
done ( ) ;
1085
1084
}
1086
1085
) ;
@@ -1129,7 +1128,7 @@ group('sliceUploadFile() ', function () {
1129
1128
TaskId = taskId ;
1130
1129
} ,
1131
1130
onProgress : function ( info ) {
1132
- if ( ! paused && info . percent >= 0.3 ) {
1131
+ if ( ! paused && info . percent >= 0.1 ) {
1133
1132
cos . pauseTask ( TaskId ) ;
1134
1133
paused = true ;
1135
1134
setTimeout ( function ( ) {
@@ -1140,9 +1139,14 @@ group('sliceUploadFile() ', function () {
1140
1139
} ,
1141
1140
} ,
1142
1141
function ( err , data ) {
1142
+ if ( paused ) {
1143
+ console . log ( 'paused-------' ) ;
1144
+ return ;
1145
+ }
1143
1146
paused = true ;
1144
1147
console . log ( 'pauseTask(),restartTask' , err || data ) ;
1145
1148
assert . ok ( 1 ) ;
1149
+ console . log ( 'done2' ) ;
1146
1150
done ( ) ;
1147
1151
}
1148
1152
) ;
@@ -1262,10 +1266,11 @@ group('sliceUploadFile() ', function () {
1262
1266
Key : filename ,
1263
1267
FilePath : filePath ,
1264
1268
onProgress : function ( info ) {
1265
- if ( info . percent >= 0.2 ) {
1269
+ if ( info . percent >= 0.1 ) {
1266
1270
if ( ! deleted ) {
1267
1271
fs . rmSync ( filePath ) ;
1268
1272
deleted = true ;
1273
+ console . log ( 'file deleted' ) ;
1269
1274
}
1270
1275
}
1271
1276
} ,
@@ -2922,14 +2927,13 @@ group('optionsObject()', function () {
2922
2927
Bucket : config . Bucket , // Bucket 格式:test-1250000000
2923
2928
Region : config . Region ,
2924
2929
Key : '1.jpg' ,
2925
- Headers : {
2926
- Origin : 'https://qq.com' ,
2927
- 'Access-Control-Request-Method' : 'PUT' ,
2928
- 'Access-Control-Request-Headers' : 'Authorization,x-cos-security-token' ,
2929
- } ,
2930
+ Origin : 'https://qq.com' ,
2931
+ AccessControlRequestMethod : 'PUT' ,
2932
+ AccessControlRequestHeaders : 'Authorization,x-cos-security-token' ,
2930
2933
} ,
2931
2934
function ( err , data ) {
2932
- assert . ok ( err ) ;
2935
+ console . log ( 'deleteBucketCors' , err || data ) ;
2936
+ assert . ok ( data . statusCode === 403 ) ;
2933
2937
done ( ) ;
2934
2938
}
2935
2939
) ;
@@ -3013,6 +3017,7 @@ group('BucketCors', function () {
3013
3017
Region : config . Region ,
3014
3018
} ,
3015
3019
function ( err , data ) {
3020
+ console . log ( 'deleteBucketCors-getBucketCors' , data . CORSRules ) ;
3016
3021
assert . ok ( comparePlainObject ( [ ] , data . CORSRules ) ) ;
3017
3022
done ( ) ;
3018
3023
}
@@ -6078,9 +6083,12 @@ group('sliceUploadFile() 续传', function () {
6078
6083
ChunkSize : 1024 * 1024 ,
6079
6084
} ,
6080
6085
function ( err , data ) {
6086
+ console . log ( 'sliceUploadFile' , err , data ) ;
6081
6087
assert . ok ( data ) ;
6082
- fs . unlinkSync ( filepath ) ;
6083
6088
done ( ) ;
6089
+ setTimeout ( function ( ) {
6090
+ fs . unlinkSync ( filepath ) ;
6091
+ } , 1000 ) ;
6084
6092
}
6085
6093
) ;
6086
6094
}
@@ -6166,7 +6174,9 @@ group('getObject() 手动关闭合并 Key 校验', function () {
6166
6174
Key : '///////' ,
6167
6175
} ,
6168
6176
function ( err , data ) {
6169
- assert . ok ( data . Body . toString ( ) . includes ( 'ListBucketResult' ) ) ;
6177
+ console . log ( 'getObject Body1' , err || data ) ;
6178
+ // assert.ok(data.Body.toString().includes('ListBucketResult'));
6179
+ assert . ok ( err ) ;
6170
6180
done ( ) ;
6171
6181
}
6172
6182
) ;
@@ -6183,7 +6193,9 @@ group('getObject() 手动关闭合并 Key 校验', function () {
6183
6193
Key : '/./' ,
6184
6194
} ,
6185
6195
function ( err , data ) {
6186
- assert . ok ( data . Body . toString ( ) . includes ( 'ListBucketResult' ) ) ;
6196
+ console . log ( 'getObject Body3' , err || data ) ;
6197
+ // assert.ok(data.Body.toString().includes('ListBucketResult'));
6198
+ assert . ok ( err ) ;
6187
6199
done ( ) ;
6188
6200
}
6189
6201
) ;
@@ -6286,24 +6298,6 @@ group('downloadFile() 手动关闭合并 Key 校验', function () {
6286
6298
} ) ;
6287
6299
} ) ;
6288
6300
6289
- group ( 'getStream() 流式下载 ECONNREFUSED 错误' , function ( ) {
6290
- test ( 'getStream() 流式下载 ECONNREFUSED 错误' , function ( done , assert ) {
6291
- cos . options . Domain = '127.0.0.1:12345' ;
6292
- cos . getObject (
6293
- {
6294
- Bucket : config . Bucket ,
6295
- Region : config . Region ,
6296
- Key : '1.jpg' ,
6297
- } ,
6298
- function ( err , data ) {
6299
- assert . ok ( err . code === 'ECONNREFUSED' ) ;
6300
- cos . options . Domain = '' ;
6301
- done ( ) ;
6302
- }
6303
- ) ;
6304
- } ) ;
6305
- } ) ;
6306
-
6307
6301
group ( 'appendObject' , function ( ) {
6308
6302
test ( 'appendObject()' , function ( done , assert ) {
6309
6303
deleteObjectBefore ( 'append.txt' ) . then ( ( ) => {
@@ -6754,3 +6748,27 @@ group('RawBody error', function () {
6754
6748
) ;
6755
6749
} ) ;
6756
6750
} ) ;
6751
+
6752
+ // 这条放最后执行
6753
+ group ( 'getStream() 流式下载 ECONNREFUSED 错误' , function ( ) {
6754
+ test ( 'getStream() 流式下载 ECONNREFUSED 错误' , function ( done , assert ) {
6755
+ var cos = new COS ( {
6756
+ SecretId : config . SecretId ,
6757
+ SecretKey : config . SecretKey ,
6758
+ Timeout : 10000 ,
6759
+ } ) ;
6760
+ cos . options . Domain = '127.0.0.1:12345' ;
6761
+ cos . getObject (
6762
+ {
6763
+ Bucket : config . Bucket ,
6764
+ Region : config . Region ,
6765
+ Key : '1.jpg' ,
6766
+ } ,
6767
+ function ( err , data ) {
6768
+ console . log ( 'ECONNREFUSED 错误' , err || data ) ;
6769
+ assert . ok ( err && ( err . code === 'ECONNREFUSED' || err . code === 'ESOCKETTIMEDOUT' ) ) ;
6770
+ done ( ) ;
6771
+ }
6772
+ ) ;
6773
+ } ) ;
6774
+ } ) ;
0 commit comments