forked from OptimalBits/node_acl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getAll contract and tests, implementation for redis.
- Loading branch information
Showing
5 changed files
with
162 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules/* | ||
.DS_Store | ||
*~ | ||
.idea/ | ||
.idea/ | ||
.tags* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,88 @@ | ||
/** | ||
Backend Interface. | ||
Implement this API for providing a backend for the acl module. | ||
Backend Interface. | ||
Implement this API for providing a backend for the acl module. | ||
*/ | ||
|
||
var contract = require('./contract'); | ||
|
||
var Backend = { | ||
/** | ||
/** | ||
Begins a transaction. | ||
*/ | ||
begin : function(){ | ||
// returns a transaction object | ||
}, | ||
|
||
/** | ||
Ends a transaction (and executes it) | ||
*/ | ||
end : function(transaction, cb){ | ||
contract(arguments).params('object', 'function').end(); | ||
contract(arguments).params('object', 'function').end(); | ||
// Execute transaction | ||
}, | ||
|
||
/** | ||
Cleans the whole storage. | ||
*/ | ||
clean : function(cb){ | ||
contract(arguments).params('function').end(); | ||
}, | ||
|
||
/** | ||
Gets the contents at the bucket's key. | ||
*/ | ||
get : function(bucket, key, cb){ | ||
contract(arguments) | ||
.params('string', 'string|number', 'function') | ||
.end(); | ||
contract(arguments) | ||
.params('string', 'string|number', 'function') | ||
.end(); | ||
}, | ||
|
||
/** | ||
Returns the union of the values in the given keys. | ||
*/ | ||
/** | ||
Gets the contents of the specified keys and returns them in the same order | ||
passed. | ||
*/ | ||
getAll : function(bucket, keys, cb){ | ||
contract(arguments) | ||
.params('string', 'array', 'function') | ||
.end(); | ||
}, | ||
|
||
/** | ||
Returns the union of the values in the given keys. | ||
*/ | ||
union : function(bucket, keys, cb){ | ||
contract(arguments) | ||
.params('string', 'array', 'function') | ||
.end(); | ||
}, | ||
.params('string', 'array', 'function') | ||
.end(); | ||
}, | ||
|
||
/** | ||
Adds values to a given key inside a bucket. | ||
*/ | ||
add : function(transaction, bucket, key, values){ | ||
contract(arguments) | ||
.params('object', 'string', 'string|number','string|array|number') | ||
Adds values to a given key inside a bucket. | ||
*/ | ||
add : function(transaction, bucket, key, values){ | ||
contract(arguments) | ||
.params('object', 'string', 'string|number','string|array|number') | ||
.end(); | ||
}, | ||
}, | ||
|
||
/** | ||
Delete the given key(s) at the bucket | ||
*/ | ||
del : function(transaction, bucket, keys){ | ||
contract(arguments) | ||
.params('object', 'string', 'string|array') | ||
.end(); | ||
contract(arguments) | ||
.params('object', 'string', 'string|array') | ||
.end(); | ||
}, | ||
/** | ||
Removes values from a given key inside a bucket. | ||
*/ | ||
remove : function(transaction, bucket, key, values){ | ||
contract(arguments) | ||
.params('object', 'string', 'string|number','string|array|number') | ||
|
||
/** | ||
Removes values from a given key inside a bucket. | ||
*/ | ||
remove : function(transaction, bucket, key, values){ | ||
contract(arguments) | ||
.params('object', 'string', 'string|number','string|array|number') | ||
.end(); | ||
}, | ||
}, | ||
} | ||
|
||
exports = module.exports = Backend; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var chai = require('chai'); | ||
var assert = chai.assert; | ||
var expect = chai.expect; | ||
var _ = require('lodash'); | ||
|
||
var testData = { | ||
key1: ["1", "2", "3"], | ||
key2: ["4", "5", "6"], | ||
key3: ["7", "8", "9"] | ||
}; | ||
var bucket = 'test-bucket'; | ||
|
||
exports.getAll = function() { | ||
describe('getAll', function() { | ||
before(function(done) { | ||
var backend = this.backend; | ||
if (!backend.getAll) { | ||
this.skip(); | ||
} | ||
|
||
backend.clean(function() { | ||
var transaction = backend.begin(); | ||
Object.keys(testData).forEach(function(key) { | ||
backend.add(transaction, bucket, key, testData[key]); | ||
}); | ||
backend.end(transaction, done); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
this.backend.clean(done); | ||
}); | ||
|
||
it('should respond with an appropriate map', function(done) { | ||
this.backend.getAll(bucket, Object.keys(testData), function(err, result) { | ||
expect(err).to.be.null; | ||
expect(result).to.be.eql(testData); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get only the specified keys', function(done) { | ||
this.backend.getAll(bucket, ['key1'], function(err, result) { | ||
expect(err).to.be.null; | ||
expect(result).to.be.eql(_.pick(testData, 'key1')); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should be order-independent', function(done) { | ||
this.backend.getAll(bucket, Object.keys(testData).reverse(), function(err, result) { | ||
expect(err).to.be.null; | ||
expect(result).to.be.eql(testData); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.