-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
100 lines (90 loc) · 3.21 KB
/
Copy pathtest.js
File metadata and controls
100 lines (90 loc) · 3.21 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
'use strict';
var util = require('util');
var http = require('http');
var events = require('events');
var test = require('tape');
var nodes3 = require('./');
test('should correctly parse a string', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com/prefix');
t.equal(s3.pathname, '/prefix', 'have prefix');
t.equal(s3.bucket, 'bucket', 'have bucket');
t.end();
});
test('should correctly parse an object', function (t) {
var options = {
key: 'key',
secret: 'secret',
bucket: 'bucket',
pathname: '/prefix'
};
var s3 = nodes3(options);
t.equal(s3.pathname, '/prefix', 'have prefix');
t.equal(s3.bucket, 'bucket', 'have bucket');
t.end();
});
test('should not require a prefix', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
t.equal(s3.pathname, '', 'have empty pathname');
var options = {
key: 'key',
secret: 'secret',
bucket: 'bucket'
};
s3 = nodes3(options);
t.equal(s3.pathname, '', 'have empty pathname');
t.end();
});
test('should require key/secret', function (t) {
var fn = function () {
nodes3('s3://bucket.s3.amazonaws.com');
}
t.throws(fn, 'S3 key and secret are required!');
t.end();
});
test('should expose 5 HTTP verbs as functions', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
t.equal(typeof s3.put, 'function', 'PUT');
t.equal(typeof s3.post, 'function', 'POST');
t.equal(typeof s3.get, 'function', 'GET');
t.equal(typeof s3.del, 'function', 'DELETE');
t.equal(typeof s3.head, 'function', 'HEAD');
t.end();
});
test('should return an EventEmitter', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
var req = s3.head('/foo');
t.ok(req instanceof events.EventEmitter, 'return an EventEmitter');
t.end();
});
test('should complete a HEAD request', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
s3.head('/foo', function (err, res, body) {
t.equal(err, null, 'have no error');
t.ok(res instanceof http.IncomingMessage, 'have an IncomingMessage');
t.equal(body, '', 'have no body');
t.equal(res.statusCode, 403, 'give 403 status-code');
t.end();
});
});
test('should complete a GET request', function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
s3.get('/foo', function (err, res, body) {
t.equal(err, null, 'have no error');
t.ok(res instanceof http.IncomingMessage, 'have an IncomingMessage');
t.ok(!!~body.indexOf('<Code>InvalidAccessKeyId</Code>'), 'respond with InvalidAccessKeyId');
t.equal(res.statusCode, 403, 'give 403 status-code');
t.end();
});
});
[{ body: 'foobar' }, 'foobar', new Buffer('foobar')].forEach(function (options) {
test('should complete a POST request with: ' + util.inspect(options), function (t) {
var s3 = nodes3('s3://key:secret@bucket.s3.amazonaws.com');
s3.post('/foo', options, function (err, res, body) {
t.equal(err, null, 'have no error');
t.ok(res instanceof http.IncomingMessage, 'have an IncomingMessage');
t.ok(!!~body.indexOf('<Code>InvalidAccessKeyId</Code>'), 'respond with InvalidAccessKeyId');
t.equal(res.statusCode, 403, 'give 403 status-code');
t.end();
});
});
});