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

Commit 7141e96

Browse files
authored
Merge pull request #339 from cloudant/custom-url
Custom url & test tagging
2 parents cfd24b0 + bd55a1c commit 7141e96

File tree

14 files changed

+98
-88
lines changed

14 files changed

+98
-88
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ You can add verbose debug messages while running tests by doing:
4949
```
5050
DEBUG=* npm test
5151
```
52+
53+
### Test configuration
54+
55+
When testing with a real server (i.e. `NOCK_OFF=true`) these options are
56+
available to set as environment variables:
57+
`cloudant_username` - username
58+
`cloudant_password` - password
59+
`SERVER_URL` - the URL to use (defaults to `https://$cloudant_user.cloudant.com`)

soak_tests/soak.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const uuidv4 = require('uuid/v4'); // random
2222

2323
const USER = process.env.cloudant_username || 'nodejs';
2424
const PASSWORD = process.env.cloudant_password || 'sjedon';
25-
const SERVER = `https://${USER}:${PASSWORD}@${USER}.cloudant.com`;
25+
const SERVER = process.env.SERVER_URL || `https://${USER}:${PASSWORD}@${USER}.cloudant.com`;
2626

2727
const MAX_RUNS = parseInt(process.env.max_runs, 10) || 100;
2828
const CONCURRENCY = parseInt(process.env.concurrency, 10) || 1;

test/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const uuidv4 = require('uuid/v4'); // random
2424

2525
const ME = process.env.cloudant_username || 'nodejs';
2626
const PASSWORD = process.env.cloudant_password || 'sjedon';
27-
const SERVER = `https://${ME}.cloudant.com`;
27+
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2828
const DBNAME = `/nodejs-cloudant-${uuidv4()}`;
2929
const DOCID = 'doc1';
3030

@@ -239,7 +239,7 @@ describe('CloudantClient', function() {
239239
}, 8000);
240240
});
241241

