Skip to content

Commit

Permalink
removed keys.json dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Sep 19, 2012
1 parent 84442bb commit e485067
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 56 deletions.
120 changes: 65 additions & 55 deletions test/keys.unit.js
@@ -1,59 +1,69 @@
var Keys = require('../lib/keys');
var Keys = require('../lib/keys')
, KEY_FILE = __dirname + '/support/keys.json'
, fs = require('fs');

describe('Keys', function() {

describe('.get(key, callback)', function() {
it('should return a key if it exists', function(done) {
var keys = new Keys(__dirname + '/support/keys.json');

keys.get('abcdefghijklmnopqrstuvwxyz', function(err, exists) {
expect(exists).to.equal(true);
done(err);
});
});

it('should not throw if the file does not exist', function(done) {
var keys = new Keys(__dirname + '/support/file-doesnt-exist.json');

keys.get('abcdefghijklmnopqrstuvwxyz', function(err, exists) {
expect(exists).to.equal(undefined);
done(err);
});
});
});

describe('.generate()', function() {
it('should create a new key', function() {
var keys = new Keys()
, key = keys.generate();

expect(key).to.exist;
expect(key.length).to.equal(512);
});
});

describe('.create(callback)', function() {
it('create a new key which should then exist', function(done) {
var keys = new Keys(__dirname + '/support/keys.json');

keys.create(function(err, key) {
expect(err).to.not.exist;
keys.get(key, function(err, exists) {
expect(exists).to.equal(true);
done(err);
});
});
});
});

describe('.getLocal(fn)', function() {
it('should get the first local key', function(done) {
var keys = new Keys(__dirname + '/support/keys.json');
keys.getLocal(function(err, key) {
expect(key).to.exist;
expect(key.length).to.equal(26);
done(err);
});
});
});
before(function () {
fs.writeFileSync(KEY_FILE, JSON.stringify({abcdefghijklmnopqrstuvwxyz: true}));
});

after(function () {
sh.rm(KEY_FILE);
});

describe('.get(key, callback)', function() {
it('should return a key if it exists', function(done) {
var keys = new Keys(KEY_FILE);

keys.get('abcdefghijklmnopqrstuvwxyz', function(err, exists) {
expect(exists).to.equal(true);
done(err);
});
});

it('should not throw if the file does not exist', function(done) {
var keys = new Keys(__dirname + '/support/file-doesnt-exist.json');

keys.get('abcdefghijklmnopqrstuvwxyz', function(err, exists) {
expect(exists).to.equal(undefined);
done(err);
});
});
});

describe('.generate()', function() {
it('should create a new key', function() {
var keys = new Keys()
, key = keys.generate();

expect(key).to.exist;
expect(key.length).to.equal(512);
});
});

describe('.create(callback)', function() {
it('create a new key which should then exist', function(done) {
var keys = new Keys(__dirname + '/support/keys.json');

keys.create(function(err, key) {
expect(err).to.not.exist;
keys.get(key, function(err, exists) {
expect(exists).to.equal(true);
done(err);
});
});
});
});

describe('.getLocal(fn)', function() {
it('should get the first local key', function(done) {
var keys = new Keys(__dirname + '/support/keys.json');
keys.getLocal(function(err, key) {
expect(key).to.exist;
expect(key.length).to.equal(26);
done(err);
});
});
});
});
1 change: 0 additions & 1 deletion test/support/keys.json

This file was deleted.

0 comments on commit e485067

Please sign in to comment.