From 4498b18dc13f5a1113f085e170fa7e6ee4324d36 Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Thu, 3 Nov 2016 14:14:51 -0400 Subject: [PATCH] FAB-950 self-contained chaincode deploy test setup Tests that need to deploy chaincode need the following setup: - GOPATH environment variable - chaincode available at the folder corresponding to $GOPATH/src/ 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 --- .gitignore | 1 + package.json | 1 - .../github.com/example_cc}/example_cc.go | 0 test/unit/endorser-tests.js | 5 +++- test/unit/util.js | 24 ++----------------- 5 files changed, 7 insertions(+), 24 deletions(-) rename test/fixtures/{ => src/github.com/example_cc}/example_cc.go (100%) diff --git a/.gitignore b/.gitignore index f7824d2d66..2a846db758 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ coverage docs/gen node_modules/* +test/fixtures/src/github.com/example_cc/Dockerfile npm-shrinkwrap.json npm-debug.log tmp diff --git a/package.json b/package.json index 74da717c0c..e14b4c7e4b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fixtures/example_cc.go b/test/fixtures/src/github.com/example_cc/example_cc.go similarity index 100% rename from test/fixtures/example_cc.go rename to test/fixtures/src/github.com/example_cc/example_cc.go diff --git a/test/unit/endorser-tests.js b/test/unit/endorser-tests.js index 2069f72d58..f5ebfced6f 100644 --- a/test/unit/endorser-tests.js +++ b/test/unit/endorser-tests.js @@ -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 // @@ -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'] }; diff --git a/test/unit/util.js b/test/unit/util.js index 61ee4d6d0f..d6abe79c9f 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -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'); }; \ No newline at end of file