Skip to content

Commit

Permalink
[FAB-6458] Throw Error if chaincode path does not exist
Browse files Browse the repository at this point in the history
Throw error when the chaincode path does not exist during
install chaincode

Change-Id: I18e69e696cc2741d44bcf85c9783a8873943ed8c
Signed-off-by: Zhao Chaoyi <[email protected]>
  • Loading branch information
Zhao Chaoyi committed Oct 26, 2017
1 parent bea0540 commit 40dc5b0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
7 changes: 6 additions & 1 deletion fabric-client/lib/packager/Golang.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ class GolangPackager extends BasePackager {
descriptors.push(desc);
}

}).on('end', () => {
})
.on('error', (error, item) => {
logger.error(`error while packaging ${item.path}`);
reject(error);
})
.on('end', () => {
resolve(descriptors);
});
});
Expand Down
41 changes: 34 additions & 7 deletions test/unit/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ test('\n\n** Golang Packager tests **\n\n', function(t) {
return Packager.package(testutil.CHAINCODE_PATH,'',true);
}).then((data) => {
t.equal(data, null, 'Should return null when packaging for dev mode');
return Packager.package('blah','',false);
}).then((data) => {
t.fail('Packager.package() should have rejected a call that does not have valid chaincodePath parameter');
t.end();
},
(err)=>{
let msg = 'ENOENT: no such file or directory';
if (err.message.indexOf(msg) >= 0) {
t.pass('Should throw error: ' + msg);
} else {
t.fail(err.message + 'should be' + msg);
t.end();
}

return Packager.package(testutil.CHAINCODE_PATH,'',false);
}).then((data) => {
let tmpFile = path.join(testutil.getTempDir(), 'test-deploy-copy.tar.gz');
Expand Down Expand Up @@ -89,15 +103,28 @@ test('\n\n** Node.js Packager tests **\n\n', function(t) {
Packager.package(testutil.NODE_CHAINCODE_PATH, 'node', true)
.then((data) => {
t.equal(data, null, 'Should return null when packaging for dev mode');
return Packager.package('blah', 'node', false);
}).then((data)=>{
t.fail('Packager.package() should have rejected a call that does not have valid chaincodePath parameter');
t.end();
},(err)=>{
let msg = 'ENOENT: no such file or directory';
if (err.message.indexOf(msg) >= 0) {
t.pass('Should throw error: ' + msg);
} else {
t.fail(err.message + 'should be' + msg);
t.end();
}

fs.removeSync(destDir);
fs.copySync(testutil.NODE_CHAINCODE_PATH, destDir);
fs.removeSync(destDir);
fs.copySync(testutil.NODE_CHAINCODE_PATH, destDir);

fs.outputFileSync(path.join(destDir, '.npmignore'), npmignore1);
fs.outputFileSync(path.join(destDir, 'node_modules/dummy/package.json'), 'dummy package.json content');
fs.outputFileSync(path.join(destDir, '.npmignore'), npmignore1);
fs.outputFileSync(path.join(destDir, 'node_modules/dummy/package.json'), 'dummy package.json content');

return Packager.package(destDir, 'node', false);
}).then((data) => {
return Packager.package(destDir, 'node', false);

}).then((data) => {
return check(data, () => {
let checkPath = path.join(targzDir, 'src', 'chaincode.js');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "src/chaincode.js" file');
Expand Down Expand Up @@ -129,4 +156,4 @@ test('\n\n** Node.js Packager tests **\n\n', function(t) {
t.comment(err.stack ? err.stack : err);
t.end();
});
});
});

0 comments on commit 40dc5b0

Please sign in to comment.