Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 062f48b

Browse files
committed
Run partitioned_databases.js tests only against Cloudant databases.
1 parent 77dcd29 commit 062f48b

File tree

1 file changed

+147
-145
lines changed

1 file changed

+147
-145
lines changed

test/partitioned_databases.js

Lines changed: 147 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -26,194 +26,196 @@ const PASSWORD = process.env.cloudant_password || 'sjedon';
2626
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727
const DBNAME = `nodejs-cloudant-${uuidv4()}`;
2828

29-
describe('Partitioned Databases #db', () => {
30-
const partitionKeys = Array.apply(null, {length: 10})
31-
.map(() => { return uuidv4(); });
32-
33-
before(() => {
34-
var mocks = nock(SERVER)
35-
.put(`/${DBNAME}`)
36-
.query({ partitioned: true })
37-
.reply(201, { ok: true });
38-
39-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
40-
return cloudant.db.create(DBNAME, { partitioned: true }).then((body) => {
41-
assert.ok(body.ok);
42-
mocks.done();
29+
if (SERVER.endsWith('.cloudant.com')) {
30+
describe('Partitioned Databases #db', () => {
31+
const partitionKeys = Array.apply(null, {length: 10})
32+
.map(() => { return uuidv4(); });
33+
34+
before(() => {
35+
var mocks = nock(SERVER)
36+
.put(`/${DBNAME}`)
37+
.query({ partitioned: true })
38+
.reply(201, { ok: true });
39+
40+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
41+
return cloudant.db.create(DBNAME, { partitioned: true }).then((body) => {
42+
assert.ok(body.ok);
43+
mocks.done();
44+
});
4345
});
44-
});
4546

46-
after(() => {
47-
var mocks = nock(SERVER)
48-
.delete(`/${DBNAME}`)
49-
.reply(200, { ok: true });
47+
after(() => {
48+
var mocks = nock(SERVER)
49+
.delete(`/${DBNAME}`)
50+
.reply(200, { ok: true });
5051

51-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
52-
return cloudant.db.destroy(DBNAME).then((body) => {
53-
assert.ok(body.ok);
54-
mocks.done();
52+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
53+
return cloudant.db.destroy(DBNAME).then((body) => {
54+
assert.ok(body.ok);
55+
mocks.done();
56+
});
5557
});
56-
});
5758

58-
it('created a partitioned database', () => {
59-
var mocks = nock(SERVER)
60-
.get(`/${DBNAME}`)
61-
.reply(200, { props: { partitioned: true } });
59+
it('created a partitioned database', () => {
60+
var mocks = nock(SERVER)
61+
.get(`/${DBNAME}`)
62+
.reply(200, { props: { partitioned: true } });
6263

63-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
64-
return cloudant.db.get(DBNAME).then((body) => {
65-
assert.ok(body.props.partitioned);
66-
mocks.done();
64+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
65+
return cloudant.db.get(DBNAME).then((body) => {
66+
assert.ok(body.props.partitioned);
67+
mocks.done();
68+
});
6769
});
68-
});
6970

70-
it('create some partitioned documents', function(done) {
71-
if (!process.env.NOCK_OFF) {
72-
this.skip();
73-
}
74-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
75-
const db = cloudant.db.use(DBNAME);
76-
77-
var q = async.queue(function(task, callback) {
78-
db.bulk({ 'docs': task.docs }).then(callback).catch(done);
79-
}, 10);
80-
q.drain = done;
81-
82-
for (let i in partitionKeys) {
83-
let docs = [];
84-
for (let j = 0; j < 10; j++) {
85-
docs.push({ _id: `${partitionKeys[i]}:doc${j}`, foo: 'bar' });
71+
it('create some partitioned documents', function(done) {
72+
if (!process.env.NOCK_OFF) {
73+
this.skip();
8674
}
87-
q.push({ 'docs': docs });
88-
}
89-
});
90-
91-
it('get partition information', () => {
92-
const pKey = partitionKeys[0];
75+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
76+
const db = cloudant.db.use(DBNAME);
9377

94-
var mocks = nock(SERVER)
95-
.get(`/${DBNAME}/_partition/${pKey}`)
96-
.reply(200, { partition: pKey, doc_count: 10 });
78+
var q = async.queue(function(task, callback) {
79+
db.bulk({ 'docs': task.docs }).then(callback).catch(done);
80+
}, 10);
81+
q.drain = done;
9782

98-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
99-
const db = cloudant.db.use(DBNAME);
100-
return db.partitionInfo(pKey).then((body) => {
101-
assert.equal(body.partition, pKey);
102-
assert.equal(body.doc_count, 10);
103-
mocks.done();
83+
for (let i in partitionKeys) {
84+
let docs = [];
85+
for (let j = 0; j < 10; j++) {
86+
docs.push({ _id: `${partitionKeys[i]}:doc${j}`, foo: 'bar' });
87+
}
88+
q.push({ 'docs': docs });
89+
}
10490
});
105-
});
106-
107-
it('get all documents in a partition', () => {
108-
const pKey = partitionKeys[0];
10991

110-
var mocks = nock(SERVER)
111-
.get(`/${DBNAME}/_partition/${pKey}/_all_docs`)
112-
.reply(200, { rows: new Array(10) });
92+
it('get partition information', () => {
93+
const pKey = partitionKeys[0];
11394

114-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
115-
const db = cloudant.db.use(DBNAME);
116-
return db.partitionedList(pKey).then((body) => {
117-
assert.equal(body.rows.length, 10);
118-
mocks.done();
119-
});
120-
});
95+
var mocks = nock(SERVER)
96+
.get(`/${DBNAME}/_partition/${pKey}`)
97+
.reply(200, { partition: pKey, doc_count: 10 });
12198

122-
describe('Partitioned Query', () => {
123-
before(() => {
124-
if (!process.env.NOCK_OFF) {
125-
return;
126-
}
12799
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
128100
const db = cloudant.db.use(DBNAME);
129-
return db.createIndex({ index: { fields: ['foo'] } }).then((body) => {
130-
assert.equal(body.result, 'created');
101+
return db.partitionInfo(pKey).then((body) => {
102+
assert.equal(body.partition, pKey);
103+
assert.equal(body.doc_count, 10);
104+
mocks.done();
131105
});
132106
});
133107

134-
it('query a partitioned query', () => {
108+
it('get all documents in a partition', () => {
135109
const pKey = partitionKeys[0];
136-
const selector = { selector: { foo: { $eq: 'bar' } } };
137110

138111
var mocks = nock(SERVER)
139-
.post(`/${DBNAME}/_partition/${pKey}/_find`, selector)
140-
.reply(200, { docs: new Array(10) });
112+
.get(`/${DBNAME}/_partition/${pKey}/_all_docs`)
113+
.reply(200, { rows: new Array(10) });
141114

142115
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
143116
const db = cloudant.db.use(DBNAME);
144-
return db.partitionedFind(pKey, selector).then((body) => {
145-
assert(body.docs.length, 10);
117+
return db.partitionedList(pKey).then((body) => {
118+
assert.equal(body.rows.length, 10);
146119
mocks.done();
147120
});
148121
});
149-
});
150122

151-
describe('Partitioned Search', () => {
152-
before(() => {
153-
if (!process.env.NOCK_OFF) {
154-
return;
155-
}
156-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
157-
const db = cloudant.db.use(DBNAME);
158-
return db.insert({
159-
_id: '_design/mysearch',
160-
options: { partitioned: true },
161-
indexes: {
162-
search1: {
163-
index: 'function(doc) { index("id", doc._id, {"store": true}); }'
164-
}
123+
describe('Partitioned Query', () => {
124+
before(() => {
125+
if (!process.env.NOCK_OFF) {
126+
return;
165127
}
166-
}).then((body) => {
167-
assert.ok(body.ok);
128+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
129+
const db = cloudant.db.use(DBNAME);
130+
return db.createIndex({ index: { fields: ['foo'] } }).then((body) => {
131+
assert.equal(body.result, 'created');
132+
});
168133
});
169-
});
170134

171-
it('query a partitioned search', () => {
172-
const pKey = partitionKeys[0];
135+
it('query a partitioned query', () => {
136+
const pKey = partitionKeys[0];
137+
const selector = { selector: { foo: { $eq: 'bar' } } };
173138

174-
var mocks = nock(SERVER)
175-
.post(`/${DBNAME}/_partition/${pKey}/_design/mysearch/_search/search1`,
176-
{ q: '*:*' })
177-
.reply(200, { rows: new Array(10) });
139+
var mocks = nock(SERVER)
140+
.post(`/${DBNAME}/_partition/${pKey}/_find`, selector)
141+
.reply(200, { docs: new Array(10) });
178142

179-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
180-
const db = cloudant.db.use(DBNAME);
181-
return db.partitionedSearch(pKey, 'mysearch', 'search1', { q: '*:*' }).then((body) => {
182-
assert(body.rows.length, 10);
183-
mocks.done();
143+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
144+
const db = cloudant.db.use(DBNAME);
145+
return db.partitionedFind(pKey, selector).then((body) => {
146+
assert(body.docs.length, 10);
147+
mocks.done();
148+
});
184149
});
185150
});
186-
});
187151

188-
describe('Partitioned View', () => {
189-
before(() => {
190-
if (!process.env.NOCK_OFF) {
191-
return;
192-
}
193-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
194-
const db = cloudant.db.use(DBNAME);
195-
return db.insert({
196-
_id: '_design/myview',
197-
options: { partitioned: true },
198-
views: { view1: { map: 'function(doc) { emit(doc._id, 1); }' } }
199-
}).then((body) => {
200-
assert.ok(body.ok);
152+
describe('Partitioned Search', () => {
153+
before(() => {
154+
if (!process.env.NOCK_OFF) {
155+
return;
156+
}
157+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
158+
const db = cloudant.db.use(DBNAME);
159+
return db.insert({
160+
_id: '_design/mysearch',
161+
options: { partitioned: true },
162+
indexes: {
163+
search1: {
164+
index: 'function(doc) { index("id", doc._id, {"store": true}); }'
165+
}
166+
}
167+
}).then((body) => {
168+
assert.ok(body.ok);
169+
});
170+
});
171+
172+
it('query a partitioned search', () => {
173+
const pKey = partitionKeys[0];
174+
175+
var mocks = nock(SERVER)
176+
.post(`/${DBNAME}/_partition/${pKey}/_design/mysearch/_search/search1`,
177+
{ q: '*:*' })
178+
.reply(200, { rows: new Array(10) });
179+
180+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
181+
const db = cloudant.db.use(DBNAME);
182+
return db.partitionedSearch(pKey, 'mysearch', 'search1', { q: '*:*' }).then((body) => {
183+
assert(body.rows.length, 10);
184+
mocks.done();
185+
});
201186
});
202187
});
203188

204-
it('query a partitioned view', () => {
205-
const pKey = partitionKeys[0];
189+
describe('Partitioned View', () => {
190+
before(() => {
191+
if (!process.env.NOCK_OFF) {
192+
return;
193+
}
194+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
195+
const db = cloudant.db.use(DBNAME);
196+
return db.insert({
197+
_id: '_design/myview',
198+
options: { partitioned: true },
199+
views: { view1: { map: 'function(doc) { emit(doc._id, 1); }' } }
200+
}).then((body) => {
201+
assert.ok(body.ok);
202+
});
203+
});
206204

207-
var mocks = nock(SERVER)
208-
.get(`/${DBNAME}/_partition/${pKey}/_design/myview/_view/view1`)
209-
.reply(200, { rows: new Array(10) });
205+
it('query a partitioned view', () => {
206+
const pKey = partitionKeys[0];
210207

211-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
212-
const db = cloudant.db.use(DBNAME);
213-
return db.partitionedView(pKey, 'myview', 'view1').then((body) => {
214-
assert(body.rows.length, 10);
215-
mocks.done();
208+
var mocks = nock(SERVER)
209+
.get(`/${DBNAME}/_partition/${pKey}/_design/myview/_view/view1`)
210+
.reply(200, { rows: new Array(10) });
211+
212+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
213+
const db = cloudant.db.use(DBNAME);
214+
return db.partitionedView(pKey, 'myview', 'view1').then((body) => {
215+
assert(body.rows.length, 10);
216+
mocks.done();
217+
});
216218
});
217219
});
218220
});
219-
});
221+
}

0 commit comments

Comments
 (0)