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

Commit da69a08

Browse files
authored
Concatenate streaming data in client tests (#423)
* Updated 'data' callback to concatenate streaming response data before asserting * Removed data chunk count assertions in retry tests. We already assert on the completed response data in 'end' callback.
1 parent 380a3b3 commit da69a08

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

test/client.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ describe('CloudantClient', function() {
954954
auth: { username: ME, password: PASSWORD },
955955
method: 'GET'
956956
};
957+
958+
var responseData = '';
957959
cloudantClient.request(options)
958960
.on('error', function(err) {
959961
assert.fail(`Unexpected error: ${err}`);
@@ -962,9 +964,10 @@ describe('CloudantClient', function() {
962964
assert.equal(resp.statusCode, 200);
963965
})
964966
.on('data', function(data) {
965-
assert.ok(data.toString('utf8').indexOf('"doc_count":1') > -1);
967+
responseData += data;
966968
})
967969
.on('end', function() {
970+
assert.ok(responseData.toString('utf8').indexOf('"doc_count":1') > -1);
968971
mocks.done();
969972
done();
970973
});
@@ -1012,6 +1015,7 @@ describe('CloudantClient', function() {
10121015
auth: { username: ME, password: PASSWORD },
10131016
method: 'GET'
10141017
};
1018+
var responseData = '';
10151019
cloudantClient.request(options)
10161020
.on('error', function(err) {
10171021
assert.fail(`Unexpected error: ${err}`);
@@ -1020,9 +1024,10 @@ describe('CloudantClient', function() {
10201024
assert.equal(resp.statusCode, 200);
10211025
})
10221026
.on('data', function(data) {
1023-
assert.ok(data.toString('utf8').indexOf('"doc_count":1') > -1);
1027+
responseData += data;
10241028
})
10251029
.on('end', function() {
1030+
assert.ok(responseData.toString('utf8').indexOf('"doc_count":1') > -1);
10261031
assert.equal(cloudantClient._plugins[0].onRequestCallCount, 1);
10271032
assert.equal(cloudantClient._plugins[0].onErrorCallCount, 0);
10281033
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 1);
@@ -1080,6 +1085,7 @@ describe('CloudantClient', function() {
10801085
auth: { username: ME, password: PASSWORD },
10811086
method: 'GET'
10821087
};
1088+
var responseData = '';
10831089
cloudantClient.request(options)
10841090
.on('error', function(err) {
10851091
assert.fail(`Unexpected error: ${err}`);
@@ -1088,9 +1094,10 @@ describe('CloudantClient', function() {
10881094
assert.equal(resp.statusCode, 200);
10891095
})
10901096
.on('data', function(data) {
1091-
assert.ok(data.toString('utf8').indexOf('"doc_count":1') > -1);
1097+
responseData += data;
10921098
})
10931099
.on('end', function() {
1100+
assert.ok(responseData.toString('utf8').indexOf('"doc_count":1') > -1);
10941101
assert.equal(cloudantClient._plugins[0].onRequestCallCount, 1);
10951102
assert.equal(cloudantClient._plugins[0].onErrorCallCount, 0);
10961103
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 1);
@@ -1158,6 +1165,7 @@ describe('CloudantClient', function() {
11581165
auth: { username: ME, password: PASSWORD },
11591166
method: 'HEAD' // ComplexPlugin1 will set method to 'PUT'
11601167
};
1168+
var responseData = '';
11611169
var startTs = (new Date()).getTime();
11621170
cloudantClient.request(options)
11631171
.on('error', function(err) {
@@ -1168,9 +1176,10 @@ describe('CloudantClient', function() {
11681176
assert.equal(resp.request.headers.ComplexPlugin1, 'foo');
11691177
})
11701178
.on('data', function(data) {
1171-
assert.ok(data.toString('utf8').indexOf('"error":"file_exists"') > -1);
1179+
responseData += data;
11721180
})
11731181
.on('end', function() {
1182+
assert.ok(responseData.toString('utf8').indexOf('"error":"file_exists"') > -1);
11741183
assert.equal(cloudantClient._plugins[0].onRequestCallCount, 10);
11751184
assert.equal(cloudantClient._plugins[0].onErrorCallCount, 0);
11761185
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 10);
@@ -1240,6 +1249,7 @@ describe('CloudantClient', function() {
12401249
auth: { username: ME, password: PASSWORD },
12411250
method: 'POST' // ComplexPlugin2 will set method to 'GET'
12421251
};
1252+
var responseData = '';
12431253
cloudantClient.request(options)
12441254
.on('error', function(err) {
12451255
assert.fail(`Unexpected error: ${err}`);
@@ -1249,9 +1259,10 @@ describe('CloudantClient', function() {
12491259
assert.equal(resp.request.headers.ComplexPlugin2, 'bar');
12501260
})
12511261
.on('data', function(data) {
1252-
assert.ok(data.toString('utf8').indexOf('"error":"unauthorized"') > -1);
1262+
responseData += data;
12531263
})
12541264
.on('end', function() {
1265+
assert.ok(responseData.toString('utf8').indexOf('"error":"unauthorized"') > -1);
12551266
assert.equal(cloudantClient._plugins[0].onRequestCallCount, 2);
12561267
assert.equal(cloudantClient._plugins[0].onErrorCallCount, 0);
12571268
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 2);
@@ -1281,6 +1292,7 @@ describe('CloudantClient', function() {
12811292
auth: { username: ME, password: PASSWORD },
12821293
method: 'DELETE' // ComplexPlugin2 will set method to 'GET'
12831294
};
1295+
var responseData = '';
12841296
cloudantClient.request(options)
12851297
.on('error', function(err) {
12861298
assert.fail(`Unexpected error: ${err}`);
@@ -1289,9 +1301,10 @@ describe('CloudantClient', function() {
12891301
assert.equal(resp.statusCode, 200);
12901302
})
12911303
.on('data', function(data) {
1292-
assert.ok(data.toString('utf8').indexOf('"ok":true') > -1);
1304+
responseData += data;
12931305
})
12941306
.on('end', function() {
1307+
assert.ok(responseData.toString('utf8').indexOf('"ok":true') > -1);
12951308
assert.equal(cloudantClient._plugins[0].onRequestCallCount, 1);
12961309
assert.equal(cloudantClient._plugins[0].onErrorCallCount, 1);
12971310
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 0);
@@ -1326,6 +1339,7 @@ describe('CloudantClient', function() {
13261339
auth: { username: ME, password: PASSWORD },
13271340
method: 'GET'
13281341
};
1342+
var responseData = '';
13291343
cloudantClient.request(options)
13301344
.on('error', function(err) {
13311345
assert.fail(`Unexpected error: ${err}`);
@@ -1334,9 +1348,10 @@ describe('CloudantClient', function() {
13341348
assert.equal(resp.statusCode, 200);
13351349
})
13361350
.on('data', function(data) {
1337-
assert.ok(data.toString('utf8').indexOf('"ok":true') > -1);
1351+
responseData += data;
13381352
})
13391353
.on('end', function() {
1354+
assert.ok(responseData.toString('utf8').indexOf('"ok":true') > -1);
13401355
assert.equal(cloudantClient._plugins[0].onResponseCallCount, 2);
13411356
mocks.done();
13421357
done();
@@ -1396,6 +1411,7 @@ describe('CloudantClient', function() {
13961411
auth: { username: ME, password: PASSWORD },
13971412
method: 'GET'
13981413
};
1414+
var responseData = '';
13991415
cloudantClient.request(options)
14001416
.on('error', function(err) {
14011417
assert.fail(`Unexpected error: ${err}`);
@@ -1404,9 +1420,10 @@ describe('CloudantClient', function() {
14041420
assert.equal(resp.statusCode, 200);
14051421
})
14061422
.on('data', function(data) {
1407-
assert.ok(data.toString('utf8').indexOf('"doc_count":1') > -1);
1423+
responseData += data;
14081424
})
14091425
.on('end', function() {
1426+
assert.ok(responseData.toString('utf8').indexOf('"doc_count":1') > -1);
14101427
mocks.done();
14111428
done();
14121429
});

0 commit comments

Comments
 (0)