242-
it('after plugin execution phase', function(done) {
242+
it('after plugin execution phase #db', function(done) {
243243
var mocks = nock(SERVER)
244244
.get(DBNAME)
245245
.reply(200, {doc_count: 1});
@@ -264,7 +264,7 @@ describe('CloudantClient', function() {
264264
});
265265
});
266266

267-
describe('using callbacks', function() {
267+
describe('#db using callbacks', function() {
268268
describe('with no plugins', function() {
269269
it('performs request and returns response', function(done) {
270270
var mocks = nock(SERVER)
@@ -816,7 +816,7 @@ describe('CloudantClient', function() {
816816
});
817817
});
818818

819-
describe('using listeners', function() {
819+
describe('#db using listeners', function() {
820820
describe('with no plugins', function() {
821821
it('performs request and returns response', function(done) {
822822
var mocks = nock(SERVER)

test/clientutils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const testPlugin = require('./fixtures/testplugins.js');
2323
const utils = require('../lib/clientutils.js');
2424

2525
const ME = process.env.cloudant_username || 'nodejs';
26-
const SERVER = `https://${ME}.cloudant.com`;
26+
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727

2828
describe('Client Utilities', function() {
2929
afterEach(function() {

test/cloudant.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const uuidv4 = require('uuid/v4'); // random
2323

2424
const ME = process.env.cloudant_username || 'nodejs';
2525
const PASSWORD = process.env.cloudant_password || 'sjedon';
26-
const SERVER = `https://${ME}.cloudant.com`;
26+
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727
const DBNAME = `nodejs-cloudant-${uuidv4()}`;
2828

29-
describe('Cloudant', function() {
29+
describe('Cloudant #db', function() {
3030
before(function(done) {
3131
var mocks = nock(SERVER)
3232
.put(`/${DBNAME}`)
@@ -77,7 +77,7 @@ describe('Cloudant', function() {
7777
.get(`/_api/v2/db/${DBNAME}/_security`)
7878
.reply(200, security);
7979

80-
var cloudant = Cloudant({ account: ME, password: PASSWORD });
80+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
8181
var db = cloudant.db.use(DBNAME);
8282

8383
db.set_security(security, function(err, result) {
@@ -103,7 +103,7 @@ describe('Cloudant', function() {
103103
.get(`/_api/v2/db/${DBNAME}/_security`)
104104
.reply(200, security);
105105

106-
var cloudant = Cloudant({ account: ME, password: PASSWORD });
106+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
107107
var db = cloudant.db.use(DBNAME);
108108

109109
db.set_security(role, function(err, result) {
@@ -138,7 +138,7 @@ describe('Cloudant', function() {
138138
.get(`/_api/v2/db/${DBNAME}/_security`)
139139
.reply(200, security);
140140

141-
var cloudant = Cloudant({ account: ME, password: PASSWORD });
141+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
142142
var db = cloudant.db.use(DBNAME);
143143

144144
db.set_security(security, function(err, result) {

test/fixtures/testplugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 IBM Corp. All rights reserved.
1+
// Copyright © 2017, 2018 IBM Corp. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@ const assert = require('assert');
1717
const BasePlugin = require('../../plugins/base.js');
1818

1919
const ME = process.env.cloudant_username || 'nodejs';
20-
const SERVER = `https://${ME}.cloudant.com`;
20+
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2121

2222
// NoopPlugin for testing
2323

test/issues/292.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ const uuidv4 = require('uuid/v4'); // random
2323

2424
const ME = process.env.cloudant_username || 'nodejs';
2525
const PASSWORD = process.env.cloudant_password || 'sjedon';
26-
const SERVER = `https://${ME}.cloudant.com`;
26+
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727
const DBNAME = `nodejs-cloudant-${uuidv4()}`;
2828

29-
describe('Issue #292', function() {
29+
describe('#db Issue #292', function() {
3030
before(function(done) {
3131
var mocks = nock(SERVER)
3232
.put(`/${DBNAME}`)
@@ -72,7 +72,7 @@ describe('Issue #292', function() {
7272
.get(`/${DBNAME}/_index`)
7373
.reply(200, { total_rows: 1, indexes: [ { name: '_all_docs' } ] });
7474

75-
var cloudant = Cloudant({ account: ME, password: PASSWORD, plugins: 'promises' });
75+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'promises' });
7676
var db = cloudant.db.use(DBNAME);
7777

7878
db.index().then((d) => {
@@ -94,7 +94,7 @@ describe('Issue #292', function() {
9494
.post(`/${DBNAME}/_index`, definition)
9595
.reply(200, { result: 'created' });
9696

97-
var cloudant = Cloudant({ account: ME, password: PASSWORD, plugins: 'promises' });
97+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'promises' });
9898
var db = cloudant.db.use(DBNAME);
9999

100100
db.index(definition).then((d) => {

test/legacy/api.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Cloudant = require('../../cloudant.js');
2828
// These globals may potentially be parameterized.
2929
var ME = process.env.cloudant_username || 'nodejs';
3030
var PASSWORD = process.env.cloudant_password || 'sjedon';
31-
var SERVER = 'https://' + ME + '.cloudant.com';
31+
var SERVER = process.env.SERVER_URL || 'https://' + ME + '.cloudant.com';
3232
var mydb = null;
3333
var cc = null;
3434
var ddoc = null;
@@ -43,7 +43,7 @@ describe('Cloudant API', function() {
4343
});
4444
});
4545

46-
describe('Initialization', function() {
46+
describe('#db Initialization', function() {
4747
it('runs synchronously with one argument', function() {
4848
(function() {
4949
var db = Cloudant({account: ME});
@@ -55,7 +55,7 @@ describe('Initialization', function() {
5555
.post('/_session').reply(200, {ok: true})
5656
.get('/').reply(200, {couchdb: 'Welcome', version: '1.0.2'});
5757

58-
Cloudant({account: ME, username: ME, password: PASSWORD}, function(er, cloudant, body) {
58+
Cloudant({url: SERVER, username: ME, password: PASSWORD}, function(er, cloudant, body) {
5959
should(er).equal(null, 'No problem pinging Cloudant');
6060
cloudant.should.be.an.Object;
6161
body.should.be.an.Object;
@@ -89,7 +89,7 @@ describe('Initialization', function() {
8989
.post('/_session').reply(200, {ok: true, userCtx: {name: ME, roles: []}})
9090
.get('/').reply(200, {couchdb: 'Welcome', version: '1.0.2'});
9191

92-
Cloudant({account: ME, username: ME, password: PASSWORD}, function(er, cloudant, welcome) {
92+
Cloudant({url: SERVER, username: ME, password: PASSWORD}, function(er, cloudant, welcome) {
9393
should(er).equal(null, 'No problem pinging Cloudant');
9494
cloudant.should.be.an.Object;
9595

@@ -110,12 +110,12 @@ describe('Initialization', function() {
110110
});
111111
});
112112

113-
describe('Authentication', function() {
113+
describe('#db Authentication', function() {
114114
it('supports Authentication API - POST /_api/v2/api_keys', function(done) {
115115
var mocks = nock(SERVER)
116116
.post('/_api/v2/api_keys').reply(200, { 'password': 'Eivln4jPiLS8BoTxjXjVukDT', 'ok': true, 'key': 'thandoodstrenterprourete' });
117117

118-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
118+
var c = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: 'retry'});
119119
c.generate_api_key(function(er, d) {
120120
should(er).equal(null);
121121
d.should.be.an.Object;
@@ -132,12 +132,12 @@ describe('Authentication', function() {
132132
});
133133
});
134134

135-
describe('CORS', function() {
135+
describe('#db CORS', function() {
136136
it('supports CORS API - GET /_api/v2/user/config/cors', function(done) {
137137
var mocks = nock(SERVER)
138138
.get('/_api/v2/user/config/cors').reply(200, { 'enable_cors': true, 'allow_credentials': true, 'origins': ['*']});
139139

140-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
140+
var c = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: 'retry'});
141141
c.get_cors(function(er, d) {
142142
should(er).equal(null);
143143
d.should.be.an.Object;
@@ -157,7 +157,7 @@ describe('CORS', function() {
157157
var mocks = nock(SERVER)
158158
.put('/_api/v2/user/config/cors').reply(200, { 'ok': true });
159159

160-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
160+
var c = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: 'retry'});
161161
c.set_cors({ 'enable_cors': true, 'allow_credentials': true, 'origins': ['*']}, function(er, d) {
162162
should(er).equal(null);
163163
d.should.be.an.Object;
@@ -170,7 +170,7 @@ describe('CORS', function() {
170170
});
171171
});
172172

173-
describe('Authorization', function() {
173+
describe('#db Authorization', function() {
174174
var dbName;
175175

176176
before(function(done) {
@@ -179,7 +179,7 @@ describe('Authorization', function() {
179179
var mocks = nock(SERVER)
180180
.put('/' + dbName).reply(200, { 'ok': true });
181181

182-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
182+
cc = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: 'retry'});
183183
cc.db.create(dbName, function(er, d) {
184184
should(er).equal(null);
185185
d.should.be.an.Object;
@@ -239,7 +239,7 @@ describe('Authorization', function() {
239239
});
240240
});
241241

242-
describe('Cloudant-Specific APIs', function() {
242+
describe('#db Cloudant-Specific APIs', function() {
243243
var dbName;
244244

245245
before(function(done) {
@@ -248,7 +248,7 @@ describe('Cloudant-Specific APIs', function() {
248248
var mocks = nock(SERVER)
249249
.put('/' + dbName).reply(200, { 'ok': true });
250250

251-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
251+
cc = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: 'retry'});
252252
cc.db.create(dbName, function(er, d) {
253253
should(er).equal(null);
254254
d.should.be.an.Object;
@@ -349,7 +349,7 @@ describe('Cloudant-Specific APIs', function() {
349349
});
350350
});
351351

352-
describe('Changes query', function() {
352+
describe('#db Changes query', function() {
353353
var dbName;
354354

355355
before(function(done) {
@@ -358,7 +358,7 @@ describe('Changes query', function() {
358358
var mocks = nock(SERVER)
359359
.put('/' + dbName).reply(200, { 'ok': true });
360360

361-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
361+
cc = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
362362
cc.db.create(dbName, function(er, d) {
363363
should(er).equal(null);
364364
d.should.be.an.Object;
@@ -465,7 +465,7 @@ describe('Changes query', function() {
465465
});
466466
});
467467

468-
describe('Changes follower', function() {
468+
describe('#db Changes follower', function() {
469469
var dbName;
470470

471471
before(function(done) {
@@ -474,7 +474,7 @@ describe('Changes follower', function() {
474474
var mocks = nock(SERVER)
475475
.put('/' + dbName).reply(200, { 'ok': true });
476476

477-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
477+
cc = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
478478
cc.db.create(dbName, function(er, d) {
479479
should(er).equal(null);
480480
d.should.be.an.Object;
@@ -606,7 +606,7 @@ describe('Changes follower', function() {
606606
});
607607
});
608608

609-
describe('Cloudant Query', function() {
609+
describe('#db Cloudant Query', function() {
610610
var dbName;
611611

612612
before(function(done) {
@@ -615,7 +615,7 @@ describe('Cloudant Query', function() {
615615
var mocks = nock(SERVER)
616616
.put('/' + dbName).reply(200, { 'ok': true });
617617

618-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
618+
cc = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
619619
cc.db.create(dbName, function(er, d) {
620620
should(er).equal(null);
621621
d.should.be.an.Object;
@@ -749,7 +749,7 @@ describe('Cloudant Query', function() {
749749
});
750750
});
751751

752-
describe('Cloudant Search', function() {
752+
describe('#db Cloudant Search', function() {
753753
var dbName;
754754

755755
before(function(done) {
@@ -758,7 +758,7 @@ describe('Cloudant Search', function() {
758758
var mocks = nock(SERVER)
759759
.put('/' + dbName).reply(200, { 'ok': true });
760760

761-
cc = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
761+
cc = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
762762
cc.db.create(dbName, function(er, d) {
763763
should(er).equal(null);
764764
d.should.be.an.Object;
@@ -938,7 +938,7 @@ describe('Gzip header tests', function() {
938938
});
939939

940940
if (!process.env.NOCK_OFF) {
941-
describe('Gzip attachment tests', test_gzip);
941+
describe('#db Gzip attachment tests', test_gzip);
942942
}
943943
function test_gzip() {
944944
it('checks that the zipped response is unzipped', function(done) {
@@ -949,7 +949,7 @@ function test_gzip() {
949949
'content-type': 'text/css'
950950
});
951951

952-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
952+
var c = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
953953
var mydb = c.db.use(dbName);
954954
mydb.attachment.get('x', 'y.css', function(er, data) {
955955
should(er).equal(null);
@@ -970,7 +970,7 @@ describe('Virtual Hosts', function() {
970970
var mocks = nock(SERVER)
971971
.get('/_api/v2/user/virtual_hosts').reply(200, {'virtual_hosts': []});
972972

973-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
973+
var c = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
974974
c.get_virtual_hosts(function(er, d) {
975975
should(er).equal(null);
976976
d.should.be.an.Object;
@@ -986,7 +986,7 @@ describe('Virtual Hosts', function() {
986986
var mocks = nock(SERVER)
987987
.post('/_api/v2/user/virtual_hosts').reply(200, {'ok': true});
988988

989-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
989+
var c = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
990990
c.add_virtual_host({ host: myHost, path: '/mypath'}, function(er, d) {
991991
should(er).equal(null);
992992
d.should.be.an.Object;
@@ -1003,7 +1003,7 @@ describe('Virtual Hosts', function() {
10031003
var mocks = nock(SERVER)
10041004
.delete('/_api/v2/user/virtual_hosts').reply(200, { 'ok': true });
10051005

1006-
var c = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'});
1006+
var c = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: 'retry' });
10071007
c.delete_virtual_host({ host: myHost, path: '/mypath'}, function(er, d) {
10081008
should(er).equal(null);
10091009
d.should.be.an.Object;

0 commit comments

Comments
 (0)