Layout test cases and files for cli commands.
This commit is contained in:
parent
17b1bf15ab
commit
00e4eac14a
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var version = require(__dirname + '/../package.json').version;
|
var version = require(__dirname + '/../package.json').version;
|
||||||
|
var create = require('../lib/scaffold/create');
|
||||||
|
var add = require('../lib/scaffold/add');
|
||||||
|
var start = require('../lib/scaffold/start');
|
||||||
|
var stop = require('../lib/scaffold/stop');
|
||||||
|
var findConfig = require('../lib/scaffold/find-config');
|
||||||
|
|
||||||
program
|
program
|
||||||
.version(version)
|
.version(version)
|
||||||
@ -12,7 +17,9 @@ program
|
|||||||
.command('create <directory> [name]')
|
.command('create <directory> [name]')
|
||||||
.description('Create a new node')
|
.description('Create a new node')
|
||||||
.action(function(directory, name){
|
.action(function(directory, name){
|
||||||
console.log(directory, name);
|
var config = findConfig();
|
||||||
|
create(config, directory, name);
|
||||||
|
console.log('Successfully created node in directory: ', directory);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -20,6 +27,9 @@ program
|
|||||||
.alias('install')
|
.alias('install')
|
||||||
.description('Install a module for the current node')
|
.description('Install a module for the current node')
|
||||||
.action(function(module){
|
.action(function(module){
|
||||||
|
var config = findConfig();
|
||||||
|
add(config, module);
|
||||||
|
console.log('Successfully added module: ', module);
|
||||||
console.log(module);
|
console.log(module);
|
||||||
}).on('--help', function() {
|
}).on('--help', function() {
|
||||||
console.log(' Examples:');
|
console.log(' Examples:');
|
||||||
@ -34,14 +44,16 @@ program
|
|||||||
.option('-b', '--background', 'Will start in the background')
|
.option('-b', '--background', 'Will start in the background')
|
||||||
.description('Start the current node')
|
.description('Start the current node')
|
||||||
.action(function(){
|
.action(function(){
|
||||||
console.log('start');
|
var config = findConfig();
|
||||||
|
start(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('stop')
|
.command('stop')
|
||||||
.description('Stop the current node')
|
.description('Stop the current node')
|
||||||
.action(function(){
|
.action(function(){
|
||||||
console.log('stop');
|
var config = findConfig();
|
||||||
|
stop(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
2
lib/scaffold/add.js
Normal file
2
lib/scaffold/add.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
71
lib/scaffold/create.js
Normal file
71
lib/scaffold/create.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
var version = require('../../package.json').version;
|
||||||
|
var mkdirp = require('mkdirp');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var BASE_CONFIG = {
|
||||||
|
name: 'My Node',
|
||||||
|
modules: [
|
||||||
|
'address'
|
||||||
|
],
|
||||||
|
datadir: './data',
|
||||||
|
network: 'livenet'
|
||||||
|
};
|
||||||
|
|
||||||
|
var BASE_PACKAGE = {
|
||||||
|
dependencies: {
|
||||||
|
'bitcore': '^' + bitcore.version,
|
||||||
|
'bitcore-node': '^' + version
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var BASE_BITCOIN_CONFIG = 'whitelist=127.0.0.1\n' + 'txindex=1\n';
|
||||||
|
|
||||||
|
function create(baseDirectory, dirname, name, done) {
|
||||||
|
|
||||||
|
if (!baseDirectory) {
|
||||||
|
baseDirectory = process.cwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
var directory = baseDirectory + '/' + dirname;
|
||||||
|
|
||||||
|
mkdirp(directory, function(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup the configuration files
|
||||||
|
var config = BASE_CONFIG;
|
||||||
|
config.name = name;
|
||||||
|
var configJSON = JSON.stringify(config, null, 2);
|
||||||
|
var packageJSON = JSON.stringify(BASE_PACKAGE, null, 2);
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(directory + '/bitcore-node.json', configJSON);
|
||||||
|
fs.writeFileSync(directory + '/package.json', packageJSON);
|
||||||
|
} catch(e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup the bitcoin data directory
|
||||||
|
mkdirp(directory + '/data', function(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(directory + '/data/bitcoin.conf', BASE_BITCOIN_CONFIG);
|
||||||
|
} catch(e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
done();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = create;
|
||||||
2
lib/scaffold/find-config.js
Normal file
2
lib/scaffold/find-config.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
1
lib/scaffold/start.js
Normal file
1
lib/scaffold/start.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
'use strict';
|
||||||
40
test/scaffold/add.integration.js
Normal file
40
test/scaffold/add.integration.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var should = require('chai').should();
|
||||||
|
var sinon = require('sinon');
|
||||||
|
|
||||||
|
describe('#add', function() {
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
// setup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
// cleanup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('will modify scaffold files', function() {
|
||||||
|
|
||||||
|
it('will give an error if expected files do not exist', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will update bitcore-node.json modules', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will update package.json modules', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will install the necessary node.js modules', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will install dependencies', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
62
test/scaffold/create.integration.js
Normal file
62
test/scaffold/create.integration.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var should = require('chai').should();
|
||||||
|
var create = require('../../lib/scaffold/create');
|
||||||
|
var fs = require('fs');
|
||||||
|
var mkdirp = require('mkdirp');
|
||||||
|
var rimraf = require('rimraf');
|
||||||
|
|
||||||
|
describe('#create', function() {
|
||||||
|
|
||||||
|
var basePath = __dirname + '/../';
|
||||||
|
var testDir = basePath + 'temporary-test-data';
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
// setup testing directories
|
||||||
|
mkdirp(testDir, function(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
// cleanup testing directories
|
||||||
|
rimraf(testDir, function(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will create scaffold files', function() {
|
||||||
|
|
||||||
|
create(testDir, 'mynode', 'My Node 1', function(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
var configPath = testDir + '/mynode/bitcore-node.json';
|
||||||
|
var packagePath = testDir + '/mynode/package.json';
|
||||||
|
var bitcoinConfig = testDir + '/mynode/data/bitcoin.conf';
|
||||||
|
|
||||||
|
should.equal(fs.existsSync(configPath), true);
|
||||||
|
should.equal(fs.existsSync(packagePath), true);
|
||||||
|
should.equal(fs.existsSync(bitcoinConfig), true);
|
||||||
|
|
||||||
|
var config = JSON.parse(fs.readFileSync(configPath));
|
||||||
|
config.name.should.equal('My Node 1');
|
||||||
|
config.modules.should.deep.equal(['address']);
|
||||||
|
config.datadir.should.equal('./data');
|
||||||
|
config.network.should.equal('livenet');
|
||||||
|
|
||||||
|
var pack = JSON.parse(fs.readFileSync(packagePath));
|
||||||
|
should.exist(pack.dependencies);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
36
test/scaffold/find-config.integration.js
Normal file
36
test/scaffold/find-config.integration.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var should = require('chai').should();
|
||||||
|
var sinon = require('sinon');
|
||||||
|
|
||||||
|
describe('#findConfig', function() {
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
// setup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
// cleanup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('will find a configuration file', function() {
|
||||||
|
|
||||||
|
it('in the current directory', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('in a parent directory', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('recursively find in parent directories', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will fallback to a default location in the home directory', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
28
test/scaffold/start.integration.js
Normal file
28
test/scaffold/start.integration.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var should = require('chai').should();
|
||||||
|
var sinon = require('sinon');
|
||||||
|
|
||||||
|
describe('#start', function() {
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
// setup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
// cleanup testing directories
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('will dynamically create a node from a configuration', function() {
|
||||||
|
|
||||||
|
it('require each bitcore-node module', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('create an instance of node with modules enabled', function() {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user