Skip to content

Commit

Permalink
Start upgrading test suite to mocha
Browse files Browse the repository at this point in the history
Fixed bugs introduced in 0.0.8
Also, bind is fucking fail :()
  • Loading branch information
3rd-Eden committed Apr 10, 2012
1 parent 3c0a18b commit a303003
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 28 deletions.
17 changes: 13 additions & 4 deletions Makefile
@@ -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
42 changes: 23 additions & 19 deletions lib/memcached.js
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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 : '') +
Expand All @@ -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]
Expand All @@ -775,7 +779,7 @@ Client.config = {
]
);

memcached.replace = privates.setters.bind(memcached
memcached.replace = curry(undefined, privates.setters
, 'replace'
, [
['key', String]
Expand All @@ -785,7 +789,7 @@ Client.config = {
]
);

memcached.add = privates.setters.bind(memcached
memcached.add = curry(undefined, privates.setters
, 'add'
, [
['key', String]
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions package.json
@@ -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"
Expand All @@ -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.