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

Commit 87b9677

Browse files
authored
Merge pull request #404 from cloudant/always-run-partitioned-db-tests
Revert "Run partitioned_databases.js tests only against Cloudant databases."
2 parents 52065c9 + 7699b3f commit 87b9677

File tree

1 file changed

+145
-147
lines changed

1 file changed

+145
-147
lines changed

test/partitioned_databases.js

Lines changed: 145 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -26,196 +26,194 @@ 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-
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, plugins: [] });
41-
return cloudant.db.create(DBNAME, { partitioned: true }).then((body) => {
42-
assert.ok(body.ok);
43-
mocks.done();
44-
});
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, plugins: [] });
40+
return cloudant.db.create(DBNAME, { partitioned: true }).then((body) => {
41+
assert.ok(body.ok);
42+
mocks.done();
4543
});
44+
});
4645

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

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

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

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

71-
it('create some partitioned documents', function(done) {
72-
if (!process.env.NOCK_OFF) {
73-
this.skip();
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, plugins: [] });
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' });
7486
}
75-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
76-
const db = cloudant.db.use(DBNAME);
87+
q.push({ 'docs': docs });
88+
}
89+
});
7790

78-
var q = async.queue(function(task, callback) {
79-
db.bulk({ 'docs': task.docs }).then(callback).catch(done);
80-
}, 10);
81-
q.drain = done;
91+
it('get partition information', () => {
92+
const pKey = partitionKeys[0];
8293

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-
}
94+
var mocks = nock(SERVER)
95+
.get(`/${DBNAME}/_partition/${pKey}`)
96+
.reply(200, { partition: pKey, doc_count: 10 });
97+
98+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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();
90104
});
105+
});
91106

92-
it('get partition information', () => {
93-
const pKey = partitionKeys[0];
107+
it('get all documents in a partition', () => {
108+
const pKey = partitionKeys[0];
94109

95-
var mocks = nock(SERVER)
96-
.get(`/${DBNAME}/_partition/${pKey}`)
97-
.reply(200, { partition: pKey, doc_count: 10 });
110+
var mocks = nock(SERVER)
111+
.get(`/${DBNAME}/_partition/${pKey}/_all_docs`)
112+
.reply(200, { rows: new Array(10) });
98113

114+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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+
});
121+
122+
describe('Partitioned Query', () => {
123+
before(() => {
124+
if (!process.env.NOCK_OFF) {
125+
return;
126+
}
99127
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
100128
const db = cloudant.db.use(DBNAME);
101-
return db.partitionInfo(pKey).then((body) => {
102-
assert.equal(body.partition, pKey);
103-
assert.equal(body.doc_count, 10);
104-
mocks.done();
129+
return db.createIndex({ index: { fields: ['foo'] } }).then((body) => {
130+
assert.equal(body.result, 'created');
105131
});
106132
});
107133

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

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

115142
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
116143
const db = cloudant.db.use(DBNAME);
117-
return db.partitionedList(pKey).then((body) => {
118-
assert.equal(body.rows.length, 10);
144+
return db.partitionedFind(pKey, selector).then((body) => {
145+
assert(body.docs.length, 10);
119146
mocks.done();
120147
});
121148
});
149+
});
122150

123-
describe('Partitioned Query', () => {
124-
before(() => {
125-
if (!process.env.NOCK_OFF) {
126-
return;
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, plugins: [] });
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+
}
127165
}
128-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
129-
const db = cloudant.db.use(DBNAME);
130-
return db.createIndex({ index: { fields: ['foo'] } }).then((body) => {
131-
assert.equal(body.result, 'created');
132-
});
133-
});
134-
135-
it('query a partitioned query', () => {
136-
const pKey = partitionKeys[0];
137-
const selector = { selector: { foo: { $eq: 'bar' } } };
138-
139-
var mocks = nock(SERVER)
140-
.post(`/${DBNAME}/_partition/${pKey}/_find`, selector)
141-
.reply(200, { docs: new Array(10) });
142-
143-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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-
});
166+
}).then((body) => {
167+
assert.ok(body.ok);
149168
});
150169
});
151170

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, plugins: [] });
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];
171+
it('query a partitioned search', () => {
172+
const pKey = partitionKeys[0];
174173

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

180-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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-
});
179+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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();
186184
});
187185
});
186+
});
188187

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, plugins: [] });
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-
});
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, plugins: [] });
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);
203201
});
202+
});
204203

205-
it('query a partitioned view', () => {
206-
const pKey = partitionKeys[0];
204+
it('query a partitioned view', () => {
205+
const pKey = partitionKeys[0];
207206

208-
var mocks = nock(SERVER)
209-
.get(`/${DBNAME}/_partition/${pKey}/_design/myview/_view/view1`)
210-
.reply(200, { rows: new Array(10) });
207+
var mocks = nock(SERVER)
208+
.get(`/${DBNAME}/_partition/${pKey}/_design/myview/_view/view1`)
209+
.reply(200, { rows: new Array(10) });
211210

212-
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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-
});
211+
const cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: [] });
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();
218216
});
219217
});
220218
});
221-
}
219+
});

0 commit comments

Comments
 (0)