This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
replicate.js
66 lines (60 loc) · 2.23 KB
/
replicate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var specify = require('specify')
, async = require('async')
, helpers = require('../helpers')
, timeout = helpers.timeout
, nano = helpers.nano
, nock = helpers.nock
;
var mock = nock(helpers.couch, "db/replicate")
, db = nano.use("db_replicate")
, replica = nano.use("db_replica")
, replica2 = nano.use("db_replica2")
;
specify("db_replicate:setup", timeout, function (assert) {
async.series(
[ function(cb) { nano.db.create("db_replicate", cb); }
, function(cb) { nano.db.create("db_replica", cb); }
, function(cb) { nano.db.create("db_replica2", cb); }
]
, function(error, results) {
assert.equal(error, undefined, "Should have created databases");
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");
});
});
});
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");
});
});
});
specify("db_replicate:test_objects", timeout, function (assert) {
nano.db.replicate(db, replica2, function(error) {
assert.equal(error, undefined, "Should be able to replicate");
replica2.list(function (error, list) {
assert.equal(error, undefined, "Should be able to list");
assert.equal(list.total_rows, 3, "Should have three documents");
});
});
});
specify("db_replicate:teardown", timeout, function (assert) {
async.series(
[ function(cb) { nano.db.destroy("db_replicate", cb); }
, function(cb) { nano.db.destroy("db_replica", cb); }
, function(cb) { nano.db.destroy("db_replica2", cb); }
]
, function(error, results) {
assert.equal(error, undefined, "Should have deleted databases");
assert.ok(mock.isDone(), "Some mocks didn't run");
});
});
specify.run(process.argv.slice(2));