Comparing version 2.1.1 to 3.0.0
407
nano.js
@@ -21,6 +21,9 @@ /* minimal couch in node | ||
, u = require('url') | ||
, error = require('./error') | ||
, errs = require('errs') | ||
, follow | ||
, nano | ||
; | ||
try { follow = require('follow'); } catch (err) {} | ||
function isEmpty(object) { | ||
@@ -85,11 +88,27 @@ for(var property in object) { | ||
function relax(opts,callback) { | ||
if(typeof opts === 'string') { opts = {path: opts}; } | ||
var log = logging(); | ||
var headers = { "content-type": "application/json" | ||
// most simple case is no opts, which returns the root | ||
if(typeof opts === "function") { | ||
callback = opts; | ||
opts = {path: ""}; | ||
} | ||
// string is the same as a simple get request to that path | ||
if(typeof opts === 'string') { | ||
opts = {path: opts}; | ||
} | ||
// no opts, meaning stream root | ||
if(!opts) { | ||
opts = {path: ""}; | ||
callback = null; | ||
} | ||
var log = logging() | ||
, params = opts.params | ||
, headers = { "content-type": "application/json" | ||
, "accept" : "application/json" | ||
} | ||
, req = { method : (opts.method || "GET") | ||
, headers: headers | ||
, uri : cfg.url } | ||
, params = opts.params | ||
, req = { method : (opts.method || "GET") | ||
, headers : headers | ||
, uri : cfg.url } | ||
, status_code | ||
@@ -100,18 +119,39 @@ , parsed | ||
if (opts.jar) { req.jar = opts.jar; } | ||
if(opts.db) { req.uri += "/" + opts.db; } | ||
if(opts.path) { req.uri += "/" + opts.path; } | ||
// cookie jar support | ||
// check github.com/mikeal/request for docs | ||
if (opts.jar) { | ||
req.jar = opts.jar; | ||
} | ||
if(opts.db) { | ||
req.uri = u.resolve(req.uri, opts.db); | ||
} | ||
if(opts.path) { | ||
req.uri += "/" + opts.path; | ||
} | ||
else if(opts.doc) { | ||
// not a design document | ||
if(!/^_design/.test(opts.doc)) { | ||
try { req.uri += "/" + encodeURIComponent(opts.doc); } | ||
catch (ex1) { | ||
ex1.message = 'couldnt encode: ' + opts.doc + ' as an uri'; | ||
return error.request_err(ex, 'encodeuri', {}); | ||
try { | ||
req.uri += "/" + encodeURIComponent(opts.doc); | ||
} | ||
catch (error) { | ||
return errs.handle(errs.merge(error, | ||
{ "note" : "couldnt encode: " + (opts && opts.doc) + " as an uri" | ||
, "scope" : "nano" | ||
, "errid" : "encode_uri" | ||
}), callback); | ||
} | ||
} | ||
else { | ||
// design document | ||
req.uri += "/" + opts.doc; | ||
} | ||
if(opts.att) { req.uri += "/" + opts.att; } | ||
if(opts.att) { | ||
req.uri += "/" + opts.att; | ||
} | ||
} | ||
if(opts.encoding !== undefined && callback) { | ||
@@ -122,2 +162,3 @@ req.encoding = opts.encoding; | ||
} | ||
if(opts.content_type) { | ||
@@ -127,18 +168,38 @@ req.headers["content-type"] = opts.content_type; | ||
} | ||
// these need to be encoded | ||
if(!isEmpty(params)) { | ||
['startkey', 'endkey', 'key', 'keys'].forEach(function (key) { | ||
if (key in params) { | ||
try { params[key] = JSON.stringify(params[key]); } | ||
catch (ex2) { | ||
ex2.message = 'bad params: ' + key + ' = ' + params[key]; | ||
return error.request_err(ex, 'jsonstringify', {}); | ||
try { | ||
['startkey', 'endkey', 'key', 'keys'].forEach(function (key) { | ||
if (key in params) { | ||
try { params[key] = JSON.stringify(params[key]); } | ||
catch (err) { | ||
return errs.handle(errs.merge(err, | ||
{ "note" : "bad params: " + key + " = " + params[key] | ||
, "scope" : "nano" | ||
, "errid" : "encode_keys" | ||
}), callback); | ||
} | ||
} | ||
} | ||
}); | ||
try { req.uri += "?" + qs.stringify(params); } | ||
catch (ex3) { | ||
ex3.message = 'invalid params: ' + params.toString(); | ||
return error.request_err(ex3, 'qsstringify', {}); | ||
}); | ||
} catch (err6) { | ||
return errs.handle(errs.merge(err6, | ||
{ "note" : "params is not an object" | ||
, "scope" : "nano" | ||
, "errid" : "bad_params" | ||
}), callback); | ||
} | ||
try { | ||
req.uri += "?" + qs.stringify(params); | ||
} | ||
catch (err2) { | ||
return errs.handle(errs.merge(err2, | ||
{ "note" : "invalid params: " + params.toString() | ||
, "scope" : "nano" | ||
, "errid" : "encode_params" | ||
}), callback); | ||
} | ||
} | ||
if(opts.body) { | ||
@@ -151,2 +212,4 @@ if (Buffer.isBuffer(opts.body)) { | ||
req.body = JSON.stringify(opts.body, function (key, value) { | ||
// don't encode functions | ||
// this allows functions to be given without pre-escaping | ||
if (typeof(value) === 'function') { | ||
@@ -158,29 +221,49 @@ return value.toString(); | ||
}); | ||
} catch (ex5) { | ||
ex5.message = "couldn't json.stringify the body you provided"; | ||
return error.request_err(ex5, 'jsonstringify', {}, callback); | ||
} catch (err3) { | ||
return errs.handle(errs.merge(err3, | ||
{ "note" : "body seems to be invalid json" | ||
, "scope" : "nano" | ||
, "errid" : "encode_body" | ||
}), callback); | ||
} | ||
} // json data | ||
} | ||
log(req); | ||
if(!callback) { // void callback, stream | ||
// streaming mode | ||
if(!callback) { | ||
try { | ||
return request(req); | ||
} catch (ex4) { | ||
return error.request_err(ex4, 'streamthrow', {}); | ||
} catch (err4) { | ||
return errs.handle(errs.merge(err4, | ||
{ "note" : "request threw when you tried to stream" | ||
, "scope" : "request" | ||
, "errid" : "stream" | ||
}), callback); | ||
} | ||
} | ||
try { | ||
var stream = request(req, function(e,h,b){ | ||
var stream = request(req, function(e,h,b) { | ||
// make sure headers exist | ||
rh = (h && h.headers || {}); | ||
rh['status-code'] = status_code = (h && h.statusCode || 500); | ||
rh.uri = req.uri; | ||
if(e) { | ||
log({err: 'socket', body: b, headers: rh }); | ||
callback(error.request(e,"socket",req,status_code),b,rh); | ||
errs.handle(errs.merge(e, | ||
{ "note" : "error happened during your connection" | ||
, "scope" : "socket" | ||
, "errid" : "request" | ||
}), callback); | ||
return stream; | ||
} | ||
delete rh.server; | ||
delete rh['content-length']; | ||
try { parsed = JSON.parse(b); } catch (err) { parsed = b; } | ||
if (status_code >= 200 && status_code < 300) { | ||
@@ -194,4 +277,10 @@ log({err: null, body: parsed, headers: rh}); | ||
if (!parsed) { parsed = {}; } | ||
callback(error.couch(parsed.reason,parsed.error,req,status_code), | ||
parsed, rh); | ||
errs.handle(errs.merge(errs.create(parsed), | ||
{ "scope" : "couch" | ||
, "status_code" : status_code | ||
, "status-code" : status_code | ||
, "request" : req | ||
, "headers" : rh | ||
, "errid" : "non_200" | ||
}), callback); | ||
return stream; | ||
@@ -201,4 +290,8 @@ } | ||
return stream; | ||
} catch(ex6) { | ||
return error.request_err(ex6, 'callbackthrow', {}); | ||
} catch(err5) { | ||
return errs.merge(err5, | ||
{ "note" : "request threw when you tried to create the object" | ||
, "scope" : "request" | ||
, "errid" : "callback" | ||
}); | ||
} | ||
@@ -293,3 +386,5 @@ } | ||
} | ||
return relax({db: db_name, doc: "_compact", att: design_name, method: "POST"},callback); | ||
return relax( | ||
{ db: db_name, doc: "_compact", att: design_name | ||
, method: "POST" }, callback); | ||
} | ||
@@ -312,7 +407,58 @@ | ||
callback = params; | ||
params = {}; | ||
params = {}; | ||
} | ||
return relax({db: db_name, path: "_changes", params: params, method: "GET"},callback); | ||
return relax( | ||
{ db: db_name, path: "_changes", params: params | ||
, method: "GET" }, callback); | ||
} | ||
/* | ||
* couchdb database follow support | ||
* | ||
* e.g. var feed = nano.db.follow(db_name, {since: "now"}); | ||
* feed.on('change', function (change) { console.log(change); }); | ||
* feed.follow(); | ||
* | ||
* @param {db_name:string} database name | ||
* @param {params:object:optional} additions to the querystring | ||
* check the follow documentation for the full api | ||
* https://github.com/iriscouch/follow | ||
* | ||
* | ||
* @see relax | ||
*/ | ||
function follow_db(db_name, params, callback) { | ||
if(typeof params === "function") { | ||
callback = params; | ||
params = {}; | ||
} | ||
// case only db name is given | ||
params = params || {}; | ||
params.db = u.resolve(cfg.url, db_name); | ||
if(!follow) { | ||
var stream = errs.handle( | ||
{ "note" : "follow is only supported on node 0.6+" | ||
, "scope" : "follow" | ||
, "errid" : "no_soup_for_you" | ||
}, callback); | ||
// streaming mode will call unexisting follow stream | ||
stream.follow = function () { | ||
return errs.handle( | ||
{ "note" : "follow is only supported on node 0.6+" | ||
, "scope" : "follow" | ||
, "errid" : "no_soup_for_you" | ||
}, callback); | ||
}; | ||
return stream; | ||
} | ||
if(typeof callback === "function") { | ||
return follow(params, callback); | ||
} else { | ||
return new follow.Feed(params); | ||
} | ||
} | ||
/* | ||
@@ -377,4 +523,5 @@ * replicates a couchdb database | ||
function destroy_doc(doc_name,rev,callback) { | ||
return relax({db: db_name, doc: doc_name, method: "DELETE", params: {rev: rev}}, | ||
callback); | ||
return relax( | ||
{ db: db_name, doc: doc_name, method: "DELETE" | ||
, params: {rev: rev} }, callback); | ||
} | ||
@@ -400,3 +547,5 @@ | ||
} | ||
return relax({db: db_name, doc: doc_name, method: "GET", params: params},callback); | ||
return relax( | ||
{ db: db_name, doc: doc_name, method: "GET" | ||
, params: params }, callback); | ||
} | ||
@@ -417,3 +566,5 @@ | ||
} | ||
return relax({db: db_name, path: "_all_docs", method: "GET", params: params},callback); | ||
return relax( | ||
{ db: db_name, path: "_all_docs", method: "GET" | ||
, params: params }, callback); | ||
} | ||
@@ -437,3 +588,5 @@ | ||
params.include_docs = true; | ||
return relax({db: db_name, path: "_all_docs", method: "POST", params: params, body: doc_names},callback); | ||
return relax( | ||
{ db: db_name, path: "_all_docs", method: "POST" | ||
, params: params, body: doc_names }, callback); | ||
} | ||
@@ -578,87 +731,109 @@ | ||
public_functions = { info: function(cb) { return get_db(db_name,cb); } | ||
, replicate: function(target,opts,cb) { | ||
return replicate_db(db_name,target,opts,cb); | ||
} | ||
, compact: function(cb) { | ||
return compact_db(db_name,cb); | ||
} | ||
, changes: function(params,cb) { | ||
return changes_db(db_name,params,cb); | ||
} | ||
, insert: insert_doc | ||
, get: get_doc | ||
, destroy: destroy_doc | ||
, bulk: bulk_docs | ||
, list: list_docs | ||
, fetch: fetch_docs | ||
, config: {url: cfg.url, db: db_name} | ||
, attachment: { insert: insert_att | ||
, get: get_att | ||
, destroy: destroy_att | ||
} | ||
, updateWithHandler: update_with_handler_doc | ||
}; | ||
public_functions.view = view_docs; | ||
// db level exports | ||
public_functions = | ||
{ info : function(cb) { return get_db(db_name,cb); } | ||
, replicate : function(target,opts,cb) { | ||
return replicate_db(db_name,target,opts,cb); | ||
} | ||
, compact : function(cb) { | ||
return compact_db(db_name,cb); | ||
} | ||
, changes : function(params,cb) { | ||
return changes_db(db_name,params,cb); | ||
} | ||
, follow : function(params,cb) { | ||
return follow_db(db_name,params,cb); | ||
} | ||
, insert : insert_doc | ||
, get : get_doc | ||
, destroy : destroy_doc | ||
, bulk : bulk_docs | ||
, list : list_docs | ||
, fetch : fetch_docs | ||
, config : {url: cfg.url, db: db_name} | ||
, attachment : | ||
{ insert : insert_att | ||
, get : get_att | ||
, destroy : destroy_att | ||
} | ||
, atomic : update_with_handler_doc | ||
, updateWithHandler : update_with_handler_doc // alias | ||
}; | ||
public_functions.view = view_docs; | ||
public_functions.view.compact = function(design_name,cb) { | ||
return compact_db(db_name,design_name,cb); | ||
}; | ||
return public_functions; | ||
} | ||
public_functions = { db: { create: create_db | ||
, get: get_db | ||
, destroy: destroy_db | ||
, list: list_dbs | ||
, use: document_module // alias | ||
, scope: document_module // alias | ||
, compact: compact_db | ||
, replicate: replicate_db | ||
, changes: changes_db | ||
} | ||
, use: document_module | ||
, scope: document_module // alias | ||
, request: relax | ||
, relax: relax // alias | ||
, dinosaur: relax // alias | ||
}; | ||
// server level exports | ||
public_functions = | ||
{ db : | ||
{ create : create_db | ||
, get : get_db | ||
, destroy : destroy_db | ||
, list : list_dbs | ||
, use : document_module // alias | ||
, scope : document_module // alias | ||
, compact : compact_db | ||
, replicate : replicate_db | ||
, changes : changes_db | ||
, follow : follow_db | ||
} | ||
, use : document_module | ||
, scope : document_module // alias | ||
, request : relax | ||
, relax : relax // alias | ||
, dinosaur : relax // alias | ||
}; | ||
// handle different type of configs | ||
if(typeof cfg === "string") { | ||
// just an url | ||
if(/^https?:/.test(cfg)) { cfg = {url: cfg}; } // url | ||
else { | ||
try { cfg = require(cfg); } // file path | ||
catch(e) { | ||
e.message = "couldn't read config file " + | ||
(cfg ? cfg.toString() : ''); | ||
throw error.init(e, "badfile"); | ||
// a file that you can require | ||
try { | ||
cfg = require(cfg); | ||
} | ||
catch(error) { | ||
throw errs.merge(error, | ||
{ "scope" : "init" | ||
, "note" : "couldn't read config file " + cfg | ||
, "errid" : "bad_file" | ||
}); | ||
} | ||
} | ||
} | ||
if(!(cfg && cfg.url)) | ||
throw error.init("no configuration with a valid url was given", "badurl"); | ||
if(!(cfg && cfg.url)) { | ||
throw errs.create( | ||
{ "scope" : "init" | ||
, "note" : "no configuration with a valid url was given" | ||
, "errid" : "bad_url" | ||
}); | ||
} | ||
// alias so config is public in nano once set | ||
public_functions.config = cfg; | ||
if(cfg.proxy || cfg.jar) { | ||
if(cfg.proxy) | ||
request_opts.proxy = cfg.proxy; | ||
request_opts.jar = !!cfg.jar; | ||
request = require('request').defaults(request_opts); | ||
// configuration for request | ||
// please send pull requests if you want to use a option | ||
// in request that is not exposed | ||
if(cfg.request_defaults) { | ||
request = require('request').defaults(request_defaults); | ||
} | ||
// assuming a cfg.log inside cfg | ||
logging = require('./logging')(cfg); | ||
try { | ||
path = u.parse(cfg.url); | ||
path_array = path.pathname.split('/').filter(function(e) { return e; }); | ||
} | ||
catch (e2) { | ||
e2.message = "your url is invalid: " + cfg.url; | ||
throw error.init(e2, "invalidurl"); | ||
} | ||
// nano('http://couch.nodejitsu.com/db1') should return a database | ||
// nano('http://couch.nodejitsu.com') should return a nano object | ||
logging = require('./logger')(cfg); | ||
path = u.parse(cfg.url); | ||
path_array = path.pathname.split('/').filter(function(e) { return e; }); | ||
// nano('http://couch.nodejitsu.com/db1') | ||
// should return a database | ||
// nano('http://couch.nodejitsu.com') | ||
// should return a nano object | ||
if(path.pathname && path_array.length > 0) { | ||
@@ -685,9 +860,7 @@ auth = path.auth ? path.auth + '@' : ''; | ||
* thanks for visiting! come again! | ||
* | ||
* LH1059-A321 | ||
* LH1178-A321 | ||
*/ | ||
// nano level exports | ||
nano.version = JSON.parse( | ||
fs.readFileSync(__dirname + "/package.json")).version; | ||
nano.path = __dirname; |
@@ -5,3 +5,3 @@ { "name" : "nano" | ||
, "repository" : "git://github.com/dscape/nano" | ||
, "version" : "2.1.1" | ||
, "version" : "3.0.0" | ||
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" | ||
@@ -25,19 +25,15 @@ , "contributors" : | ||
["couchdb", "data", "request", "json", "nosql", "micro", "nano", "database"] | ||
, "dependencies" : {"request": "2.9.x"} | ||
, "dependencies" : {"request": "2.9.x", "follow": "*"} | ||
, "devDependencies" : | ||
{ "async" : "0.1.15" | ||
, "ensure" : "0.4.6" | ||
, "nock" : "0.5.5" | ||
, "tap-runner" : "0.0.7" | ||
, "tap-producer" : "0.0.1" | ||
, "tap" : "0.1.3" | ||
, "inherits" : "1.0.0" | ||
, "yamlish" : "0.0.2" | ||
, "slide" : "1.1.3" | ||
, "underscore" : "1.3.1" | ||
{ "async" : "0.1.x" | ||
, "specify" : "0.4.x" | ||
, "nock" : "0.13.x" | ||
, "errs" : "0.2.x" | ||
} | ||
, "scripts" : | ||
{ "test" : "./node_modules/ensure/bin/tap.js tests/*/*.js" } | ||
{ "test" : "ls -tr tests/*/*.js | NOCK=on xargs -I{} node {}" | ||
, "nock_off" : "ls -tr tests/*/*.js | xargs -I{} node {}" | ||
} | ||
, "main" : "./nano.js" | ||
, "engines" : { "node": ">=0.3.6" } | ||
} |
@@ -1,63 +0,39 @@ | ||
var ensure = require('ensure') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("att_de") | ||
, tests = exports | ||
, nock = require('nock') | ||
, couchdb | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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 | ||
}) | ||
var mock = nock(helpers.couch, "att/destroy") | ||
, db = nano.use("att_destroy") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
specify("att_destroy:setup", timeout, function (assert) { | ||
nano.db.create("att_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.att_des = function (callback) { | ||
console.log(require('../../nano')) | ||
nano.db.create(db_name("a"), function () { | ||
db("a").attachment.insert("new", "att", "Hello World!", "text/plain", | ||
function (e,b) { | ||
db("a").attachment.destroy("new", "att", b.rev, callback); | ||
specify("att_destroy:test", timeout, function (assert) { | ||
db.attachment.insert("new", "att", "Hello World!", "text/plain", | ||
function (error, att) { | ||
assert.equal(error, undefined, "Should store the attachment"); | ||
assert.equal(att.ok, true, "Response should be ok"); | ||
assert.ok(att.rev, "Should have a revision number"); | ||
db.attachment.destroy("new", "att", att.rev, function(error, response) { | ||
assert.equal(error, undefined, "Should delete the attachment"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
assert.equal(response.id, "new", "Id should be new"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.att_des_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("att_destroy:teardown", timeout, function (assert) { | ||
nano.db.destroy("att_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,71 +0,40 @@ | ||
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 | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "att/get") | ||
, db = nano.use("att_get") | ||
; | ||
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); } | ||
db("a").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev}, | ||
function (e2,b2) { | ||
if(e2) { callback(e2); } | ||
db("a").attachment.get("new", "att", {rev: b2.rev}, callback); | ||
}); | ||
specify("att_get:setup", timeout, function (assert) { | ||
nano.db.create("att_get", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
specify("att_get:test", timeout, function (assert) { | ||
db.attachment.insert("new", "att", "Hello", "text/plain", | ||
function(error, hello) { | ||
assert.equal(error, undefined, "Should store hello"); | ||
assert.equal(hello.ok, true, "Response should be ok"); | ||
assert.ok(hello.rev, "Should have a revision number"); | ||
db.attachment.get("new", "att", | ||
function (error, helloWorld) { | ||
assert.equal(error, undefined, "Should get the hello"); | ||
assert.equal("Hello", helloWorld, "hello is reflexive"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.att_get_ok = function (e,b) { | ||
this.t.notOk(e, 'No Error'); | ||
var from_buffer = new Buffer(b, "binary").toString("base64"); | ||
this.t.equal(from_buffer, pixel, 'Buffer is pixel'); | ||
this.t.equal(b.toString("base64"), pixel, 'Result buffer is pixel'); | ||
this.t.ok(couch.isDone(), 'Nock is done'); | ||
}; | ||
specify("att_get:teardown", timeout, function (assert) { | ||
nano.db.destroy("att_get", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,44 +0,34 @@ | ||
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 | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "att/insert") | ||
, db = nano.use("att_insert") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
specify("att_insert:setup", timeout, function (assert) { | ||
nano.db.create("att_insert", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.att_new_doc = function (callback) { | ||
nano.db.create(db_name("a"), function () { | ||
db("a").attachment.insert("new", "att", "Hello World!", "text/plain", callback); | ||
specify("att_insert:test", timeout, function (assert) { | ||
db.attachment.insert("new", "att", "Hello World!", "text/plain", | ||
function (error, att) { | ||
assert.equal(error, undefined, "Should store the attachment"); | ||
assert.equal(att.ok, true, "Response should be ok"); | ||
assert.ok(att.rev, "Should have a revision number"); | ||
}); | ||
}; | ||
}); | ||
tests.att_new_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("att_insert:teardown", timeout, function (assert) { | ||
nano.db.destroy("att_insert", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,78 +0,45 @@ | ||
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==" | ||
, couch | ||
var fs = require('fs') | ||
, path = require('path') | ||
, specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
, pixel = helpers.pixel | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "att/pipe") | ||
, db = nano.use("att_pipe") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
function file_name(i) { return __dirname + "/." + i + "-tmp.bmp"; } | ||
function f_s(i) { return fs.createWriteStream(file_name(i)); } | ||
specify("att_pipe:setup", timeout, function (assert) { | ||
nano.db.create("att_pipe", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.att_pipe = function (callback) { | ||
var buffer = new Buffer(pixel, 'base64') | ||
, file_stream = f_s("a"); | ||
file_stream.on("close", function() { callback(); }); | ||
nano.db.create(db_name("a"), function () { | ||
db("a").attachment.insert("new", "att", "Hello", "text/plain", | ||
function(e,b) { | ||
if(e) { callback(e); } | ||
db("a").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev}, | ||
function (e2,b2) { | ||
if(e2) { callback(e2); } | ||
db("a").attachment.get("new", "att", {rev: b2.rev}) | ||
.pipe(file_stream); | ||
}); | ||
specify("att_pipe:test", timeout, function (assert) { | ||
var buffer = new Buffer(pixel, 'base64') | ||
, filename = path.join(__dirname, '.temp.bmp') | ||
, ws = fs.createWriteStream(filename) | ||
; | ||
ws.on('close', function () { | ||
assert.equal(fs.readFileSync(filename).toString('base64'), pixel); | ||
fs.unlinkSync(filename); | ||
}); | ||
db.attachment.insert("new", "att", buffer, "image/bmp", | ||
function (error, bmp) { | ||
assert.equal(error, undefined, "Should store the pixel"); | ||
db.attachment.get("new", "att", {rev: bmp.rev}).pipe(ws); | ||
}); | ||
}); | ||
specify("att_pipe:teardown", timeout, function (assert) { | ||
nano.db.destroy("att_pipe", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}; | ||
}); | ||
tests.att_pipe_ok = function () { | ||
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]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,58 +0,40 @@ | ||
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 | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
, pixel = helpers.pixel | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "att/update") | ||
, db = nano.use("att_update") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
specify("att_update:setup", timeout, function (assert) { | ||
nano.db.create("att_update", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.att_doc = function (callback) { | ||
specify("att_update:test", timeout, function (assert) { | ||
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) { | ||
if(e) { callback(e); } | ||
db("b").attachment.insert("new", "att", buffer, "image/bmp", {rev: b.rev}, | ||
callback); | ||
db.attachment.insert("new", "att", "Hello", "text/plain", | ||
function(error, hello) { | ||
assert.equal(error, undefined, "Should store hello"); | ||
assert.equal(hello.ok, true, "Response should be ok"); | ||
assert.ok(hello.rev, "Should have a revision number"); | ||
db.attachment.insert("new", "att", buffer, "image/bmp", | ||
{ rev: hello.rev }, function (error, bmp) { | ||
assert.equal(error, undefined, "Should store the pixel"); | ||
}); | ||
}); | ||
}); | ||
specify("att_update:teardown", timeout, function (assert) { | ||
nano.db.destroy("att_update", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}; | ||
}); | ||
tests.att_doc_ok = function (e,b) { | ||
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]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,74 +0,42 @@ | ||
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 | ||
var specify = require('specify') | ||
, async = require('async') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/changes") | ||
, db = nano.use("db_changes") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.changes_db = function (callback) { | ||
nano.db.create(db_name("a"), function () { | ||
specify("db_changes:setup", timeout, function (assert) { | ||
nano.db.create("db_changes", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
async.parallel( | ||
[ function(cb) { db("a").insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db("a").insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db("a").insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
db("a").changes({since:2}, callback); | ||
}); | ||
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); } | ||
] | ||
, function(error, results){ | ||
assert.equal(error, undefined, "Should have stored docs"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.changes_db_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("db_changes:test", timeout, function (assert) { | ||
db.changes({since:2}, function (error, response) { | ||
assert.equal(error, undefined, "Changes should respond"); | ||
assert.equal(response.results.length, 1, 'Gets one result'); | ||
assert.equal(response.last_seq, 3, 'seq is 3'); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_changes:teardown", timeout, function (assert) { | ||
nano.db.destroy("db_changes", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,88 +0,56 @@ | ||
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 | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/compact") | ||
, db = nano.use("db_compact") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.compact_db = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
async.parallel( | ||
[ 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(err, results){ | ||
db('1').compact(function () { | ||
db('1').info(callback); | ||
}); | ||
specify("db_compact:setup", timeout, function (assert) { | ||
nano.db.create("db_compact", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
db.destroy("foobaz", foo.rev, function (error, response) { | ||
assert.equal(error, undefined, "Should have deleted foo"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.compact_db_ok = function (err,list) { | ||
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'); | ||
}; | ||
specify("db_compact:test", timeout, function (assert) { | ||
db.compact(function (error) { | ||
assert.equal(error, undefined, "Compact didn't respond"); | ||
db.info(function (error, info) { | ||
assert.equal(error, undefined, "Info didn't respond"); | ||
assert.equal(info.doc_count, 0, "Document count is not 3"); | ||
assert.equal(info.doc_del_count, 1, "No deleted documents"); | ||
assert.equal(info.update_seq, 2, "seq is two"); | ||
assert.equal(info.compact_running, true, "Compaction is running"); | ||
}); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_compact:teardown", timeout, function (assert) { | ||
// you can really mess up couchdb by trying to | ||
// delete while a db is compacting | ||
(function destroy_when_compact_finished(timeout) { | ||
timeout = timeout || 50; | ||
db.info(function (error, info) { | ||
if(error || info && info.compact_running) { | ||
return setTimeout(destroy_when_compact_finished, timeout*2); | ||
} | ||
nano.db.destroy("db_compact", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
})(); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,29 +0,23 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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.create(db_name('1'), callback); | ||
}; | ||
var mock = nock(helpers.couch, "db/create"); | ||
tests.create_db_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("db_create:test", timeout, function (assert) { | ||
nano.db.create("db_create", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_create:teardown", timeout, function (assert) { | ||
nano.db.destroy("db_create", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,37 +0,23 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/destroy"); | ||
tests.destroy_db = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.destroy(db_name('1'), callback); | ||
specify("db_destroy:setup", timeout, function (assert) { | ||
nano.db.create("db_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}; | ||
}); | ||
tests.destroy_db_ok = function (e,b) { | ||
this.t.notOk(e, 'Error says Yey'); | ||
this.t.equal(b.ok, true, '{ok: yeah}'); | ||
this.t.ok(couch.isDone(), 'Nock not done'); | ||
}; | ||
specify("db_destroy:test", timeout, function (assert) { | ||
nano.db.destroy("db_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,42 +0,31 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/get"); | ||
tests.get_db = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.get(db_name('1'), function (e,b) { | ||
callback(e,b); | ||
return; | ||
}); | ||
specify("db_get:setup", timeout, function (assert) { | ||
nano.db.create("db_get", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}; | ||
}); | ||
tests.get_db_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("db_get:test", timeout, function (assert) { | ||
nano.db.get("db_get", function (error, response) { | ||
assert.equal(error, undefined, "Failed to get database"); | ||
assert.equal(response.doc_count, 0, "I can haz docs?"); | ||
assert.equal(response.db_name, "db_get"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_get:teardown", timeout, function (assert) { | ||
nano.db.destroy("db_get", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,37 +0,33 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/list"); | ||
tests.list_db = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
nano.db.list(callback); | ||
specify("db_list:setup", timeout, function (assert) { | ||
nano.db.create("db_list", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}; | ||
}); | ||
tests.list_db_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("db_list:test", timeout, function (assert) { | ||
nano.db.list(function (error, list) { | ||
assert.equal(error, undefined, "Failed to list databases"); | ||
var filtered = list.filter(function (e) { | ||
return e === "db_list" || e === "_replicator" || e === "_users"; | ||
}); | ||
assert.equal(filtered.length, 3, "Has exactly those threee dbs"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_list:teardown", timeout, function (assert) { | ||
nano.db.destroy("db_list", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,92 +0,51 @@ | ||
var ensure = require('ensure') | ||
, nock = require('nock') | ||
var specify = require('specify') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("db_re") | ||
, tests = exports | ||
, couch | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "db/replicate") | ||
, db = nano.use("db_replicate") | ||
, replica = nano.use("db_replica") | ||
; | ||
tests.replicate_db = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
var db = nano.use(db_name('1')) | ||
, replica = nano.use(db_name('1')+"_replica"); | ||
async.parallel( | ||
[ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz",cb); } | ||
, function(cb) { nano.db.create(db_name('1')+"_replica", cb); } | ||
], | ||
function(err, results) { | ||
db.replicate(db_name('1')+"_replica", function() { | ||
replica.list(callback); | ||
}); | ||
}); | ||
specify("db_replicate:setup", timeout, function (assert) { | ||
nano.db.create("db_replicate", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
nano.db.create("db_replica", function (err) { | ||
assert.equal(err, undefined, "Failed to create replica database"); | ||
async.parallel( | ||
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); } | ||
] | ||
, function(error, results){ | ||
assert.equal(error, undefined, "Should have stored docs"); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.replicate_db_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("db_replicate:test", timeout, function (assert) { | ||
db.replicate("db_replica", function(error) { | ||
assert.equal(error, undefined, "Should be able to replicate"); | ||
replica.list(function (error, list) { | ||
assert.equal(error, undefined, "Should be able to list"); | ||
assert.equal(list.total_rows, 3, "Should have three documents"); | ||
}); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("db_replicate:teardown", timeout, function (assert) { | ||
nano.db.destroy("db_replicate", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
nano.db.destroy("db_replica", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy replica database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,53 +0,36 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "doc/bulk") | ||
, db = nano.use("doc_bulk") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
specify("doc_bulk:setup", timeout, function (assert) { | ||
nano.db.create("doc_bulk", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.bulk_docs = function (callback) { | ||
nano.db.create(db_name("a"), function () { | ||
db("a").bulk( | ||
{"docs":[{"key":"baz","name":"bazzel"},{"key":"bar","name":"barry"}]}, | ||
function (e,r) { | ||
callback(e,r); | ||
}); | ||
specify("doc_bulk:test", timeout, function (assert) { | ||
db.bulk( | ||
{"docs":[{"key":"baz","name":"bazzel"},{"key":"bar","name":"barry"}]}, | ||
function (error,response) { | ||
assert.equal(error, undefined, 'No error'); | ||
assert.equal(response.length, 2, 'Has two docs'); | ||
assert.ok(response[0].id, 'First got id'); | ||
assert.ok(response[1].id, 'Second got id'); | ||
}); | ||
}; | ||
}); | ||
tests.bulk_docs_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_bulk:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_bulk", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,57 +0,39 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "doc/destroy") | ||
, db = nano.use("doc_destroy") | ||
, rev | ||
; | ||
tests.destroy_doc = function (callback) { | ||
var db = nano.use(db_name('1')); | ||
nano.db.create(db_name('1'), function () { | ||
db.insert({foo: "bar"}, "foo", function (_,b) { | ||
db.destroy("foo", b.rev, function (e,b) { | ||
callback(e,b); | ||
return; | ||
}); | ||
specify("doc_destroy:setup", timeout, function (assert) { | ||
nano.db.create("doc_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
rev = foo.rev; | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.destroy_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_destroy:test", timeout, function (assert) { | ||
db.destroy("foobaz", rev, function (error, response) { | ||
assert.equal(error, undefined, "Should have deleted foo"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("doc_destroy:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_destroy", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,133 +0,50 @@ | ||
var ensure = require('ensure') | ||
, nock = require('nock') | ||
var specify = require('specify') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_li") | ||
, tests = exports | ||
, couch | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
couch = nock(cfg.url) | ||
.put('/' + db_name("b")) | ||
.reply(201, "{\"ok\":true}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lib', | ||
date: 'Fri, 24 Feb 2012 14:48:10 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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lia', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '12', | ||
'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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lib/foobaz', | ||
etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lib/barfoo', | ||
etag: '"1-41412c293dade3fe73279cba8b4cece4"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '69', | ||
'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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lib/foobar', | ||
etag: '"1-4c6114c65e295552ab1019e2b046b10e"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '69', | ||
'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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lia/foobar', | ||
etag: '"1-4c6114c65e295552ab1019e2b046b10e"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lia/barfoo', | ||
etag: '"1-41412c293dade3fe73279cba8b4cece4"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 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/R14B02)', | ||
location: 'http://localhost:5984/v067_doc_lia/foobaz', | ||
etag: '"1-cfa20dddac397da5bf0be2b50fb472fe"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '69', | ||
'cache-control': 'must-revalidate' }) | ||
.post('/' + db_name("b")+ '/_all_docs?include_docs=true', "{\"keys\":[\"foobar\",\"barfoo\"]}") | ||
.reply(200, "{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}},\r\n{\"id\":\"barfoo\",\"key\":\"barfoo\",\"value\":{\"rev\":\"1-41412c293dade3fe73279cba8b4cece4\"},\"doc\":{\"_id\":\"barfoo\",\"_rev\":\"1-41412c293dade3fe73279cba8b4cece4\",\"bar\":\"foo\"}}\r\n]}\n", { 'transfer-encoding': 'chunked', | ||
server: 'CouchDB/1.1.1 (Erlang OTP/R14B02)', | ||
etag: '"7X2D919KBXMJ5Z6JJ4RCZXZCB"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'cache-control': 'must-revalidate' }) | ||
.post('/' + db_name("a")+ '/_all_docs?include_docs=true', "{\"keys\":[\"foobar\"]}") | ||
.reply(200, "{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"foobar\",\"key\":\"foobar\",\"value\":{\"rev\":\"1-4c6114c65e295552ab1019e2b046b10e\"},\"doc\":{\"_id\":\"foobar\",\"_rev\":\"1-4c6114c65e295552ab1019e2b046b10e\",\"foo\":\"bar\"}}\r\n]}\n", { 'transfer-encoding': 'chunked', | ||
server: 'CouchDB/1.1.1 (Erlang OTP/R14B02)', | ||
etag: '"2GOFI0AQ1BKE16DH52QAWBY0K"', | ||
date: 'Fri, 24 Feb 2012 14:48:10 GMT', | ||
'content-type': 'application/json', | ||
'cache-control': 'must-revalidate' }); | ||
var mock = nock(helpers.couch, "doc/fetch") | ||
, db = nano.use("doc_fetch") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.fetch_doc = function (callback) { | ||
nano.db.create(db_name('a'), function () { | ||
specify("doc_fetch:setup", timeout, function (assert) { | ||
nano.db.create("doc_fetch", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
async.parallel( | ||
[ function(cb) { db('a').insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db('a').insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db('a').insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
db('a').fetch({ keys: ["foobar"]}, callback); | ||
}); | ||
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); } | ||
] | ||
, function(error, results) { | ||
assert.equal(error, undefined, "Should have stored docs"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.fetch_doc_ok = function (e,b) { | ||
this.t.notOk(e, 'No 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, 'Got rows'); | ||
this.t.ok(couch.isDone(), 'Nock is done'); | ||
}; | ||
specify("doc_fetch:one_key", timeout, function (assert) { | ||
db.fetch({keys:["foobar"]}, function (error, docs) { | ||
assert.equal(error, undefined, 'No errors'); | ||
assert.equal(docs.rows.length, 1, 'One row'); | ||
assert.equal(docs.total_rows, 3, 'Out of 3'); | ||
}); | ||
}); | ||
tests.fetch_multiple = function (callback) { | ||
nano.db.create(db_name('b'), function () { | ||
async.parallel( | ||
[ function(cb) { db('b').insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db('b').insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db('b').insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
db('b').fetch({keys: ["foobar", "barfoo" ]}, callback); | ||
}); | ||
specify("doc_fetch:multiple_keys", timeout, function (assert) { | ||
db.fetch({keys:["foobar", "barfoo"]}, function (error, docs) { | ||
assert.equal(error, undefined, 'No errors'); | ||
assert.equal(docs.rows.length, 2, 'Two rows'); | ||
assert.equal(docs.total_rows, 3, 'Out of 3'); | ||
}); | ||
}; | ||
}); | ||
tests.fetch_multiple_ok = function (e,b) { | ||
this.t.notOk(e, 'Not Err'); | ||
this.t.equal(b.rows.length,2, 'Two Rows'); | ||
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'); | ||
}; | ||
specify("doc_fetch:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_fetch", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,105 +0,47 @@ | ||
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 | ||
, couch | ||
var specify = require("specify") | ||
, helpers = require("../helpers") | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "doc/get") | ||
, db = nano.use("doc_get") | ||
, rev | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.get_doc = function (callback) { | ||
nano.db.create(db_name('a'), function () { | ||
db('a').insert({foo: "bar"}, "foo", function () { | ||
db('a').get("foo", callback); | ||
specify("doc_get:setup", timeout, function (assert) { | ||
nano.db.create("doc_get", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foobaz"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.equal(foo.id, "foobaz", "My id is foobaz"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
rev = foo.rev; | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.get_doc_ok = function (e,b) { | ||
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) { | ||
nano.db.create(db_name('b'), function () { | ||
db('b').insert({foo: "bar"}, "foo", function () { | ||
db('b').insert({foo: "bar"}, "foo", function () { // Conflict, no rev | ||
db('b').get("foo", {revs_info: true}, callback); | ||
}); | ||
specify("doc_get:test", timeout, function (assert) { | ||
db.insert({"foo": "bar"}, "foobaz", function (error, response) { | ||
assert.equal(error["status-code"], 409, "Should be conflict"); | ||
assert.equal(error.scope, "couch", "Scope is couch"); | ||
assert.equal(error.error, "conflict", "Error is conflict"); | ||
db.get("foobaz", {revs_info: true}, function (error, foobaz) { | ||
assert.equal(error, undefined, "Should get foobaz"); | ||
assert.ok(foobaz._revs_info, "Got revs info"); | ||
assert.equal(foobaz._id, "foobaz", "Id is food"); | ||
assert.equal(foobaz.foo, "baz", "Baz is in foo"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.get_doc_params_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_get:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_get", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,78 +0,62 @@ | ||
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 | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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", "fn": "function () { return true; }", fn2: "function () { return false; }"}) | ||
.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' }); | ||
var mock = nock(helpers.couch, "doc/insert") | ||
, db = nano.use("doc_insert") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
specify("doc_insert:setup", timeout, function (assert) { | ||
nano.db.create("doc_insert", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
}); | ||
}); | ||
tests.insert_doc = function (callback) { | ||
nano.db.create(db_name("a"), function () { | ||
db("a").insert({foo: "bar"}, callback); | ||
specify("doc_insert:simple", timeout, function (assert) { | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
}); | ||
}; | ||
}); | ||
tests.insert_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_insert:functions", timeout, function (assert) { | ||
db.insert({fn: function () { return true; }, | ||
fn2: "function () { return true; }"}, function (error, fns) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(fns.ok, true, "Response should be ok"); | ||
assert.ok(fns.rev, "Response should have rev"); | ||
db.get(fns.id, function (error, fns) { | ||
assert.equal(fns.fn, fns.fn2, "fn matches fn2"); | ||
assert.equal(error, undefined, "Should get foo"); | ||
}); | ||
}); | ||
}); | ||
tests.insert_doc_path = function (callback) { | ||
nano.db.create(db_name("b"), function () { | ||
db("b").insert({foo: "bar", fn: function () { return true; }, | ||
fn2: "function () { return false; }" }, | ||
'some/path', callback); | ||
specify("doc_insert:streaming", timeout, function (assert) { | ||
var buffer = "" | ||
, foobar = db.insert({"foo": "bar"}) | ||
; | ||
function runAssertions(error, foobar) { | ||
assert.equal(error, undefined, "Should have stored foobar"); | ||
assert.ok(foobar.ok, "This is ok"); | ||
assert.ok(foobar.rev, "I GOT REVZ"); | ||
} | ||
foobar.on('data', function(chunk) { buffer += chunk; }); | ||
foobar.on('end', function () { runAssertions(null, JSON.parse(buffer)); }); | ||
foobar.on('error', runAssertions); | ||
}); | ||
specify("doc_insert:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_insert", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}; | ||
}); | ||
tests.insert_doc_path_ok = function (e,b) { | ||
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]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,217 +0,66 @@ | ||
var ensure = require('ensure') | ||
, nock = require('nock') | ||
var specify = require('specify') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("doc_li") | ||
, tests = exports | ||
, couch | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "doc/list") | ||
, db = nano.use("doc_list") | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.list_doc = function (callback) { | ||
nano.db.create(db_name('a'), function () { | ||
specify("doc_list:setup", timeout, function (assert) { | ||
nano.db.create("doc_list", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
async.parallel( | ||
[ function(cb) { db('a').insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db('a').insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db('a').insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
db('a').list(callback); | ||
}); | ||
[ function(cb) { db.insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db.insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db.insert({"foo": "baz"}, "foobaz", cb); } | ||
] | ||
, function(error, results) { | ||
assert.equal(error, undefined, "Should have stored docs"); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.list_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_list:list", timeout, function (assert) { | ||
db.list(function (error, docs) { | ||
assert.equal(error, undefined, "List didn't work"); | ||
assert.equal(docs.total_rows, 3, "Got total three rows"); | ||
assert.ok(docs.rows, "Got rows"); | ||
}); | ||
}); | ||
tests.ns_list_doc = function (callback) { | ||
nano.db.create(db_name('b'), function () { | ||
async.parallel( | ||
[ function(cb) { db('b').insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db('b').insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db('b').insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
nano.request( { db: db_name('b') | ||
, doc: "_all_docs" | ||
, method: "GET" | ||
, params: {limit: 1} | ||
}, callback); | ||
}); | ||
specify("doc_list:relaxed", timeout, function (assert) { | ||
nano.relax( | ||
{ db : "doc_list" | ||
, doc : "_all_docs" | ||
, method : "GET" | ||
, params : {limit: 1} | ||
}, function (error, docs) { | ||
assert.equal(error, undefined, "Relax didn't work"); | ||
assert.ok(docs.rows, "Got rows"); | ||
assert.equal(docs.rows.length, 1, "Only one row"); | ||
assert.equal(docs.total_rows, 3, "Got total three rows"); | ||
}); | ||
}; | ||
}); | ||
tests.ns_list_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_list:relaxed", timeout, function (assert) { | ||
db.list({startkey: 'c'}, function (error, docs) { | ||
assert.equal(error, undefined, "Startkey didn't work"); | ||
assert.ok(docs.rows, "Got rows"); | ||
assert.equal(docs.rows.length, 2, "Started in row two"); | ||
assert.equal(docs.total_rows, 3, "Got total three rows"); | ||
assert.equal(docs.offset, 1, "Offset by 1"); | ||
}); | ||
}); | ||
tests.list_doc_params = function (callback) { | ||
nano.db.create(db_name('c'), function () { | ||
async.parallel( | ||
[ function(cb) { db('c').insert({"foo": "bar"}, "foobar", cb); } | ||
, function(cb) { db('c').insert({"bar": "foo"}, "barfoo", cb); } | ||
, function(cb) { db('c').insert({"foo": "baz"}, "foobaz", cb); } | ||
], | ||
function(err, results){ | ||
db('c').list({startkey: 'c'},callback); | ||
}); | ||
specify("doc_list:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_list", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}; | ||
}); | ||
tests.list_doc_params_ok = function (e,b) { | ||
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]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,59 +0,39 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "doc/update") | ||
, db = nano.use("doc_update") | ||
, rev | ||
; | ||
function db(i) { return nano.use(db_name(i)); } | ||
tests.update_doc = function (callback) { | ||
nano.db.create(db_name('a'), function () { | ||
db('a').insert({foo: "bar"}, "foo", function (_,b) { | ||
db('a').insert({"_rev": b.rev, foo: "baz"}, "foo", callback); | ||
specify("doc_update:setup", timeout, function (assert) { | ||
nano.db.create("doc_update", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobar", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
rev = foo.rev; | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.update_doc_ok = function (e,b) { | ||
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'); | ||
}; | ||
specify("doc_update:test", timeout, function (assert) { | ||
db.insert({foo: "bar", "_rev": rev}, "foobar", function (error, response) { | ||
assert.equal(error, undefined, "Should have deleted foo"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
}); | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("doc_update:teardown", timeout, function (assert) { | ||
nano.db.destroy("doc_update", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,27 +0,87 @@ | ||
var ensure = require('ensure') | ||
, err = require('../../error') | ||
, tests = exports; | ||
var specify = require("specify") | ||
, helpers = require("../helpers") | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, Nano = helpers.Nano | ||
, nock = helpers.nock | ||
; | ||
tests.empty_error = function (callback) { | ||
callback(null,err.couch(null,null,null,null)); | ||
}; | ||
var mock = nock(helpers.couch, "shared/error") | ||
, db = nano.use("shared_error") | ||
; | ||
tests.empty_error_ok = function (_,e) { | ||
this.t.equal(e.message, "Unknown Error"); | ||
this.t.equal(e['status-code'], 500); | ||
this.t.equal(e.error, "unknown"); | ||
this.t.ok(typeof e.request === 'object'); | ||
}; | ||
specify("shared_error:setup", timeout, function (assert) { | ||
nano.db.create("shared_error", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foobaz"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
assert.equal(foo.id, "foobaz", "My id is foobaz"); | ||
assert.ok(foo.rev, "Response should have rev"); | ||
}); | ||
}); | ||
}); | ||
tests.error_412 = function (callback) { | ||
callback(null,err.couch(null,null,null,412)); | ||
}; | ||
specify("shared_error:conflict", timeout, function (assert) { | ||
db.insert({"foo": "bar"}, "foobaz", function (error, response) { | ||
assert.equal(error["status-code"], 409, "Should be conflict"); | ||
assert.equal(error.scope, "couch", "Scope is couch"); | ||
assert.equal(error.error, "conflict", "Error is conflict"); | ||
}); | ||
}); | ||
tests.error_412_ok = function (_,e) { | ||
this.t.equal(e.message, "Precondition Failed"); | ||
this.t.equal(e['status-code'], 412); | ||
this.t.equal(e.error, "unknown"); | ||
this.t.ok(typeof e.request === 'object'); | ||
}; | ||
specify("shared_error:init", timeout, function (assert) { | ||
try { | ||
Nano('Not a File'); | ||
} catch(err) { | ||
assert.ok(err, "There must be an error"); | ||
assert.ok(err.note, "A note is given"); | ||
assert.equal(err.errid, "bad_file", "Code is right"); | ||
assert.equal(err.scope, "init", "Scope is init"); | ||
} | ||
try { | ||
Nano({}); | ||
} catch(err2) { | ||
assert.ok(err2, "There must be an error"); | ||
assert.ok(err2.note, "A note is given"); | ||
assert.equal(err2.errid, "bad_url", "Code is right"); | ||
assert.equal(err2.scope, "init", "Scope is init"); | ||
} | ||
}); | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify("shared_error:root", timeout, function (assert) { | ||
// this shouldn't error | ||
var root = nano.request() | ||
, buffer = "" | ||
; | ||
root.on('data', function (chunk) { buffer += chunk; }); | ||
root.on('end', function () { | ||
assert.ok(true, "Ended"); | ||
}); | ||
}); | ||
specify("shared_error:stream", timeout, function (assert) { | ||
db.list("bad params").on('error', function (error) { | ||
assert.ok(error.note, "A note is given"); | ||
assert.equal(error.errid, "bad_params", "Code is right"); | ||
assert.equal(error.scope, "nano", "Scope exists"); | ||
}); | ||
}); | ||
specify("shared_error:callback", timeout, function (assert) { | ||
db.list("bad params", function (error, response) { | ||
assert.ok(error, "There must be an error"); | ||
assert.ok(error.note, "A note is given"); | ||
assert.equal(error.errid, "bad_params", "Code is right"); | ||
assert.equal(error.scope, "nano", "Scope exists"); | ||
}); | ||
}); | ||
specify("shared_error:teardown", timeout, function (assert) { | ||
nano.db.destroy("shared_error", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,11 +0,11 @@ | ||
var ensure = require('ensure') | ||
, nano = require('../../nano') | ||
, tests = exports; | ||
var specify = require('specify') | ||
, timeout = require('../helpers').timeout | ||
, nano = require('../../nano') | ||
; | ||
tests.version = function (callback) { callback(null,nano.version); }; | ||
tests.version_ok = function (_,n) { this.t.ok(n); }; | ||
specify("shared_nano:test", timeout, function (assert) { | ||
assert.ok(nano.version, "Version is defined"); | ||
assert.ok(nano.path, "Path is defined"); | ||
}); | ||
tests.path = function (callback) { callback(null,nano.path); }; | ||
tests.path_ok = function (_,n) { this.t.ok(n); }; | ||
ensure(__filename,tests,module,process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
@@ -1,103 +0,52 @@ | ||
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 | ||
, couch | ||
var specify = require('specify') | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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' }); | ||
var mock = nock(helpers.couch, "view/compact") | ||
, db = nano.use("view_compact") | ||
; | ||
tests.compact_view = function (callback) { | ||
nano.db.create(db_name('1'), function () { | ||
var db = nano.use(db_name('1')); | ||
async.parallel( | ||
[ function(cb) { db.insert({"foo": "bar"},"foobar",cb); } | ||
, function(cb) { db.insert({"bar": "foo"},"barfoo",cb); } | ||
, function(cb) { db.insert({"foo": "baz"},"foobaz",cb); } | ||
], | ||
function(err, results) { | ||
var foobaz_rev = results[2][0].rev; | ||
db.insert({"views": { "by_id": { | ||
"map": "function(doc) { emit(doc._id, doc); }" } } | ||
}, '_design/alice', function(e,b,h) { | ||
db.destroy('foobaz', foobaz_rev, function (e,b,h) { | ||
db.view.compact('alice', function(e,b,h) { | ||
db.view('alice','by_id', callback); | ||
}); | ||
}); | ||
specify("view_compact:setup", timeout, function (assert) { | ||
nano.db.create("view_compact", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert( | ||
{ "views": | ||
{ "by_id": | ||
{ "map": function(doc) { emit(doc._id, doc); } } | ||
} | ||
}, '_design/alice', function (error, response) { | ||
assert.equal(error, undefined, "Failed to create views"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
db.insert({"foo": "baz"}, "foobaz", function (error, foo) { | ||
assert.equal(error, undefined, "Should have stored foo"); | ||
assert.equal(foo.ok, true, "Response should be ok"); | ||
db.destroy("foobaz", foo.rev, function (error, response) { | ||
assert.equal(error, undefined, "Should have deleted foo"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); | ||
tests.compact_view_ok = function (err,view) { | ||
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'); | ||
}; | ||
specify("view_compact:test", timeout, function (assert) { | ||
db.view.compact("alice", function (error) { | ||
assert.equal(error, undefined, "Compact didn't respond"); | ||
db.view('alice','by_id', function (error, view) { | ||
assert.equal(error, undefined, "View didn't respond"); | ||
assert.equal(view.total_rows, 0, "Stuff got deleted"); | ||
}); | ||
}); | ||
}); | ||
ensure(__filename, tests, module,process.argv[2]); | ||
specify("view_compact:teardown", timeout, function (assert) { | ||
nano.db.destroy("view_compact", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
specify.run(process.argv.slice(2)); |
@@ -1,107 +0,58 @@ | ||
var ensure = require('ensure') | ||
, nock = require('nock') | ||
var specify = require('specify') | ||
, async = require('async') | ||
, cfg = require('../../cfg/tests.js') | ||
, nano = require('../../nano')(cfg) | ||
, db_name = require('../utils').db_name("view_qu") | ||
, tests = exports | ||
, couch | ||
, helpers = require('../helpers') | ||
, timeout = helpers.timeout | ||
, nano = helpers.nano | ||
, nock = helpers.nock | ||
; | ||
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': '12', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('2') + '/randall', | ||
{ "name": "Randall" | ||
, "city": "San Francisco // CA, USA" | ||
}) | ||
.reply(201, "{\"ok\":true,\"id\":\"randall\",\"rev\":\"1-37dfdbddd84354050154f2e39b6bda90\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('2') + '/randall', | ||
etag: '"1-37dfdbddd84354050154f2e39b6bda90"', | ||
date: 'Fri, 02 Dec 2011 03:19:26 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '70', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('2') + '/nuno', | ||
{ "name": "Nuno" | ||
, "city": "Porto // PT, Portugal" | ||
}) | ||
.reply(201, "{\"ok\":true,\"id\":\"nuno\",\"rev\":\"1-638d3cde87402899b4aacc6490c01d3b\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('2') + '/nuno', | ||
etag: '"1-638d3cde87402899b4aacc6490c01d3b"', | ||
date: 'Fri, 02 Dec 2011 03:19:26 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '67', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('2') + '/derek', | ||
{ "name": "Derek" | ||
, "city": "San Francisco // CA, USA"}) | ||
.reply(201, "{\"ok\":true,\"id\":\"derek\",\"rev\":\"1-f849b3014fcb990a74fca741edf34fea\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('2') + '/derek', | ||
etag: '"1-f849b3014fcb990a74fca741edf34fea"', | ||
date: 'Fri, 02 Dec 2011 03:19:26 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '68', | ||
'cache-control': 'must-revalidate' }) | ||
.put('/' + db_name('2') + '/_design/people', | ||
{"views": {"by_name_and_city": | ||
{"map":"function(doc) { emit([doc.name, doc.city], doc._id); }"}}}) | ||
.reply(201, "{\"ok\":true,\"id\":\"_design/people\",\"rev\":\"1-81370b2d35e19e28d491e81922bb9fba\"}\n", { server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
location: cfg.url + '/' + db_name('2') + '/_design/people', | ||
etag: '"1-81370b2d35e19e28d491e81922bb9fba"', | ||
date: 'Fri, 02 Dec 2011 03:19:27 GMT', | ||
'content-type': 'application/json', | ||
'content-length': '77', | ||
'cache-control': 'must-revalidate' }) | ||
.get('/' + db_name('2') + '/_design/people/_view/by_name_and_city?key=%5B%22Derek%22%2C%22San%20Francisco%20%2F%2F%20CA%2C%20USA%22%5D') | ||
.reply(200, "{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"derek\",\"key\":[\"Derek\",\"San Francisco // CA, USA\"],\"value\":\"derek\"}\r\n]}\n", { 'transfer-encoding': 'chunked', | ||
server: 'CouchDB/1.1.1 (Erlang OTP/R14B04)', | ||
etag: '"49G7ABUI3FOA4M2EHE2GG2OES"', | ||
date: 'Fri, 02 Dec 2011 03:19:27 GMT', | ||
'content-type': 'application/json', | ||
'cache-control': 'must-revalidate' }); | ||
var mock = nock(helpers.couch, "view/query") | ||
, db = nano.use("view_query") | ||
; | ||
function db_gen(i) { return nano.use(db_name(i)); } | ||
function complex_key_test(cb,i,params,map) { | ||
map = map ? map : 'emit([doc.city,doc.name], doc._id);'; | ||
nano.db.create(db_name(i), function () { | ||
var db = db_gen(i); | ||
async.parallel( | ||
[ function(cb2) { db.insert({name: "Derek", city: "San Francisco // CA, USA"}, "derek", cb2); } | ||
, function(cb2) { db.insert({name: "Randall", city: "San Francisco // CA, USA"}, "randall", cb2); } | ||
, function(cb2) { db.insert({name: "Nuno", city: "Porto // PT, Portugal"}, "nuno", cb2); } | ||
], | ||
function(err, results){ | ||
db.insert( | ||
{ "views": | ||
{ "by_name_and_city": | ||
{ "map": "function(doc) { " + map + " }" } | ||
} | ||
}, '_design/people' | ||
, function () { | ||
db.view('people','by_name_and_city', params, cb); | ||
}); | ||
specify("view_query:setup", timeout, function (assert) { | ||
nano.db.create("view_query", function (err) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
db.insert( | ||
{ "views": | ||
{ "by_name_and_city": | ||
{ "map": function(doc) { emit([doc.name, doc.city], doc._id); } } | ||
} | ||
}, '_design/people', function (error, response) { | ||
assert.equal(error, undefined, "Failed to create views"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
async.parallel( | ||
[ function(cb) { db.insert( | ||
{ name: "Derek", city: "San Francisco" }, "p_derek", cb); } | ||
, function(cb) { db.insert( | ||
{ name: "Randall", city: "San Francisco" }, "p_randall", cb); } | ||
, function(cb) { db.insert( | ||
{ name: "Nuno", city: "New York" }, "p_nuno", cb); } | ||
] | ||
, function(error, results) { | ||
assert.equal(error, undefined, "Should have stored docs"); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
tests.array_in_key = function (cb) { | ||
complex_key_test(cb,"2",{key: ["Derek","San Francisco // CA, USA"]},'emit([doc.name, doc.city], doc._id);'); | ||
}; | ||
specify("view_query:test", timeout, function (assert) { | ||
db.view('people','by_name_and_city', | ||
{key: ["Derek","San Francisco"]}, function (error, view) { | ||
assert.equal(error, undefined, "View didn't respond"); | ||
assert.equal(view.rows.length,1); | ||
assert.equal(view.rows.length,1); | ||
assert.equal(view.rows[0].id,'p_derek'); | ||
assert.equal(view.rows[0].key[0],'Derek'); | ||
assert.equal(view.rows[0].key[1],'San Francisco'); | ||
}); | ||
}); | ||
tests.array_in_key_ok = function (e,b,h) { | ||
this.t.notOk(e); | ||
this.t.equal(b.rows.length,1); | ||
this.t.equal(b.rows.length,1); | ||
this.t.equal(b.rows[0].id,'derek'); | ||
this.t.equal(b.rows[0].key[0],'Derek'); | ||
this.t.equal(b.rows[0].key[1],'San Francisco // CA, USA'); | ||
}; | ||
specify("view_query:teardown", timeout, function (assert) { | ||
nano.db.destroy("view_query", function (err) { | ||
assert.equal(err, undefined, "Failed to destroy database"); | ||
assert.ok(mock.isDone(), "Some mocks didn't run"); | ||
}); | ||
}); | ||
ensure(__filename, tests, module, process.argv[2]); | ||
specify.run(process.argv.slice(2)); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
68
565
112454
2
2803
1
7
1
+ Addedfollow@*
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbrowser-request@0.3.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfollow@1.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.0(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)