Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('\n\n** Java chaincode Packager tests **\n\n', async (t) => {
try {
const dev_mode_package = await Packager.package(testutil.JAVA_CHAINCODE_PATH, 'java', true);
t.equal(dev_mode_package, null, 'Should return null when packaging for dev mode');
try {
await Packager.package('blah', 'java', false);
t.fail('Packager.package() should have rejected a call that does not have valid chaincodePath parameter');
} catch (error) {
const msg = 'ENOENT: no such file or directory';
if (error.message.indexOf(msg) >= 0) {
t.pass('Should throw error: ' + msg);
} else {
t.fail(error.message + 'should be' + msg);
t.end();
}
}
destDir = path.join(testutil.getTempDir(), 'test-java-chaincode');
tmpFile = path.join(testutil.getTempDir(), 'test-java-chaincode.tar.gz');
targzDir = path.join(testutil.getTempDir(), 'test-java-chaincode-tar-gz');
fs.removeSync(destDir);
test('\n\n** Golang Packager tests **\n\n', (t) => {
Packager.package('blah', '', true)
.then((data) => {
t.equal(data, null, 'Channel.packageChaincode() should return null for dev mode');
return Packager.package(null, '', false);
}).then(() => {
t.fail('Packager.package() should have rejected a call that does not have chaincodePath parameter');
t.end();
},
(err) => {
const msg = 'Missing chaincodePath parameter';
if (err.message.indexOf(msg) >= 0) {
t.pass('Should throw error: ' + msg);
} else {
t.fail(err.message + ' should be ' + msg);
t.end();
}
}).then(() => {
const destDir = path.join(testutil.getTempDir(), 'test-deploy-copy-tar-gz');
const checkPath = path.join(destDir, 'src', 'github.com', 'example_cc', 'example_cc.go');
console.log('***** tmpFile :: ' + tmpFile);
console.log('***** checkPath :: ' + checkPath);
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "chaincode/github.com/example_cc/example_cc.go" file');
return Packager.package(testutil.CHAINCODE_PATH, '', false, testutil.METADATA_PATH);
}).then((data) => {
const tmpFile = path.join(testutil.getTempDir(), 'test-deploy-copy.tar.gz');
}, (err) => {
const 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.outputFileSync(path.join(destDir, 'node_modules/dummy/package.json'), 'dummy package.json content');
fs.outputFileSync(path.join(destDir, 'dummy.js'), 'this is the content of dummy.js');
return Packager.package(destDir, 'node', false);
}).then((data) => {
return check(data, () => {
}).then((data) => {
t.equal(data, null, 'Should return null when packaging for dev mode');
return Packager.package('blah', '', false);
}).then(() => {
t.fail('Packager.package() should have rejected a call that does not have valid chaincodePath parameter');
(err) => {
const 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) => {
const tmpFile = path.join(testutil.getTempDir(), 'test-deploy-copy.tar.gz');
.then((data) => {
t.equal(data, null, 'Channel.packageChaincode() should return null for dev mode');
return Packager.package(null, '', false);
}).then(() => {
t.fail('Packager.package() should have rejected a call that does not have chaincodePath parameter');
if (error.message.indexOf(msg) >= 0) {
t.pass('Should throw error: ' + msg);
} else {
t.fail(error.message + 'should be' + msg);
t.end();
}
}
destDir = path.join(testutil.getTempDir(), 'test-java-chaincode');
tmpFile = path.join(testutil.getTempDir(), 'test-java-chaincode.tar.gz');
targzDir = path.join(testutil.getTempDir(), 'test-java-chaincode-tar-gz');
fs.removeSync(destDir);
fs.copySync(testutil.JAVA_CHAINCODE_PATH, destDir);
const real_package = await Packager.package(destDir, 'java', false);
await processPackage(real_package, tmpFile, targzDir);
let checkPath = path.join(targzDir, 'src', 'src', 'main', 'java', 'org', 'hyperledger', 'fabric', 'example', 'SimpleChaincode.java');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "SimpleChaincode.java" file');
const meta_package = await Packager.package(destDir, 'java', false, testutil.METADATA_PATH);
await processPackage(meta_package, tmpFile, targzDir);
checkPath = path.join(targzDir, 'META-INF', 'statedb', 'couchdb', 'indexes', 'index.json');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "META-INF/statedb/couchdb/indexes/index.json" file');
} catch (overall_error) {
t.fail('Caught error in Java Package.package tests');
t.comment(overall_error.stack ? overall_error.stack : overall_error);
}
t.end();
});
.then((data) => {
t.equal(data, null, 'Should return null when packaging for dev mode');
return Packager.package('blah', 'node', false);
}).then(() => {
t.fail('Packager.package() should have rejected a call that does not have valid chaincodePath parameter');
}
}
destDir = path.join(testutil.getTempDir(), 'test-java-chaincode');
tmpFile = path.join(testutil.getTempDir(), 'test-java-chaincode.tar.gz');
targzDir = path.join(testutil.getTempDir(), 'test-java-chaincode-tar-gz');
fs.removeSync(destDir);
fs.copySync(testutil.JAVA_CHAINCODE_PATH, destDir);
const real_package = await Packager.package(destDir, 'java', false);
await processPackage(real_package, tmpFile, targzDir);
let checkPath = path.join(targzDir, 'src', 'src', 'main', 'java', 'org', 'hyperledger', 'fabric', 'example', 'SimpleChaincode.java');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "SimpleChaincode.java" file');
const meta_package = await Packager.package(destDir, 'java', false, testutil.METADATA_PATH);
await processPackage(meta_package, tmpFile, targzDir);
checkPath = path.join(targzDir, 'META-INF', 'statedb', 'couchdb', 'indexes', 'index.json');
t.equal(fs.existsSync(checkPath), true, 'The tar.gz file produced by Packager.package() has the "META-INF/statedb/couchdb/indexes/index.json" file');
} catch (overall_error) {
t.fail('Caught error in Java Package.package tests');
t.comment(overall_error.stack ? overall_error.stack : overall_error);
}
t.end();
});