UT: Added verbosity and no_server options to setUp routine.

This commit is contained in:
Stefan Thomas
2012-10-23 22:39:30 +02:00
parent b7a40435b8
commit cb2fb10b65
4 changed files with 69 additions and 25 deletions

View File

@@ -6,33 +6,78 @@ var Server = require("./server.js").Server;
var config = require("./config.js");
var test_setup = function (done, host, verbose) {
var self = this;
var host = host || config.server_default;
/**
* Helper called by test cases to generate a setUp routine.
*
* By default you would call this without options, but it is useful to
* be able to plug options in during development for quick and easy
* debugging.
*
* @example
* buster.testCase("Foobar", {
* setUp: testutils.build_setup({verbose: true}),
* // ...
* });
*
* @param host {String} Identifier for the host configuration to be used.
* @param opts {Object} These options allow quick-and-dirty test-specific
* customizations of your test environment.
* @param opts.verbose {Bool} Enable all debug output (then cover your ears
* and run)
* @param opts.verbose_ws {Bool} Enable tracing in the Remote class. Prints
* websocket traffic.
* @param opts.verbose_server {Bool} Set the -v option when running rippled.
* @param opts.no_server {Bool} Don't auto-run rippled.
*/
var build_setup = function (opts) {
opts = this.opts = opts || {};
this.store = this.store || {};
// Normalize options
if (opts.verbose) {
opts.verbose_ws = true;
opts.verbose_server = true;
};
var data = this.store[host] = this.store[host] || {};
return function (done) {
var self = this;
data.server = Server.from_config(host, verbose).on('started', function () {
self.remote = data.remote = Remote.from_config(host).once('ledger_closed', done).connect();
}).start();
var host = host || config.server_default;
this.store = this.store || {};
var data = this.store[host] = this.store[host] || {};
async.series([
function runServerStep(callback) {
if (opts.no_server) return callback();
data.server = Server.from_config(host, !!opts.verbose_server).on('started', callback).start();
},
function connectWebsocketStep(callback) {
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws).once('ledger_closed', callback).connect();
}
], done);
};
};
var test_setup_verbose = function (done, host) {
test_setup.call(this, done, host, 'VERBOSE');
}
var test_teardown = function (done, host) {
host = host || config.server_default;
var test_teardown = function (done, host) {
var host = host || config.server_default;
var data = this.store[host];
var opts = this.opts;
var data = this.store[host];
async.series([
function disconnectWebsocketStep(callback) {
data.remote
.on('disconnected', callback)
.connect(false);
},
function stopServerStep(callback) {
if (opts.no_server) return callback();
data.remote
.on('disconnected', function () {
data.server.on('stopped', done).stop();
})
.connect(false);
data.server.on('stopped', callback).stop();
}
], done);
};
var create_accounts = function (remote, src, amount, accounts, callback) {
@@ -76,8 +121,7 @@ var credit_limit = function (remote, src, amount, callback) {
exports.create_accounts = create_accounts;
exports.credit_limit = credit_limit;
exports.test_setup = test_setup;
exports.test_setup_verbose = test_setup_verbose;
exports.build_setup = build_setup;
exports.test_teardown = test_teardown;
// vim:sw=2:sts=2:ts=8