Permalink
Browse files

[tests] tests are now mocks

  • Loading branch information...
2 parents 4b17e66 + 36549d1 commit f56684e7036af0b936353c7507fdd55d8a92a024 @dscape committed Dec 3, 2011
View
1 README.md
@@ -199,6 +199,7 @@ where `list_doc_params` is the test name.
* code: `git clone git://github.com/dscape/nano.git`
* home: <http://github.com/dscape/nano>
* bugs: <http://github.com/dscape/nano/issues>
+* build: [![build status](https://secure.travis-ci.org/dscape/nano.png)](http://travis-ci.org/dscape/nano)
`(oO)--',-` in [caos][3]
View
2 nano.js
@@ -263,7 +263,7 @@ module.exports = exports = nano = function database_module(cfg) {
callback = design_name;
design_name = null;
}
- return relax({db: db_name, path: ("_compact" + design_name), method: "POST"},callback);
+ return relax({db: db_name, doc: "_compact", att: design_name, method: "POST"},callback);
}
/*
View
11 package.json
@@ -4,16 +4,17 @@
, "repository" : "git://github.com/dscape/nano"
, "version" : "0.9.8"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"
-, "contributors" :
+, "contributors" :
[ "Thiago Arrais <thiago.arrais@gmail.com> (http://thiagoarrais.com)"
, "Derek Perez <derek@derekperez.com> (http://blog.derekperez.com)"
, "Patrick Heneise (http://patrickheneise.me)"
, "Artur Konarski (http://tarantoga.com)"
- , "Pedro Teixeira <pedro.teixeira@gmail.com (http://metaduck.com)"
+ , "Pedro Teixeira <pedro.teixeira@gmail.com> (http://metaduck.com)"
]
-, "keywords" : ["couchdb", "data", "request", "json", "nosql", "micro", "nano"]
-, "dependencies" : {"request": "2.2.9", "underscore": "~1.1.7"}
-, "devDependencies" : { "async": "~0.1.9", "ensure": "0.4.6" }
+, "keywords" :
+ ["couchdb", "data", "request", "json", "nosql", "micro", "nano", "database"]
+, "dependencies" : {"request": "2.2.0", "underscore": "~1.1.7"}
+, "devDependencies" : { "async": "~0.1.9", "ensure": "0.4.6", "nock": "0.5.x"}
, "scripts" : { "test": "./node_modules/ensure/bin/tap.js tests/*/*.js" }
, "main" : "./nano.js"
, "engines" : { "node": ">=0.3.6" }
View
44 tests/att/destroy.js
@@ -3,6 +3,42 @@ var ensure = require('ensure')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("att_de")
, tests = exports
+ , nock = require('nock')
+ , couchdb
+ ;
+
+ path = '/' + db_name("a");
+ location = cfg.url + path;
+ couchdb = nock(cfg.url)
+ .put('/' + db_name("a")
+ , ''
+ , { 'content-type': 'application/json'
+ , "accept": 'application/json' })
+ .reply(201, { ok: true },
+ { location: cfg.url + '/' + db_name("a")
+ , date: 'Wed, 30 Nov 2011 15:21:58 GMT'
+ , 'content-type': 'application/json'
+ , 'cache-control': 'must-revalidate'
+ , 'status-code': 201
+ })
+
+ .put(path + '/new/att', "\"Hello World!\"")
+ .reply(201, { ok: true, id: 'new', rev: '1-921bd51ccdef5ab4c84b07bab7b80e7e' },
+ { location: location + '/new/att'
+ , date: 'Wed, 30 Nov 2011 15:21:58 GMT'
+ , 'content-type': 'application/json'
+ , 'cache-control': 'must-revalidate'
+ , 'status-code': 201
+ })
+
+ .delete(path + '/new/att?rev=1-921bd51ccdef5ab4c84b07bab7b80e7e')
+ .reply(201, { ok: true, id:'new' },
+ { location: location + '/new/att?rev=1-921bd51ccdef5ab4c84b07bab7b80e7e'
+ , date: 'Wed, 30 Nov 2011 15:21:58 GMT'
+ , 'content-type': 'application/json'
+ , 'cache-control': 'must-revalidate'
+ , 'status-code': 201
+ })
;
function db(i) { return nano.use(db_name(i)); }
@@ -17,10 +53,10 @@ tests.att_des = function (callback) {
};
tests.att_des_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.equal(b.id, "new");
+ this.t.notOk(e, 'No Error');
+ this.t.ok(b.ok, 'Ok is there');
+ this.t.equal(b.id, "new", 'Id is "new"');
+ this.t.ok(couchdb.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
47 tests/att/get.js
@@ -1,33 +1,70 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("att_ge")
, tests = exports
, pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
+ , couch
;
+couch = nock(cfg.url)
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 16:34:28 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/new/att', '"Hello"')
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-5142a2e74e1ec33e6e5b621418210283\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/new/att',
+ etag: '"1-5142a2e74e1ec33e6e5b621418210283"',
+ date: 'Fri, 02 Dec 2011 16:34:29 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/new/att?rev=1-5142a2e74e1ec33e6e5b621418210283'
+ , new Buffer(pixel, 'base64').toString())
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"2-3b1f88c637fde74a486cf3ce5558b47e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/new/att',
+ etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
+ date: 'Fri, 02 Dec 2011 16:34:29 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('a') + '/new/att?rev=2-3b1f88c637fde74a486cf3ce5558b47e')
+ .reply(200, new Buffer(pixel, 'base64'), { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
+ date: 'Fri, 02 Dec 2011 16:34:30 GMT',
+ 'content-type': 'image/bmp',
+ 'content-md5': 'Ow9j2dR0Qm58Qi3z8p2w3A==',
+ 'content-length': '58',
+ 'cache-control': 'must-revalidate',
+ 'accept-ranges': 'bytes' });
+
function db(i) { return nano.use(db_name(i)); }
tests.att_get = function (callback) {
var buffer = new Buffer(pixel, 'base64');
nano.db.create(db_name("a"), function () {
db("a").attachment.insert("new", "att", "Hello", "text/plain",
function(e,b) {
- if(e) { callback(e); nano.db.destroy(db_name("a")); }
+ if(e) { callback(e); }
db("a").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev},
function (e2,b2) {
- if(e2) { callback(e2); nano.db.destroy(db_name("a")); }
+ if(e2) { callback(e2); }
db("a").attachment.get("new", "att", {rev: b2.rev}, callback);
});
});
});
};
tests.att_get_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
+ this.t.notOk(e, 'No Error');
var from_buffer = new Buffer(b, "binary").toString("base64");
- this.t.equal(from_buffer, pixel);
+ this.t.equal(from_buffer, pixel, 'Buffer is pixel');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
29 tests/att/insert.js
@@ -1,10 +1,31 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("att_in")
, tests = exports
+ , couch
;
+ couch = nock(cfg.url)
+ .put('/' + db_name("a"))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)'
+ , location: cfg.url + '/' + db_name("a")
+ , date: 'Fri, 02 Dec 2011 00:21:46 GMT'
+ , 'content-type': 'application/json'
+ , 'content-length': '12'
+ , 'cache-control': 'must-revalidate'
+ })
+ .put('/' + db_name("a") + '/new/att', '"Hello World!"')
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-921bd51ccdef5ab4c84b07bab7b80e7e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("a") + '/new/att',
+ etag: '"1-921bd51ccdef5ab4c84b07bab7b80e7e"',
+ date: 'Fri, 02 Dec 2011 00:21:46 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.att_new_doc = function (callback) {
@@ -14,10 +35,10 @@ tests.att_new_doc = function (callback) {
};
tests.att_new_doc_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.equal(b.id, "new");
+ this.t.notOk(e, 'No errrs');
+ this.t.ok(b.ok, 'Im oh a OK');
+ this.t.equal(b.id, "new", "Id is new");
+ this.t.ok(couch.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
45 tests/att/pipe.js
@@ -1,10 +1,51 @@
var ensure = require('ensure')
+ , nock = require('nock')
, fs = require('fs')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, tests = exports
, db_name = require('../utils').db_name("att_pi")
- , pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA==";
+ , pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 19:06:26 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/new/att', '"Hello"')
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-5142a2e74e1ec33e6e5b621418210283\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/new/att',
+ etag: '"1-5142a2e74e1ec33e6e5b621418210283"',
+ date: 'Fri, 02 Dec 2011 19:06:26 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put( '/' + db_name('a') +
+ '/new/att?rev=1-5142a2e74e1ec33e6e5b621418210283'
+ , new Buffer(pixel, 'base64').toString())
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"2-3b1f88c637fde74a486cf3ce5558b47e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/new/att',
+ etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
+ date: 'Fri, 02 Dec 2011 19:06:27 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('a') +
+ '/new/att?rev=2-3b1f88c637fde74a486cf3ce5558b47e')
+ .reply(200, new Buffer(pixel, 'base64'),
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"2-3b1f88c637fde74a486cf3ce5558b47e"',
+ date: 'Fri, 02 Dec 2011 19:06:27 GMT',
+ 'content-type': 'image/bmp',
+ 'content-md5': 'Ow9j2dR0Qm58Qi3z8p2w3A==',
+ 'content-length': '58',
+ 'cache-control': 'must-revalidate',
+ 'accept-ranges': 'bytes' });
function db(i) { return nano.use(db_name(i)); }
function file_name(i) { return __dirname + "/." + i + "-tmp.bmp"; }
@@ -28,9 +69,9 @@ tests.att_pipe = function (callback) {
};
tests.att_pipe_ok = function () {
- nano.db.destroy(db_name("a"));
this.t.equal(fs.readFileSync(file_name("a")).toString("base64"), pixel);
fs.unlinkSync(file_name("a"));
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
40 tests/att/update.js
@@ -1,15 +1,43 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("att_up")
+ , pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
, tests = exports
;
+ couch = nock(cfg.url)
+ .put('/' + db_name('b'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b'),
+ date: 'Fri, 02 Dec 2011 18:49:22 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/new/att', '"Hello World!"')
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"1-921bd51ccdef5ab4c84b07bab7b80e7e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/new/att',
+ etag: '"1-921bd51ccdef5ab4c84b07bab7b80e7e"',
+ date: 'Fri, 02 Dec 2011 18:49:23 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put( '/' + db_name('b') + '/new/att?rev=1-921bd51ccdef5ab4c84b07bab7b80e7e'
+ , new Buffer(pixel, 'base64').toString())
+ .reply(201, "{\"ok\":true,\"id\":\"new\",\"rev\":\"2-c6d2cd80113d505ec29430ac0859b41b\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/new/att',
+ etag: '"2-c6d2cd80113d505ec29430ac0859b41b"',
+ date: 'Fri, 02 Dec 2011 18:50:44 GMT',
+ 'content-type': 'text/plain;charset=utf-8',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.att_doc = function (callback) {
- var pixel = "Qk06AAAAAAAAADYAAAAoAAAAAQAAAP////8BABgAAAAAAAAAAAATCwAAEwsAAAAAAAAAAAAAWm2CAA=="
- , buffer = new Buffer(pixel, 'base64');
+ var buffer = new Buffer(pixel, 'base64');
nano.db.create(db_name("b"), function () {
db("b").attachment.insert("new", "att", "Hello World!", "text/plain",
function (e,b) {
@@ -21,10 +49,10 @@ tests.att_doc = function (callback) {
};
tests.att_doc_ok = function (e,b) {
- nano.db.destroy(db_name("b"));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.equal(b.id, "new");
+ this.t.notOk(e, 'No errs');
+ this.t.ok(b.ok, 'Ok');
+ this.t.equal(b.id, "new", 'Id is new');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
51 tests/db/changes.js
@@ -1,11 +1,54 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_ch")
, tests = exports
+ , couch
;
+ couch = nock(cfg.url)
+ .put('/' + db_name("a"))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("a"),
+ date: 'Fri, 02 Dec 2011 00:34:57 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("a") + '/foobar', {"foo":"bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("a") + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 00:34:58 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("a") + '/barfoo', {"bar": "foo"})
+ .reply(201, "{\"ok\":true,\"id\":\"barfoo\",\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("a") + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 00:34:58 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("a") + '/foobaz', {"foo":"baz"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("a") + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 00:34:58 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name("a") + '/_changes?since=2')
+ .reply(200, "{\"results\":[\n{\"seq\":3,\"id\":\"foobaz\",\"changes\":[{\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}]}\n],\n\"last_seq\":3}\n\n", { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"78IVA6O2WBXVUGGXYKZ7V2GBH"',
+ date: 'Fri, 02 Dec 2011 00:34:58 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.changes_db = function (callback) {
@@ -22,10 +65,10 @@ tests.changes_db = function (callback) {
};
tests.changes_db_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
- this.t.equal(b.results.length,1);
- this.t.equal(b.last_seq,3);
+ this.t.notOk(e, 'No Error');
+ this.t.equal(b.results.length,1, 'Gets one result');
+ this.t.equal(b.last_seq,3, 'Last seq is 3');
+ this.t.ok(couch.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
64 tests/db/compact.js
@@ -1,11 +1,65 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_co")
, tests = exports
+ , couch
;
+couch = nock(cfg.url)
+ .put('/' + db_name("1"))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("1") + '',
+ date: 'Fri, 02 Dec 2011 01:27:15 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("1") + '/foobar', {"foo":"bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("1") + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 01:27:15 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("1") + '/barfoo', {"bar":"foo"})
+ .reply(201, "{\"ok\":true,\"id\":\"barfoo\",\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("1") + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 01:27:15 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name("1") + '/foobaz', {"foo":"baz"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name("1") + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 01:27:15 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .delete('/' + db_name("1") + '/foobaz?rev=1-cfa20dddac397da5bf0be2b50fb472fe')
+ .reply(200, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"2-a2a31b340cec15e18fbe6c82db6d2c2a\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"2-a2a31b340cec15e18fbe6c82db6d2c2a"',
+ date: 'Fri, 02 Dec 2011 01:27:16 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .post('/' + db_name("1") + '/_compact')
+ .reply(202, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 01:27:16 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name("1") + '')
+ .reply(200, "{\"db_name\":\"" + db_name("1") + "\",\"doc_count\":3,\"doc_del_count\":0,\"update_seq\":4,\"purge_seq\":0,\"compact_running\":false,\"disk_size\":8281,\"instance_start_time\":\"1322789235294158\",\"disk_format_version\":5,\"committed_update_seq\":4}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 01:27:17 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '218',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.compact_db = function (callback) {
@@ -14,7 +68,7 @@ tests.compact_db = function (callback) {
[ function(cb) { db('1').insert({"foo": "bar"},"foobar",cb); }
, function(cb) { db('1').insert({"bar": "foo"},"barfoo",cb); }
, function(cb) { db('1').insert({"foo": "baz"},"foobaz",
- function (e,b) { db('1').destroy("foobaz", b._rev, cb); }); }
+ function (e,b) { db('1').destroy("foobaz", b.rev, cb); }); }
],
function(err, results){
db('1').compact(function () {
@@ -25,10 +79,10 @@ tests.compact_db = function (callback) {
};
tests.compact_db_ok = function (err,list) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(err);
- this.t.equal(list.doc_count, 3);
- this.t.equal(list.doc_del_count, 0);
+ this.t.notOk(err, 'No err');
+ this.t.equal(list.doc_count, 3, 'Doc count is 3');
+ this.t.equal(list.doc_del_count, 0, 'No deleted documents');
+ this.t.ok(couch.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
24 tests/db/create.js
@@ -1,19 +1,29 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_cr")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 01:44:15 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' });
+
tests.create_db = function (callback) {
- nano.db.destroy(db_name('1'), function () {
- nano.db.create(db_name('1'), callback);
- });
+ nano.db.create(db_name('1'), callback);
};
tests.create_db_ok = function (e,b) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(e);
- this.t.equal(b.ok, true);
+ this.t.notOk(e, 'Error shouldnt exist');
+ this.t.equal(b.ok, true, 'Ok must be returned');
+ this.t.ok(couch.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
25 tests/db/destroy.js
@@ -1,8 +1,26 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_de")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 01:50:45 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .delete('/' + db_name('1'))
+ .reply(200, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 01:50:46 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' });
tests.destroy_db = function (callback) {
nano.db.create(db_name('1'), function () {
@@ -11,8 +29,9 @@ tests.destroy_db = function (callback) {
};
tests.destroy_db_ok = function (e,b) {
- this.t.notOk(e);
- this.t.equal(b.ok, true);
+ this.t.notOk(e, 'Error says Yey');
+ this.t.equal(b.ok, true, '{ok: yeah}');
+ this.t.ok(couch.isDone(), 'Nock not done');
};
ensure(__filename,tests,module,process.argv[2]);
View
30 tests/db/get.js
@@ -1,8 +1,26 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_ge")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 02:00:17 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('1'))
+ .reply(200, "{\"db_name\":\"" + db_name('1') + "\",\"doc_count\":0,\"doc_del_count\":0,\"update_seq\":0,\"purge_seq\":0,\"compact_running\":false,\"disk_size\":79,\"instance_start_time\":\"1322791217213709\",\"disk_format_version\":5,\"committed_update_seq\":0}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:00:17 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '216',
+ 'cache-control': 'must-revalidate' });
tests.get_db = function (callback) {
nano.db.create(db_name('1'), function () {
@@ -14,11 +32,11 @@ tests.get_db = function (callback) {
};
tests.get_db_ok = function (e,b) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(e);
- this.t.equal(b.doc_count,0);
- this.t.equal(b.doc_del_count,0);
- this.t.equal(b.db_name,db_name('1'));
+ this.t.notOk(e, 'No errors');
+ this.t.equal(b.doc_count,0, 'No docs');
+ this.t.equal(b.doc_del_count,0, 'No deleted docs');
+ this.t.equal(b.db_name,db_name('1'), 'DB name is correct');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
26 tests/db/list.js
@@ -1,8 +1,26 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_li")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 02:15:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .get('/_all_dbs')
+ .reply(200, "[\"" + db_name('1') + "\"]\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:15:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '81',
+ 'cache-control': 'must-revalidate' });
tests.list_db = function (callback) {
nano.db.create(db_name('1'), function () {
@@ -11,9 +29,9 @@ tests.list_db = function (callback) {
};
tests.list_db_ok = function (e,b) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(e);
- this.t.notEqual(b.indexOf(db_name('1')),-1);
+ this.t.notOk(e, 'Exception free since teh last run');
+ this.t.notEqual(b.indexOf(db_name('1')),-1, 'I can haz db name?!');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
70 tests/db/replicate.js
@@ -1,9 +1,68 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("db_re")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: '' + cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 02:29:28 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '_replica')
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '_replica',
+ date: 'Fri, 02 Dec 2011 02:29:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foobaz', {"foo":"baz"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 02:29:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/barfoo', {"bar":"foo"})
+ .reply(201, "{\"ok\":true,\"id\":\"barfoo\",\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 02:29:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foobar', {"foo":"bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 02:29:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .post('/_replicate',
+ { "source": db_name('1')
+ , "target": db_name('1') + "_replica"
+ })
+ .reply(200, "{\"ok\":true,\"session_id\":\"47c3b30bde0d3bd943f5530aaec65602\",\"source_last_seq\":3,\"replication_id_version\":2,\"history\":[{\"session_id\":\"47c3b30bde0d3bd943f5530aaec65602\",\"start_time\":\"Fri, 02 Dec 2011 02:29:29 GMT\",\"end_time\":\"Fri, 02 Dec 2011 02:29:29 GMT\",\"start_last_seq\":0,\"end_last_seq\":3,\"recorded_seq\":3,\"missing_checked\":0,\"missing_found\":3,\"docs_read\":3,\"docs_written\":3,\"doc_write_failures\":0}]}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:29:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '402',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('1') + '_replica/_all_docs')
+ .reply(200, "{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}},\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}},\r\n{\"id\":\"foobaz\",\"key\":\"foobaz\",\"value\":{\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}}\r\n]}\n", { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"B0AI082A5BICTO8T8KCPEAN3Q"',
+ date: 'Fri, 02 Dec 2011 02:29:30 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' });
tests.replicate_db = function (callback) {
nano.db.create(db_name('1'), function () {
@@ -24,11 +83,10 @@ tests.replicate_db = function (callback) {
};
tests.replicate_db_ok = function (e,b) {
- nano.db.destroy(db_name('1'));
- nano.db.destroy(db_name('1')+"_replica");
- this.t.notOk(e);
- this.t.equal(b.total_rows, 3);
- this.t.ok(b.rows);
+ this.t.notOk(e, 'Y U NO ERR?');
+ this.t.equal(b.total_rows, 3, 'I have 3 rows');
+ this.t.ok(b.rows, 'And that means I have rows. Nuno is stoopid.');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
37 tests/doc/bulk.js
@@ -1,9 +1,34 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_bu")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n"
+ , { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 19:18:16 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .post('/' + db_name('a') + '/_bulk_docs'
+ , { "docs":
+ [ {"key": "baz","name": "bazzel"}
+ , {"key": "bar", "name": "barry"}
+ ]
+ })
+ .reply(201, "[{\"id\":\"b31761fe89e0d343c41d3cdbd9004eb7\",\"rev\":\"1-f5f3f3e496c72307975a69c73fd53d42\"},{\"id\":\"b31761fe89e0d343c41d3cdbd9005632\",\"rev\":\"1-8ad0e70d5e6edd474ec190eac2376bde\"}]\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 19:18:17 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '172',
+ 'cache-control': 'must-revalidate' });
function db(i) { return nano.use(db_name(i)); }
@@ -18,11 +43,11 @@ tests.bulk_docs = function (callback) {
};
tests.bulk_docs_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
- this.t.equal(b.length, 2);
- this.t.ok(b[0].id);
- this.t.ok(b[1].id);
+ this.t.notOk(e, 'No error');
+ this.t.equal(b.length, 2, 'Two docs');
+ this.t.ok(b[0].id, 'First got id');
+ this.t.ok(b[1].id, 'Second got id');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
42 tests/doc/destroy.js
@@ -1,8 +1,38 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_de")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 19:23:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foo', {"foo": "bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foo\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foo',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 19:23:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .delete('/' + db_name('1') +
+ '/foo?rev=1-4c6114c65e295552ab1019e2b046b10e')
+ .reply(200, "{\"ok\":true,\"id\":\"foo\",\"rev\":\"2-185ccf92154a9f24a4f4fd12233bf463\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"2-185ccf92154a9f24a4f4fd12233bf463"',
+ date: 'Fri, 02 Dec 2011 19:23:55 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' });
tests.destroy_doc = function (callback) {
var db = nano.use(db_name('1'));
@@ -17,11 +47,11 @@ tests.destroy_doc = function (callback) {
};
tests.destroy_doc_ok = function (e,b) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.equal(b.id, "foo");
- this.t.ok(b.rev);
+ this.t.notOk(e, 'No errors');
+ this.t.ok(b.ok, 'I got ok');
+ this.t.equal(b.id, "foo", 'Id is foo');
+ this.t.ok(b.rev, 'Got rev');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
84 tests/doc/get.js
@@ -1,8 +1,70 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_ge")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('b'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b'),
+ date: 'Fri, 02 Dec 2011 19:28:49 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 19:28:49 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/foo', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/foo',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 19:28:49 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/foo', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/foo',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 19:28:49 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('a') + '/foo')
+ .reply(200, "{\"_id\": \"foo\",\"_rev\": \"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\": \"bar\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 19:28:50 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '70',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/foo', {"foo": "bar"})
+ .reply(409,
+ "{\"error\": \"conflict\",\"reason\": \"Document update conflict.\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 19:28:50 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '58',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('b') + '/foo?revs_info=true')
+ .reply(200, "{\"_id\": \"foo\",\"_rev\": \"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\": \"bar\",\"_revs_info\": [{\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"status\": \"available\"}]}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 19:28:50 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '151',
+ 'cache-control': 'must-revalidate' });
function db(i) { return nano.use(db_name(i)); }
@@ -15,11 +77,11 @@ tests.get_doc = function (callback) {
};
tests.get_doc_ok = function (e,b) {
- nano.db.destroy(db_name('a'));
- this.t.notOk(e);
- this.t.ok(b._rev);
- this.t.equal(b._id, "foo");
- this.t.equal(b.foo, "bar");
+ this.t.notOk(e, 'No excs');
+ this.t.ok(b._rev, 'I got rev');
+ this.t.equal(b._id, "foo", 'My id is foo');
+ this.t.equal(b.foo, "bar", 'My foo is bar');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
tests.get_doc_params = function (callback) {
@@ -33,11 +95,11 @@ tests.get_doc_params = function (callback) {
};
tests.get_doc_params_ok = function (e,b) {
- nano.db.destroy(db_name('b'));
- this.t.notOk(e);
- this.t.ok(b._revs_info);
- this.t.equal(b._id, "foo");
- this.t.equal(b.foo, "bar");
+ this.t.notOk(e, 'Err, not here');
+ this.t.ok(b._revs_info, 'Got revs info');
+ this.t.equal(b._id, "foo", 'Id is food');
+ this.t.equal(b.foo, "bar", 'Bar is in foo');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
58 tests/doc/insert.js
@@ -1,10 +1,48 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_in")
, tests = exports
+ , couch
;
+ couch = nock(cfg.url)
+ .put('/' + db_name('b'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b'),
+ date: 'Fri, 02 Dec 2011 20:15:11 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: 'http://nodejsbug.iriscouch.com/v061_doc_ina',
+ date: 'Fri, 02 Dec 2011 20:15:11 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .post('/' + db_name('a'), {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"cb691f3e73482a0fb7e76bd3350037b4\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') +
+ '/cb691f3e73482a0fb7e76bd3350037b4',
+ date: 'Fri, 02 Dec 2011 20:15:11 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '95',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/some%2Fpath', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"some/path\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/some/path',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 20:15:11 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '72',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.insert_doc = function (callback) {
@@ -14,11 +52,11 @@ tests.insert_doc = function (callback) {
};
tests.insert_doc_ok = function (e,b) {
- nano.db.destroy(db_name("a"));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.ok(b.rev);
- this.t.ok(b.id);
+ this.t.notOk(e, 'No eerz');
+ this.t.ok(b.ok, 'This is ok');
+ this.t.ok(b.rev, 'I GOT REVZ');
+ this.t.ok(b.id, 'I got Id!');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
tests.insert_doc_path = function (callback) {
@@ -28,11 +66,11 @@ tests.insert_doc_path = function (callback) {
};
tests.insert_doc_path_ok = function (e,b) {
- nano.db.destroy(db_name("b"));
- this.t.notOk(e);
- this.t.ok(b.ok);
- this.t.ok(b.rev);
- this.t.equal(b.id, "some/path");
+ this.t.notOk(e, 'Y U NO Errs');
+ this.t.ok(b.ok, 'I got ok');
+ this.t.ok(b.rev, 'I got rev');
+ this.t.equal(b.id, "some/path", 'I got id, not over 21 though');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
168 tests/doc/list.js
@@ -1,11 +1,151 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_li")
, tests = exports
+ , couch
;
+ couch = nock(cfg.url)
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('c'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('c'),
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b'),
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/foobar', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobar\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/barfoo', {"bar": "foo"})
+ .reply(201, "{\"ok\": true,\"id\": \"barfoo\",\"rev\": \"1-41412c293dade3fe73279cba8b4cece4\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('c') + '/foobar', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobar\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('c') + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 20:26:29 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/foobaz', {"foo": "baz"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobaz\",\"rev\": \"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('c') + '/barfoo', {"bar": "foo"})
+ .reply(201, "{\"ok\": true,\"id\": \"barfoo\",\"rev\": \"1-41412c293dade3fe73279cba8b4cece4\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('c') + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('a') + '/_all_docs')
+ .reply(200, "{\"total_rows\": 3,\"offset\": 0,\"rows\": [\r\n{\"id\": \"barfoo\",\"key\": \"barfoo\",\"value\": {\"rev\": \"1-41412c293dade3fe73279cba8b4cece4\"}},\r\n{\"id\" :\"foobar\",\"key\": \"foobar\",\"value\": {\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}},\r\n{\"id\": \"foobaz\",\"key\": \"foobaz\",\"value\": {\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}}\r\n]}\n",
+ { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"AXA5PYPHH9S5SIRQ1NH1N0896"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/foobar', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobar\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/barfoo', {"bar": "foo"})
+ .reply(201, "{\"ok\": true,\"id\": \"barfoo\",\"rev\": \"1-41412c293dade3fe73279cba8b4cece4\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('b') + '/foobaz', {"foo": "baz"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobaz\",\"rev\": \"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('b') + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('c') + '/foobaz', {"foo": "baz"})
+ .reply(201, "{\"ok\": true,\"id\": \"foobaz\",\"rev\": \"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('c') + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .delete('/' + db_name('a'))
+ .reply(200, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('b') + '/_all_docs?limit=1')
+ .reply(200, "{\"total_rows\": 3,\"offset\": 0,\"rows\": [\r\n{\"id\": \"barfoo\",\"key\": \"barfoo\",\"value\": {\"rev\": \"1-41412c293dade3fe73279cba8b4cece4\"}}\r\n]}\n",
+ { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"7FE6ZA8SPA15QUXDRRHGRLWKO"',
+ date: 'Fri, 02 Dec 2011 20:26:30 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('c') + '/_all_docs?startkey=%22c%22')
+ .reply(200, "{\"total_rows\": 3,\"offset\": 1,\"rows\": [\r\n{\"id\": \"foobar\",\"key\": \"foobar\",\"value\": {\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}},\r\n{\"id\": \"foobaz\",\"key\": \"foobaz\",\"value\": {\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}}\r\n]}\n",
+ { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"B5NTIXF7OO6RFK10FU94G5O3Y"',
+ date: 'Fri, 02 Dec 2011 20:26:31 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' });
+
function db(i) { return nano.use(db_name(i)); }
tests.list_doc = function (callback) {
@@ -22,10 +162,10 @@ tests.list_doc = function (callback) {
};
tests.list_doc_ok = function (e,b) {
- nano.db.destroy(db_name('a'));
- this.t.notOk(e);
- this.t.equal(b.total_rows,3);
- this.t.ok(b.rows);
+ this.t.notOk(e, 'No err');
+ this.t.equal(b.total_rows,3, '3 Rows');
+ this.t.ok(b.rows, 'Got rows');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
tests.ns_list_doc = function (callback) {
@@ -46,11 +186,11 @@ tests.ns_list_doc = function (callback) {
};
tests.ns_list_doc_ok = function (e,b) {
- nano.db.destroy(db_name('b'));
- this.t.notOk(e);
- this.t.equal(b.rows.length,1);
- this.t.equal(b.total_rows,3);
- this.t.ok(b.rows);
+ this.t.notOk(e, 'Not Err');
+ this.t.equal(b.rows.length,1, 'One Row');
+ this.t.equal(b.total_rows,3, 'Out of 3');
+ this.t.ok(b.rows, 'I got Rows');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
tests.list_doc_params = function (callback) {
@@ -67,11 +207,11 @@ tests.list_doc_params = function (callback) {
};
tests.list_doc_params_ok = function (e,b) {
- nano.db.destroy(db_name('c'));
- this.t.notOk(e);
- this.t.equal(b.rows.length,2);
- this.t.equal(b.total_rows,3);
- this.t.ok(b.rows);
+ this.t.notOk(e, 'No errs');
+ this.t.equal(b.rows.length,2, 'Two rows returned');
+ this.t.equal(b.total_rows,3, 'Out of 3');
+ this.t.ok(b.rows, 'That means we got rows');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
46 tests/doc/update.js
@@ -1,8 +1,42 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("doc_up")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('a'))
+ .reply(201, "{\"ok\":true}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a'),
+ date: 'Fri, 02 Dec 2011 19:38:03 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/foo', {"foo": "bar"})
+ .reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"1-4c6114c65e295552ab1019e2b046b10e\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/foo',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 19:38:04 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('a') + '/foo',
+ { "_rev": "1-4c6114c65e295552ab1019e2b046b10e"
+ , "foo": "baz"
+ })
+ .reply(201, "{\"ok\": true,\"id\": \"foo\",\"rev\": \"2-cfcd6781f13994bde69a1c3320bfdadb\"}\n",
+ { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('a') + '/foo',
+ etag: '"2-cfcd6781f13994bde69a1c3320bfdadb"',
+ date: 'Fri, 02 Dec 2011 19:38:04 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' });
function db(i) { return nano.use(db_name(i)); }
@@ -15,11 +49,11 @@ tests.update_doc = function (callback) {
};
tests.update_doc_ok = function (e,b) {
- nano.db.destroy(db_name('a'));
- this.t.notOk(e);
- this.t.equal(b.id, "foo");
- this.t.ok(b.ok);
- this.t.ok(b.rev);
+ this.t.notOk(e, 'I got err free status');
+ this.t.equal(b.id, "foo", 'My filename is foo');
+ this.t.ok(b.ok, 'I am now ok');
+ this.t.ok(b.rev, 'I got rev');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename,tests,module,process.argv[2]);
View
31 tests/shared/cfg.js
@@ -1,7 +1,36 @@
var ensure = require('ensure')
+ , nock = require('nock')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .get('/acb')
+ .reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:53:14 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '44',
+ 'cache-control': 'must-revalidate' })
+ .get('/adb')
+ .reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:53:14 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '44',
+ 'cache-control': 'must-revalidate' })
+ .get('/adb')
+ .reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:53:14 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '44',
+ 'cache-control': 'must-revalidate' })
+ .get('/a')
+ .reply(404, "{\"error\":\"not_found\",\"reason\":\"no_db_file\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 02:53:14 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '44',
+ 'cache-control': 'must-revalidate' });
tests.url = function (callback) { callback(null,nano('http://someurl.com')); };
tests.url_ok = function (_,n) { this.t.equal(n.config.url, "http://someurl.com"); };
View
74 tests/view/compact.js
@@ -1,9 +1,75 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("view_co")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
+
+ couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 03:09:53 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foobar', {"foo":"bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobar\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foobar',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 03:09:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/barfoo', {"bar":"foo"})
+ .reply(201, "{\"ok\":true,\"id\":\"barfoo\",\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/barfoo',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 03:09:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foobaz', {"foo":"baz"})
+ .reply(201, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foobaz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 03:09:54 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/_design/alice',
+ { "views":
+ {"by_id":{"map":"function(doc) { emit(doc._id, doc); }"}}})
+ .reply(201, "{\"ok\":true,\"id\":\"_design/alice\",\"rev\":\"1-14e6bcd59de8d02b840c4db3c95637c5\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/_design/alice',
+ etag: '"1-14e6bcd59de8d02b840c4db3c95637c5"',
+ date: 'Fri, 02 Dec 2011 03:09:55 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '76',
+ 'cache-control': 'must-revalidate' })
+ .delete('/' + db_name('1') + '/foobaz?rev=1-cfa20dddac397da5bf0be2b50fb472fe')
+ .reply(200, "{\"ok\":true,\"id\":\"foobaz\",\"rev\":\"2-a2a31b340cec15e18fbe6c82db6d2c2a\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"2-a2a31b340cec15e18fbe6c82db6d2c2a"',
+ date: 'Fri, 02 Dec 2011 03:09:55 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '69',
+ 'cache-control': 'must-revalidate' })
+ .post('/' + db_name('1') + '/_compact/alice')
+ .reply(202, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ date: 'Fri, 02 Dec 2011 03:09:55 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .get('/' + db_name('1') + '/_design/alice/_view/by_id')
+ .reply(200, "{\"total_rows\":2,\"offset\":0,\"rows\":[\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"}},\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}}\r\n]}\n", { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"AZYB6353W6O0LS9Z4M13CDL7R"',
+ date: 'Fri, 02 Dec 2011 03:09:56 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' });
tests.compact_view = function (callback) {
nano.db.create(db_name('1'), function () {
@@ -29,9 +95,9 @@ tests.compact_view = function (callback) {
};
tests.compact_view_ok = function (err,view) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(err);
- this.t.equal(view.total_rows, 2);
+ this.t.notOk(err, 'STD Free, no errs');
+ this.t.equal(view.total_rows, 2, 'Total rows is two');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename, tests, module,process.argv[2]);
View
67 tests/view/multi-document-fetch.js
@@ -1,11 +1,68 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("view_md")
, tests = exports
+ , couch
;
+ couch = nock(cfg.url)
+ .put('/' + db_name('1'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1'),
+ date: 'Fri, 02 Dec 2011 02:58:50 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '12',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/foo', {"foo":"bar"})
+ .reply(201, "{\"ok\":true,\"id\":\"foo\",\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/foo',
+ etag: '"1-4c6114c65e295552ab1019e2b046b10e"',
+ date: 'Fri, 02 Dec 2011 02:58:51 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/baz', {"foo":"baz"})
+ .reply(201, "{\"ok\":true,\"id\":\"baz\",\"rev\":\"1-cfa20dddac397da5bf0be2b50fb472fe\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/baz',
+ etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"',
+ date: 'Fri, 02 Dec 2011 02:58:51 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/bar', {"bar":"foo"})
+ .reply(201, "{\"ok\":true,\"id\":\"bar\",\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/bar',
+ etag: '"1-41412c293dade3fe73279cba8b4cece4"',
+ date: 'Fri, 02 Dec 2011 02:58:51 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '66',
+ 'cache-control': 'must-revalidate' })
+ .put('/' + db_name('1') + '/_design/alice'
+ , { "views":
+ { "by_id":
+ { "map": "function(doc) { emit(doc._id, doc); }"
+ }
+ }
+ })
+ .reply(201, "{\"ok\":true,\"id\":\"_design/alice\",\"rev\":\"1-14e6bcd59de8d02b840c4db3c95637c5\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('1') + '/_design/alice',
+ etag: '"1-14e6bcd59de8d02b840c4db3c95637c5"',
+ date: 'Fri, 02 Dec 2011 02:58:52 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '76',
+ 'cache-control': 'must-revalidate' })
+ .post('/' + db_name('1') + '/_design/alice/_view/by_id?include_docs=true'
+ , {"keys":["foo","bar"]})
+ .reply(200, "{\"total_rows\":3,\"offset\":2,\"rows\":[\r\n{\"id\":\"foo\",\"key\":\"foo\",\"value\":{\"_id\":\"foo\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"},\"doc\":{\"_id\":\"foo\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"bar\",\"key\":\"bar\",\"value\":{\"_id\":\"bar\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"},\"doc\":{\"_id\":\"bar\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"}}\r\n]}\n", { 'transfer-encoding': 'chunked',
+ server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ etag: '"MZ8GS7KA63WNTZ3RI58JU64R"',
+ date: 'Fri, 02 Dec 2011 02:58:52 GMT',
+ 'content-type': 'application/json',
+ 'cache-control': 'must-revalidate' });
+
tests.multi_doc = function (callback) {
nano.db.create(db_name('1'), function () {
var db = nano.use(db_name('1'));
@@ -27,11 +84,11 @@ tests.multi_doc = function (callback) {
};
tests.multi_doc_ok = function (err,view) {
- nano.db.destroy(db_name('1'));
- this.t.notOk(err);
- this.t.equal(view.rows.length, 2);
- this.t.equal(view.rows[0].id, 'foo');
- this.t.equal(view.rows[1].id, 'bar');
+ this.t.notOk(err, 'I got no errors');
+ this.t.equal(view.rows.length, 2, 'And two rows');
+ this.t.equal(view.rows[0].id, 'foo', 'Got an id of foo');
+ this.t.equal(view.rows[1].id, 'bar', 'And an id of bar');
+ this.t.ok(couch.isDone(), 'Nock is done');
};
ensure(__filename, tests, module,process.argv[2]);
View
92 tests/view/query.js
@@ -1,39 +1,72 @@
var ensure = require('ensure')
+ , nock = require('nock')
, async = require('async')
, cfg = require('../../cfg/tests.js')
, nano = require('../../nano')(cfg)
, db_name = require('../utils').db_name("view_qu")
- , tests = exports;
+ , tests = exports
+ , couch
+ ;
-function db_gen(i) { return nano.use(db_name(i)); }
-
-tests.recursive_create_view = function (tried,callback) {
- if(typeof tried === 'function') {
- callback = tried;
- tried = {tried:0, max_retries:2};
- }
- nano.db.create(db_name('1'), function () {
- var db = db_gen('1');
- db.view('cats','by_id', function (e,b,h) {
- if(tried.tried === tried.max_retries) { return callback('failed'); }
- if(e && e.message === 'missing') {
- return db.insert({"views": { "by_id": {
- "map": "function(doc) { emit(doc._id, doc); }" } }
- }, '_design/cats', function () {
- tried.tried += 1;
- tests.recursive_create_view(tried,callback);
- });
- }
- return callback(e,b,h);
- });
- });
-};
+ couch = nock(cfg.url)
+ .put('/' + db_name('2'))
+ .reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)',
+ location: cfg.url + '/' + db_name('2'),
+ date: 'Fri, 02 Dec 2011 03:19:26 GMT',
+ 'content-type': 'application/json',
+ 'content-length': '