Skip to content

Commit

Permalink
FAB-950 self-contained chaincode deploy test setup
Browse files Browse the repository at this point in the history
Tests that need to deploy chaincode need the following setup:
- GOPATH environment variable
- chaincode available at the folder corresponding to
$GOPATH/src/<the GO package>

have this be part of the test fixture so contributors don't have to
manually set it up locally. set process.env.GOPATH in the code to
the test fixture folder just for the test execution.

Change-Id: I348a5b32fe52a67498c3578e9c4918cf4294bc39
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Nov 3, 2016
1 parent 5202a3c commit 4498b18
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
coverage
docs/gen
node_modules/*
test/fixtures/src/github.com/example_cc/Dockerfile
npm-shrinkwrap.json
npm-debug.log
tmp
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
},
"devDependencies": {
"bunyan": "^1.8.1",
"fs-extra": "^0.30.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.1.1",
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion test/unit/endorser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ var test = _test(tape);
var hfc = require('../..');
var util = require('util');
var fs = require('fs');
var testUtil = require('./util.js');

var keyValStorePath = '/tmp/keyValStore';

testUtil.setupChaincodeDeploy();

//
// Run the endorser test
//
Expand All @@ -51,7 +54,7 @@ test('endorser test', function(t) {
// send proposal to endorser
var request = {
endorserUrl: 'grpc://localhost:7051',
chaincodePath: 'github.com/chaincode_example02',
chaincodePath: testUtil.CHAINCODE_PATH,
fcn: 'init',
args: ['a', '100', 'b', '200']
};
Expand Down
24 changes: 2 additions & 22 deletions test/unit/util.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
var fs = require('fs-extra');
var path = require('path');

module.exports.CHAINCODE_PATH = 'github.com/example_cc';
module.exports.CHAINCODE_FILE = 'example_cc.go';

// temporarily set $GOPATH to the test fixture folder
module.exports.setupChaincodeDeploy = function() {
var gopath = process.env.GOPATH;

if (!gopath) {
throw new Error('Environment variable $GOPATH must be set for the SDK to deploy chaincode');
}
var src = path.join(__dirname, '../fixtures/example_cc.go');

var fullpath = path.join(gopath, 'src', module.exports.CHAINCODE_PATH);
var target = path.join(fullpath, module.exports.CHAINCODE_FILE);

fs.mkdirs(fullpath, function(err1) {
if (err1) throw new Error(err1);

fs.copy(src, target, function(err2) {
if (err2) throw new Error(err2);

return;
});

});
process.env.GOPATH = path.join(__dirname, '../fixtures');
};

0 comments on commit 4498b18

Please sign in to comment.