Skip to content

Commit

Permalink
Refactor headless-tests.js into individual files
Browse files Browse the repository at this point in the history
FAB-2164
this file is getting very big with thousands of lines of code.
it becomes increasingly difficult to code and debug with it.

this changeset breaks it apart into separate "test suites"
and group them together in a single folder dedicated to
headless tests (those that don't require a target network to run)

the test runner 'tape' does not support test suite hierarchy
(istanbul will not be able to find coverage information if a test
module is required from another module). so the solution is to use
a "gulp" task to launch it

Change-Id: I70a5afca13de10099989905d0f6df6db40cc8063
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Feb 14, 2017
1 parent 4ae123e commit 691af63
Show file tree
Hide file tree
Showing 33 changed files with 3,554 additions and 3,133 deletions.
25 changes: 14 additions & 11 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@ gulp.task('pre-test', function() {
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function() {
gulp.task('test', ['lint', 'test-headless'], function() {
// use individual tests to control the sequence they get executed
// first run the ca-tests that tests all the member registration and
// enrollment scenarios (good and bad calls). then the rest of the
// tests will re-used the same key value store that has saved the
// user certificates so they can interact with the network
return gulp.src([
// 'test/unit/ca-tests.js',
'test/unit/chain-fabriccop-tests.js',
'test/unit/endorser-tests.js',
'test/unit/orderer-tests.js',
'test/unit/orderer-chain-tests.js',
'test/unit/end-to-end.js',
'test/unit/headless-tests.js'
// 'test/integration/ca-tests.js',
'test/integration/chain-fabriccop-tests.js',
'test/integration/endorser-tests.js',
'test/integration/orderer-tests.js',
'test/integration/orderer-chain-tests.js'
])
.pipe(tape({
reporter: tapColorize()
}))
.pipe(istanbul.writeReports());
});

gulp.task('test-headless', ['pre-test'], function() {
gulp.task('test-headless', ['lint', 'pre-test'], function() {
// this is needed to avoid a problem in tape-promise with adding too many listeners
// to the "unhandledRejection" event
process.setMaxListeners(0);

return gulp.src([
'test/unit/headless-tests.js',
'test/unit/msp-tests.js'
'test/unit/**/*.js',
'!test/unit/util.js',
'!test/unit/pkcs11.js'
])
.pipe(tape({
reporter: tapColorize()
Expand Down
15 changes: 0 additions & 15 deletions fabric-client/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,6 @@ module.exports.toArrayBuffer = function(buffer) {
return ab;
};

// utility function to check if directory or file exists
// uses entire / absolute path from root
module.exports.existsSync = function(absolutePath /*string*/) {
try {
var stat = fs.statSync(absolutePath);
if (stat.isDirectory() || stat.isFile()) {
return true;
} else
return false;
}
catch (e) {
return false;
}
};

// utility function to build an unique transaction id
// The request object may contain values that could be
// used to help generate the result value
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var test = _test(tape);
var hfc = require('fabric-client');
var util = require('util');
var fs = require('fs');
var testUtil = require('./util.js');
var testUtil = require('../unit/util.js');

var Orderer = require('fabric-client/lib/Orderer.js');
var Chain = require('fabric-client/lib/Chain.js');
Expand All @@ -30,97 +30,6 @@ var keyValStorePath = testUtil.KVS;

var client = new hfc();

//
// Orderer via chain setOrderer/getOrderer
//
// Set the orderer URL through the chain setOrderer method. Verify that the
// orderer URL was set correctly through the getOrderer method. Repeat the
// process by updating the orderer URL to a different address.
//
test('\n\n** TEST ** orderer via chain setOrderer/getOrderer', function(t) {
//
// Create and configure the test chain
//
hfc.newDefaultKeyValueStore({
path: testUtil.KVS
})
.then ( function (store) {
client.setStateStore(store);

var chain = client.newChain('testChain-orderer-member');
try {
var orderer = new Orderer('grpc://localhost:7050');
chain.addOrderer(orderer);
t.pass('Successfully set the new orderer URL');

var orderers = chain.getOrderers();
if(orderers !== null && orderers.length > 0 && orderers[0].getUrl() === 'grpc://localhost:7050') {
t.pass('Successfully retrieved the new orderer URL from the chain');
}
else {
t.fail('Failed to retieve the new orderer URL from the chain');
t.end();
}

try {
var orderer2 = new Orderer('grpc://localhost:5152');
chain.addOrderer(orderer2);
t.pass('Successfully updated the orderer URL');

var orderers = chain.getOrderers();
if(orderers !== null && orderers.length > 0 && orderers[1].getUrl() === 'grpc://localhost:5152') {
t.pass('Successfully retrieved the upated orderer URL from the chain');
t.end();
}
else {
t.fail('Failed to retieve the updated orderer URL from the chain');
t.end();
}
}
catch(err2) {
t.fail('Failed to update the order URL ' + err2);
t.end();
}
}
catch(err) {
t.fail('Failed to set the new order URL ' + err);
t.end();
}
});
});

//
// Orderer via chain set/get bad address
//
// Set the orderer URL to a bad address through the chain setOrderer method.
// Verify that an error is reported when trying to set a bad address.
//
test('\n\n** TEST ** orderer via chain set/get bad address', function(t) {
//
// Create and configure the test chain
//
var chain = client.newChain('testChain-orderer-member1');

t.throws(
function() {
var order_address = 'xxx';
chain.addOrderer(new Orderer(order_address));
},
/InvalidProtocol: Invalid protocol: undefined/,
'Test setting a bad orderer address'
);

t.throws(
function() {
chain.addOrderer(new Orderer());
},
/TypeError: Parameter "url" must be a string, not undefined/,
'Test setting an empty orderer address'
);

t.end();
});

//
// Orderer via member missing orderer
//
Expand Down
File renamed without changes.
Loading

0 comments on commit 691af63

Please sign in to comment.