Permalink
Browse files

Add basic unit tests and check Makefile target

Change-Id: I6d5489fc29ed260f1d3c981b0310441fb04c559b
Reviewed-on: http://review.couchbase.org/19720
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent 6068aee commit 39cb08f0b47e218ffc8fe24676e4a51eba7edaf3 @mnunberg mnunberg committed with trondn Aug 16, 2012
Showing with 83 additions and 0 deletions.
  1. +3 −0 Makefile
  2. +61 −0 tests/00-args.t.js
  3. +13 −0 tests/params.js
  4. +6 −0 tests/runtests.sh
View
@@ -17,6 +17,9 @@ install:
dist:
@node-waf dist
+check:
+ ./tests/runtests.sh tests/*t.js
+
reformat:
@astyle --mode=c \
--quiet \
View
@@ -0,0 +1,61 @@
+var params = require('./params');
+var cb = params.create_handle();
+
+
+// Verify simple stuff don't crap out:
+cb._opCallStyle('dict');
+cb.get("foo", function(){});
+cb.set("foo", "bar", function(){});
+cb.delete("foo", function(){});
+cb.arithmetic("foo", 0, function(){});
+
+
+// These things should fail:
+
+function must_fail(fn, args) {
+ var exc = null;
+ try {
+ fn.apply(cb, args);
+ } catch (err) {
+ exc = err;
+ }
+ if (!exc) {
+ msg = "Expected error for arguments " +
+ args + " and function " + fn.name;
+ throw msg;
+ }
+};
+
+// Must have callback
+must_fail(cb.get, ["foo"]);
+must_fail(cb.set, ["foo"]);
+
+// CAS processing...
+must_fail(cb.set, ["foo", "bar", function(){}, { cas : "invalid"} ]);
+
+
+// Ensure all these false-ish values don't error for cas or expiry..
+var falsevals = [null, undefined, 0, false];
+for (var ii = 0; ii < falsevals.length; ii++) {
+ var fv = falsevals[ii];
+ try {
+ cb.set("foo", "bar", function(){},
+ { exp : fv, cas : fv });
+ } catch (err) {
+ throw err + " for value " + fv;
+ }
+}
+
+// Check that the positional tests work..
+cb._opCallStyle('positional');
+cb.get("foo", 0, function(){});
+cb.set("foo", "bar", 0, 0, function(){});
+cb.delete("foo", 0, function(){});
+cb.arithmetic("foo", 0, 0, 0, 0, function(){});
+
+must_fail(cb.get, ["foo"]);
+must_fail(cb.set, ["foo", "bar"]);
+must_fail(cb.arithmetic, ["foo"]);
+must_fail(cb.remove, ["foo"]);
+
+process.exit(0);
View
@@ -54,3 +54,16 @@ exports.parse_cliargs = function () {
ii++;
}
};
+
+exports.create_handle = function() {
+ var driver = require('couchbase');
+ exports.parse_cliargs();
+
+ var cb = new driver.Couchbase(
+ exports.params['hostname'],
+ exports.params['username'],
+ exports.params['password'],
+ exports.params['bucket']
+ );
+ return cb;
+};
View
@@ -0,0 +1,6 @@
+#!/bin/sh
+for t in $@; do
+ node $t
+ rv=$?
+ test $rv -eq 0 && echo "$t .. OK" || echo "$t .. FAIL"
+done

0 comments on commit 39cb08f

Please sign in to comment.