Skip to content

Commit

Permalink
Cleanup tests a bit.
Browse files Browse the repository at this point in the history
Moved from ./auth to ./test/auth.json. Sorry for the one-time pain.
  • Loading branch information
domenic committed Oct 27, 2012
1 parent a172697 commit 1020200
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 38 deletions.
5 changes: 1 addition & 4 deletions .gitignore
@@ -1,6 +1,3 @@
.DS_Store
test.js
/auth
/test/auth.json
/node_modules/
/npm-debug.log
.idea
6 changes: 1 addition & 5 deletions .npmignore
@@ -1,12 +1,8 @@
# From .gitignore
.DS_Store
test.js
/auth
/node_modules/
/npm-debug.log

# Additions for .npmignore only
/test
/test/
/.npmignore
/History.md
/index.html
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Expand Up @@ -242,8 +242,8 @@ If you want to use a custom [HTTP agent][], you can specify this with the

## Running Tests

To run the test suite you must first have an S3 account, and create
a file named _./auth_, which contains your credentials as json, for example:
To run the test suite you must first have an S3 account. Then create a file named
_./test/auth.json_, which contains your credentials as JSON, for example:

```json
{
Expand Down
47 changes: 21 additions & 26 deletions test/knox.test.js
@@ -1,8 +1,3 @@

/**
* Module dependencies.
*/

var knox = require('..')
, signQuery = require('../lib/auth').signQuery
, fs = require('fs')
Expand All @@ -11,7 +6,7 @@ var knox = require('..')
, crypto = require('crypto');

try {
var auth = JSON.parse(fs.readFileSync('auth', 'ascii'));
var auth = require("./auth.json");
var client = knox.createClient(auth);
auth.bucket = auth.bucketUsWest2;
// Without this we get a 307 redirect
Expand All @@ -23,12 +18,12 @@ try {
var clientUsWest2 = knox.createClient(auth);
} catch (err) {
console.error(err);
console.error('The tests require ./auth to contain a JSON string with');
console.error('key, secret, bucket and bucketUsWest2 in order to run tests.');
console.error('Both bucket and bucketUsWest2 must exist and should not');
console.error('contain anything you want to keep. bucket2 should be');
console.error('created in the us-west-2 (Oregon) region, not the default');
console.error('region.');
console.error('The tests require ./auth to contain a JSON string with key, ' +
'secret, bucket, and bucketUsWest2 in order to run tests. ' +
'Both bucket and bucketUsWest2 must exist and should not ' +
'contain anything you want to keep. bucketUsWest2 should be ' +
'created in the us-west-2 (Oregon) region, not the default ' +
'region.');
process.exit(1);
}

Expand All @@ -53,7 +48,7 @@ module.exports = {

assert.throws(
function () {
knox.createClient({ key: 'foo', secret: 'bar', bucket: 'BuCkEt' })
knox.createClient({ key: 'foo', secret: 'bar', bucket: 'BuCkEt' });
},
/bucket names must be all lower case/
);
Expand Down Expand Up @@ -171,7 +166,7 @@ module.exports = {
done();
});
req.end(buf);
})
});
});
},

Expand Down Expand Up @@ -203,7 +198,7 @@ module.exports = {
if (100 !== res.statusCode) assert.equal(200, res.statusCode);
done();
});
})
});
},

'test .putStream() with http stream': function(done){
Expand Down Expand Up @@ -297,26 +292,26 @@ module.exports = {
client.getFile('/test/user.json', function(err, res){
assert.ok(!err);
assert.equal(200, res.statusCode);
assert.equal('application/json', res.headers['content-type'])
assert.equal(13, res.headers['content-length'])
assert.equal('application/json', res.headers['content-type']);
assert.equal(13, res.headers['content-length']);
done();
});
},

'test .get()': function(done){
client.get('/test/user4.json').on('response', function(res){
assert.equal(200, res.statusCode);
assert.equal('application/json', res.headers['content-type'])
assert.equal(13, res.headers['content-length'])
assert.equal('application/json', res.headers['content-type']);
assert.equal(13, res.headers['content-length']);
done();
}).end();
},

'test .get() without leading slash': function(done){
client.get('buffer.txt').on('response', function(res){
assert.equal(200, res.statusCode);
assert.equal('text/plain', res.headers['content-type'])
assert.equal(17, res.headers['content-length'])
assert.equal('text/plain', res.headers['content-type']);
assert.equal(17, res.headers['content-length']);
done();
}).end();
},
Expand All @@ -334,8 +329,8 @@ module.exports = {
'test .head()': function(done){
client.head('/test/user.json').on('response', function(res){
assert.equal(200, res.statusCode);
assert.equal('application/json', res.headers['content-type'])
assert.equal(13, res.headers['content-length'])
assert.equal('application/json', res.headers['content-type']);
assert.equal(13, res.headers['content-length']);
done();
}).end();
},
Expand All @@ -344,8 +339,8 @@ module.exports = {
client.headFile('/test/user.json', function(err, res){
assert.ok(!err);
assert.equal(200, res.statusCode);
assert.equal('application/json', res.headers['content-type'])
assert.equal(13, res.headers['content-length'])
assert.equal('application/json', res.headers['content-type']);
assert.equal(13, res.headers['content-length']);
done();
});
},
Expand Down Expand Up @@ -450,7 +445,7 @@ module.exports = {
'test .signedUrl()': function(){
// Not much of a test, but hopefully will prevent regressions (see GH-81)
var date = new Date(2020, 1, 1);
var timestamp = date.getTime() * .001;
var timestamp = date.getTime() * 0.001;
var signedUrl = client.signedUrl('/test/user.json', date);
var signature = signQuery({
secret: client.secret
Expand Down
3 changes: 2 additions & 1 deletion test/mocha.opts
@@ -1,3 +1,4 @@
--ui exports
--slow 500ms
--slow 1000ms
--timeout 5000ms
--reporter spec

0 comments on commit 1020200

Please sign in to comment.