-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
141 lines (134 loc) · 4.57 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var tape = require('tape');
var s3mpuCleanup = require('./index');
var s3 = {};
// Mock abortMultipartUpload behavior.
s3.abortMultipartUpload = function(options, callback) {
if (!options.Bucket || !options.UploadId || !options.Key) {
throw new Error('Bucket, UploadId, Key params are required');
}
return callback();
};
// Mock listMultipartUploads behavior.
s3.listMultipartUploads = function(options, callback) {
if (options.Bucket === 'test-bucket' && !options.KeyMarker) {
return callback(null, {
"Bucket": "test-bucket",
"KeyMarker": "",
"UploadIdMarker": "",
"NextKeyMarker": "b.json",
"NextUploadIdMarker": "id.2",
"MaxUploads": 2,
"IsTruncated": true,
"Uploads": [
{
"UploadId": "id.1",
"Key": "a.json",
"Initiated": new Date("2015-01-01T00:00:00.000Z"),
"StorageClass": "STANDARD",
"Owner": {
"DisplayName": "test",
"ID": "111"
},
"Initiator": {
"ID": "arn:aws:iam::111:user/test",
"DisplayName": "test"
}
},
{
"UploadId": "id.2",
"Key": "b.json",
"Initiated": new Date(),
"StorageClass": "STANDARD",
"Owner": {
"DisplayName": "test",
"ID": "111"
},
"Initiator": {
"ID": "arn:aws:iam::111:user/test",
"DisplayName": "test"
}
}
],
"CommonPrefixes": []
});
} else if (options.Bucket === 'test-bucket' && options.KeyMarker === 'b.json' && options.UploadIdMarker === 'id.2') {
return callback(null, {
"Bucket": "test-bucket",
"KeyMarker": "b.json",
"UploadIdMarker": "id.2",
"NextKeyMarker": "c.json",
"NextUploadIdMarker": "id.3",
"MaxUploads": 2,
"IsTruncated": false,
"Uploads": [
{
"UploadId": "id.3",
"Key": "c.json",
"Initiated": new Date(+new Date() - 36e5),
"StorageClass": "STANDARD",
"Owner": {
"DisplayName": "test",
"ID": "111"
},
"Initiator": {
"ID": "arn:aws:iam::111:user/test",
"DisplayName": "test"
}
}
],
"CommonPrefixes": []
});
} else {
return callback(new Error('Mock: unsupported behavior'));
}
};
tape('listAll', function(assert) {
s3mpuCleanup.listAll({ s3: s3, bucket: 'test-bucket' }, function(err, data) {
assert.ifError(err);
assert.equal(data.length, 3, 'lists for all items using marker');
assert.deepEqual(data.map(function(o) { return o.UploadId; }), [
'id.1',
'id.2',
'id.3'
], 'returns upload items');
assert.end();
});
});
tape('cleanup (defaults)', function(assert) {
s3mpuCleanup({s3: s3, bucket:'test-bucket'}, function(err, aborted) {
assert.ifError(err);
assert.deepEqual(aborted, [
's3://test-bucket/[email protected]'
], 'aborts expired [email protected]');
assert.end();
});
});
tape('cleanup (logger)', function(assert) {
var logged = [];
s3mpuCleanup({
s3: s3,
bucket:'test-bucket',
logger: function(entry) {
logged.push(entry);
}
}, function(err, aborted) {
assert.ifError(err);
assert.deepEqual(aborted, [
's3://test-bucket/[email protected]'
], 'aborts expired [email protected]');
assert.deepEqual(logged, [
's3://test-bucket/[email protected]'
], 'calls logger function');
assert.end();
});
});
tape('cleanup (before=10min ago)', function(assert) {
s3mpuCleanup({s3: s3, bucket:'test-bucket', before: new Date(+new Date - 60e3)}, function(err, aborted) {
assert.ifError(err);
assert.deepEqual(aborted, [
's3://test-bucket/[email protected]',
's3://test-bucket/[email protected]'
], 'aborts expired [email protected], [email protected]');
assert.end();
});
});