mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 02:25:53 +00:00
JS Tests: Refactored config handling.
Still far from perfect, but better than it was.
This commit is contained in:
@@ -7,11 +7,13 @@ var testconfig = require("./testconfig.js");
|
||||
|
||||
exports.accounts = testconfig.accounts;
|
||||
|
||||
// Where to find the binary.
|
||||
exports.rippled = path.resolve("build/rippled");
|
||||
|
||||
exports.server_default = "alpha";
|
||||
|
||||
exports.default_server_config = {
|
||||
// Where to find the binary.
|
||||
rippled_path: path.resolve(__dirname, "../build/rippled")
|
||||
};
|
||||
|
||||
//
|
||||
// Configuration for servers.
|
||||
//
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
var buster = require("buster");
|
||||
var buster = require("buster");
|
||||
var extend = require("extend");
|
||||
var Server = require("./server").Server;
|
||||
|
||||
var testutils = require("./testutils");
|
||||
var Server = require("./server").Server;
|
||||
var config = testutils.init_config();
|
||||
|
||||
// How long to wait for server to start.
|
||||
// var serverDelay = 1500;
|
||||
@@ -9,19 +12,22 @@ var alpha;
|
||||
|
||||
buster.testCase("Standalone server startup", {
|
||||
"server start and stop" : function (done) {
|
||||
alpha = Server.from_config("alpha", false); //ADD ,true for verbosity
|
||||
var cfg = extend({}, config.default_server_config,
|
||||
config.servers.alpha);
|
||||
|
||||
alpha
|
||||
.on('started', function () {
|
||||
alpha
|
||||
.on('stopped', function () {
|
||||
buster.assert(true);
|
||||
alpha = Server.from_config("alpha", cfg);
|
||||
|
||||
done();
|
||||
})
|
||||
.stop();
|
||||
alpha
|
||||
.on('started', function () {
|
||||
alpha
|
||||
.on('stopped', function () {
|
||||
buster.assert(true);
|
||||
|
||||
done();
|
||||
})
|
||||
.start();
|
||||
.stop();
|
||||
})
|
||||
.start();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ var path = require("path");
|
||||
var util = require("util");
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var config = require("./config");
|
||||
var nodeutils = require("./nodeutils");
|
||||
|
||||
// Create a server object
|
||||
@@ -58,8 +57,8 @@ var Server = function (name, config, verbose) {
|
||||
|
||||
util.inherits(Server, EventEmitter);
|
||||
|
||||
Server.from_config = function (name, verbose) {
|
||||
return new Server(name, config.servers[name], verbose);
|
||||
Server.from_config = function (name, config, verbose) {
|
||||
return new Server(name, config, verbose);
|
||||
};
|
||||
|
||||
Server.prototype.on = function (e, c) {
|
||||
@@ -106,7 +105,7 @@ Server.prototype._serverSpawnSync = function() {
|
||||
|
||||
// Spawn in standalone mode for now.
|
||||
this.child = child.spawn(
|
||||
config.rippled,
|
||||
this.config.rippled_path,
|
||||
args,
|
||||
{
|
||||
cwd: this.serverPath(),
|
||||
@@ -116,7 +115,10 @@ Server.prototype._serverSpawnSync = function() {
|
||||
|
||||
if (!this.quiet)
|
||||
console.log("server: start %s: %s --conf=%s",
|
||||
this.child.pid, config.rippled, args.join(" "), this.configPath());
|
||||
this.child.pid,
|
||||
this.config.rippled_path,
|
||||
args.join(" "),
|
||||
this.configPath());
|
||||
|
||||
// By default, just log exits.
|
||||
this.child.on('exit', function(code, signal) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
var async = require("async");
|
||||
var extend = require("extend");
|
||||
|
||||
var Amount = require("ripple-lib").Amount;
|
||||
var Remote = require("ripple-lib").Remote;
|
||||
var Server = require("./server").Server;
|
||||
var Transaction = require("ripple-lib").Transaction;
|
||||
|
||||
var config = require('ripple-lib').config.load(require('./config'));
|
||||
|
||||
var account_dump = function (remote, account, callback) {
|
||||
var self = this;
|
||||
|
||||
@@ -65,6 +64,8 @@ var account_dump = function (remote, account, callback) {
|
||||
* @param host {String} Identifier for the host configuration to be used.
|
||||
*/
|
||||
var build_setup = function (opts, host) {
|
||||
var config = get_config();
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
// Normalize options
|
||||
@@ -100,8 +101,12 @@ var build_setup = function (opts, host) {
|
||||
function runServerStep(callback) {
|
||||
if (opts.no_server) return callback();
|
||||
|
||||
var server_config = extend({}, config.default_server_config,
|
||||
config.servers[host]);
|
||||
|
||||
data.server = Server
|
||||
.from_config(host, !!opts.verbose_server)
|
||||
.from_config(host, server_config,
|
||||
!!opts.verbose_server)
|
||||
.on('started', callback)
|
||||
.on('exited', function () {
|
||||
// If know the remote, tell it server is gone.
|
||||
@@ -127,6 +132,7 @@ var build_setup = function (opts, host) {
|
||||
* @param host {String} Identifier for the host configuration to be used.
|
||||
*/
|
||||
var build_teardown = function (host) {
|
||||
var config = get_config();
|
||||
|
||||
return function (done) {
|
||||
host = host || config.server_default;
|
||||
@@ -218,16 +224,20 @@ var credit_limit = function (remote, src, amount, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
function init_config() {
|
||||
var cfg;
|
||||
function get_config() {
|
||||
var cfg = require('./config-example');
|
||||
|
||||
// See if the person testing wants to override the configuration by creating a
|
||||
// file called test/config.js.
|
||||
try {
|
||||
cfg = require('./config');
|
||||
} catch (e) {
|
||||
cfg = require('./config-example');
|
||||
}
|
||||
cfg = extend({}, cfg, require('./config'));
|
||||
} catch (e) { }
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
function init_config() {
|
||||
var cfg = get_config();
|
||||
|
||||
return require('ripple-lib').config.load(cfg);
|
||||
}
|
||||
@@ -500,6 +510,7 @@ exports.build_teardown = build_teardown;
|
||||
exports.create_accounts = create_accounts;
|
||||
exports.credit_limit = credit_limit;
|
||||
exports.credit_limits = credit_limits;
|
||||
exports.get_config = get_config;
|
||||
exports.init_config = init_config;
|
||||
exports.ledger_close = ledger_close;
|
||||
exports.payment = payment;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var buster = require("buster");
|
||||
var extend = require("extend");
|
||||
|
||||
var Server = require("./server").Server;
|
||||
var Remote = require("ripple-lib").Remote;
|
||||
@@ -8,12 +9,27 @@ var config = testutils.init_config();
|
||||
|
||||
buster.testRunner.timeout = 5000;
|
||||
|
||||
var server;
|
||||
buster.testCase("WebSocket connection", {
|
||||
'setUp' :
|
||||
function (done) { if (config.servers.alpha.no_server) done(); else server = Server.from_config("alpha").on('started', done).start(); },
|
||||
function (done) {
|
||||
var cfg = extend({}, config.default_server_config,
|
||||
config.servers.alpha);
|
||||
if (cfg.no_server) {
|
||||
done();
|
||||
} else {
|
||||
server = Server.from_config("alpha", cfg).on('started', done).start();
|
||||
}
|
||||
},
|
||||
|
||||
'tearDown' :
|
||||
function (done) { if (config.servers.alpha.no_server) done(); else server.on('stopped', done).stop(); },
|
||||
function (done) {
|
||||
if (config.servers.alpha.no_server) {
|
||||
done();
|
||||
} else {
|
||||
server.on('stopped', done).stop();
|
||||
}
|
||||
},
|
||||
|
||||
"websocket connect and disconnect" :
|
||||
function (done) {
|
||||
|
||||
Reference in New Issue
Block a user