Permalink
Browse files

Start upgrading test suite to mocha

Fixed bugs introduced in 0.0.8
Also, bind is fucking fail :()
  • Loading branch information...
1 parent 3c0a18b commit a3030032184519cb753280ec203d6614a314ce64 @3rd-Eden committed Apr 10, 2012
Showing with 55 additions and 28 deletions.
  1. +13 −4 Makefile
  2. +23 −19 lib/memcached.js
  3. +10 −0 lib/utils.js
  4. +9 −5 package.json
View
@@ -1,7 +1,16 @@
-doc:
- dox --title "node-memcached" lib/* > doc/index.html
+ALL_TESTS = $(shell find tests -name '*.test.js')
+REPORTER = spec
+UI = bdd
test:
- expresso -I lib $(TESTFLAGS) tests/*.test.js
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter $(REPORTER) \
+ --ui $(UI) \
+ --growl \
+ $(ALL_TESTS)
+
+doc:
+ dox --title "node-memcached" lib/* > doc/index.html
-.PHONY: test doc
+.PHONY: test doc
View
@@ -18,6 +18,12 @@ var HashRing = require('hashring')
, Manager = Connection.Manager
, IssueLog = Connection.IssueLog;
+/**
+ * Variable lookups
+ */
+
+var curry = Utils.curry;
+
/**
* Constructs a new memcached client
*
@@ -154,7 +160,7 @@ Client.config = {
, error: function streamError (err) {
memcached.connectionIssue(err, S, callback);
}
- , data: privates.buffer.bind(memcached, S)
+ , data: curry(memcached, privates.buffer, S)
, timeout: function streamTimeout () {
Manager.remove(this);
}
@@ -688,13 +694,12 @@ Client.config = {
memcached.getMulti = function getMulti(keys, callback) {
var memcached = this
, responses = {}
- , errors = null
+ , errors = []
, calls;
// handle multiple responses and cache them untill we receive all.
function handle (err, results) {
if (err) {
- errors = errors || [];
errors.push(err);
}
@@ -727,7 +732,6 @@ Client.config = {
// enough to ignore those.
privates.setters = function setters (type, validate, key, value, lifetime, callback, cas) {
var flag = 0
- , memcached = this
, valuetype = typeof value
, length;
@@ -742,11 +746,11 @@ Client.config = {
}
length = Buffer.byteLength(value);
- if (length > memcached.maxValue) {
- return privates.errorResponse('The length of the value is greater than ' + memcached.maxValue, callback);
+ if (length > this.maxValue) {
+ return privates.errorResponse('The length of the value is greater than ' + this.maxValue, callback);
}
- memcached.command(function settersCommand (noreply) {
+ this.command(function settersCommand (noreply) {
return {
key: key
, callback: callback
@@ -755,7 +759,7 @@ Client.config = {
, cas: cas
, validate: validate
, type: type
- , redundancyEnabled: true
+ , redundancyEnabled: false
, command: [type, key, flag, lifetime, length].join(' ') +
(cas ? ' ' + cas : '') +
(noreply ? NOREPLY : '') +
@@ -765,7 +769,7 @@ Client.config = {
};
// Curry the function and so we can tell the type our private set function
- memcached.set = privates.setters.bind(memcached
+ memcached.set = curry(undefined, privates.setters
, 'set'
, [
['key', String]
@@ -775,7 +779,7 @@ Client.config = {
]
);
- memcached.replace = privates.setters.bind(memcached
+ memcached.replace = curry(undefined, privates.setters
, 'replace'
, [
['key', String]
@@ -785,7 +789,7 @@ Client.config = {
]
);
- memcached.add = privates.setters.bind(memcached
+ memcached.add = curry(undefined, privates.setters
, 'add'
, [
['key', String]
@@ -865,8 +869,8 @@ Client.config = {
};
// Curry the function and so we can tell the type our private incrdecr
- memcached.increment = memcached.incr = privates.incrdecr.bind(memcached, 'incr');
- memcached.decrement = memcached.decr = privates.incrdecr.bind(memcached, 'decr');
+ memcached.increment = memcached.incr = curry(undefined, privates.incrdecr, 'incr');
+ memcached.decrement = memcached.decr = curry(undefined, privates.incrdecr, 'decr');
// Deletes the keys from the servers
memcached.del = function del (key, callback){
@@ -920,12 +924,12 @@ Client.config = {
};
// Curry the function and so we can tell the type our private singles
- memcached.version = privates.singles.bind(memcached, 'version');
- memcached.flush = privates.singles.bind(memcached, 'flush_all');
- memcached.stats = privates.singles.bind(memcached, 'stats');
- memcached.settings = privates.singles.bind(memcached, 'stats settings');
- memcached.slabs = privates.singles.bind(memcached, 'stats slabs');
- memcached.items = privates.singles.bind(memcached, 'stats items');
+ memcached.version = curry(undefined, privates.singles, 'version');
+ memcached.flush = curry(undefined, privates.singles, 'flush_all');
+ memcached.stats = curry(undefined, privates.singles, 'stats');
+ memcached.settings = curry(undefined, privates.singles, 'stats settings');
+ memcached.slabs = curry(undefined, privates.singles, 'stats slabs');
+ memcached.items = curry(undefined, privates.singles, 'stats items');
// aliases
memcached.flushAll = memcached.flush;
View
@@ -78,6 +78,16 @@ exports.merge = function merge (target, obj) {
return target;
};
+// curry/bind functions
+exports.curry = function curry (context, fn) {
+ var copy = Array.prototype.slice
+ , args = copy.call(arguments, 2);
+
+ return function bowlofcurry () {
+ return fn.apply(context || this, args.concat(copy.call(arguments)));
+ };
+};
+
// a small items iterator
exports.Iterator = function iterator (collection, callback) {
var arr = Array.isArray(collection)
View
@@ -1,6 +1,6 @@
{
"name": "memcached"
- , "version": "0.0.8"
+ , "version": "0.0.9"
, "author": "Arnout Kazemier"
, "description": "A fully featured Memcached API client, supporting both single and clustered Memcached servers through consistent hashing and failover/failure. Memcached is rewrite of nMemcached, which will be deprecated in the near future."
, "main": "index"
@@ -26,14 +26,18 @@
, "url": "http://www.3rd-Eden.com"
}]
, "license": {
- "type": "MIT"
- , "url": "http://github.com/3rd-Eden/node-memcached/blob/master/LICENSE"
+ "type": "MIT"
+ , "url": "http://github.com/3rd-Eden/node-memcached/blob/master/LICENSE"
}
, "repository": {
- "type": "git"
- , "url" : "http://github.com/3rd-Eden/node-memcached.git"
+ "type": "git"
+ , "url" : "http://github.com/3rd-Eden/node-memcached.git"
}
, "dependencies": {
"hashring": "*"
}
+ , "devDependencies": {
+ "mocha": "*"
+ , "should": "*"
+ }
}

0 comments on commit a303003

Please sign in to comment.