-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathstorage-object-test.js
More file actions
189 lines (179 loc) · 5.45 KB
/
storage-object-test.js
File metadata and controls
189 lines (179 loc) · 5.45 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* container-test.js: Tests for Rackspace Cloudfiles containers
*
* (C) 2010 Nodejitsu Inc.
* MIT LICENSE
*
*/
var path = require('path'),
vows = require('vows'),
fs = require('fs'),
assert = require('assert'),
cloudfiles = require('../lib/cloudfiles'),
helpers = require('./helpers');
var testData = {}, client = helpers.createClient(),
sampleData = fs.readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')).toString();
vows.describe('node-cloudfiles/storage-object').addBatch(helpers.requireAuth(client)).addBatch({
"The node-cloudfiles client": {
"the addFile() method": {
topic: function () {
var ustream = client.addFile('test_container', {
remote: 'file1.txt',
local: path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')
}, function () { });
ustream.on('end', this.callback);
},
"should raise the `end` event": function () {
assert.isTrue(true);
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the addFile() method called a second time": {
topic: function () {
var ustream = client.addFile('test_container', {
remote: 'file2.txt',
local: path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')
}, function () { });
ustream.on('end', this.callback)
},
"should raise the `end` event": function () {
assert.isTrue(true);
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the addFile() method with a pre-provided read stream": {
topic: function () {
var fileName = path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt'),
readStream = fs.createReadStream(fileName),
headers = { 'content-length': fs.statSync(fileName).size },
ustream;
ustream = client.addFile('test_container', {
remote: 'file3.txt',
stream: readStream,
headers: headers
}, this.callback);
ustream.on('end', this.callback);
},
"should raise the `end` event": function () {
assert.isTrue(true);
}
},
"the addFile() method using a stream without a predefined length": {
topic: function () {
var fileName = path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt'),
readStream = fs.createReadStream(fileName),
ustream;
ustream = client.addFile('test_container', {
remote: 'file3.txt',
stream: readStream
}, this.callback);
ustream.on('end', this.callback);
},
"should raise the `end` event": function () {
assert.isTrue(true);
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the addFile() method": {
topic: function () {
client.addFile('test_container', {
remote: 'file3.txt',
local: path.join(__dirname, '..', 'test', 'fixtures', 'fillerama.txt')
}, this.callback);
},
"returns the response": function(err, response) {
assert.equal(typeof response, 'object');
assert.isTrue('headers' in response);
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the getFiles() method": {
topic: function () {
client.getFiles('test_container', this.callback);
},
"should return a valid list of files": function (err, files) {
files.forEach(function (file) {
helpers.assertFile(file);
});
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the getFile() method": {
"for a file that exists": {
topic: function () {
client.getFile('test_container', 'file2.txt', this.callback);
},
"should return a valid StorageObject": function (err, file) {
helpers.assertFile(file);
testData.file = file;
}
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"an instance of StorageObject": {
"the save() method": {
topic: function () {
var self = this;
testData.file.save({ local: path.join(__dirname, 'fixtures', 'fillerama3.txt') }, function (err, filename) {
if (err) {
return self.callback(err);
}
fs.stat(filename, self.callback)
});
},
"should write the file to the specified location": function (err, stats) {
assert.isNull(err);
assert.isNotNull(stats);
}
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"the destroyFile() method": {
"for a file that exists": {
topic: function () {
client.destroyFile('test_container', 'file1.txt', this.callback);
},
"should return true": function (err, deleted) {
assert.isTrue(deleted);
}
}
, "for a file that does not exist": {
topic: function () {
client.destroyFile('test_container', 'file0.txt', this.callback);
},
"should return error": function (err, deleted) {
assert.ok(err instanceof Error);
}
}
}
}
}).addBatch({
"The node-cloudfiles client": {
"an instance of a StorageObject": {
"the destroy() method": {
"for a file that exists": {
topic: function () {
testData.file.destroy(this.callback);
},
"should return true": function (err, deleted) {
assert.isTrue(deleted);
}
}
}
}
}
}).export(module);