Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Mar 26, 2012
1 parent af7e785 commit e2d5b81
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ Requires ```Content-Type``` and ```Content-Length``` headers
## s3.ls(path, callback)

List files with a given prefix (path). Do NOT use a leading slash.

# Run Tests
Ensure you have mocha installed.

npm install mocha

Add a config file for s3asy to use in ```~/.s3asy_test_config.js```.

module.exports = {
key: '<api-key-here>',
secret: '<secret-here>',
bucket: 'bucket-name',
cache: true
};

Run tests

cd test
mocha test.js --reporter spec
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Andrew J. Stone <andrew.j.stone.1@gmail.com>",
"name": "s3asy",
"description": "Simple S3 integration with a cache backed by Redis",
"version": "0.3.0",
"version": "0.4.0",
"repository": {
"type": "git",
"url": "git://github.com/andrewjstone/s3asy.git"
Expand All @@ -17,5 +17,7 @@
"async": "*",
"sax": "*"
},
"devDependencies": {}
"devDependencies": {
"mocha": "*"
}
}
52 changes: 52 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var S3 = require('../index');
var config = require(process.env.HOME+'/.s3asy_test_config');
var assert = require('assert');

var s3 = new S3(config);
s3.cache.default_ttl = 1;

var original = 'Hello World!';

describe('s3asy', function() {

// Basic Tests
it('can put a file', function(done) {
s3.put('/test/s3asy', {
'Content-Type': 'text/plain',
'Content-Length': original.length
}, original, function(err) {
assert.ok(!err);
done();
});
});

it('can retrieve the same file', function(done) {
s3.get('/test/s3asy', function(err, data) {
assert.ok(!err);
assert.equal(data, original);
done();
});
});

// Cache tests
it('has the file cached', function(done) {
s3.cache.get('/test/s3asy', function(err, data) {
assert.ok(!err);
assert.equal(data, original);
done();
});
});

it('does not have the file cached after 2 seconds', function(done) {
this.timeout(5000);
setTimeout(function() {
s3.cache.get('/test/s3asy', function(err, data) {
assert.ok(!err);
assert.deepEqual(data, undefined);
done();
});
}, 2000);
});

});

0 comments on commit e2d5b81

Please sign in to comment.