From 86700c30bb9fb51665ba564c36a495690897db1a Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 15 Sep 2012 15:45:33 -0700 Subject: [PATCH] Build testing newcoind.cfg as needed. --- .gitignore | 3 +++ test/config.js | 15 +++++++++++++++ test/server.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/config.js diff --git a/.gitignore b/.gitignore index ec0acfa4f..92eb7bb78 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ newcoind # Ignore locally installed node_modules node_modules + +# Ignore tmp directory. +tmp diff --git a/test/config.js b/test/config.js new file mode 100644 index 000000000..004767c15 --- /dev/null +++ b/test/config.js @@ -0,0 +1,15 @@ +// +// Configuration for unit tests +// + +exports.servers = { + alpha : { + "peer_ip" : "0.0.0.0", + "peer_port" : 51235, + "websocket_ip" : "127.0.0.1", + "websocket_port" : 5005, + "validation_seed" : "shhDFVsmS2GSu5vUyZSPXYfj1r79h", + "validators" : "n9L8LZZCwsdXzKUN9zoVxs4YznYXZ9hEhsQZY7aVpxtFaSceiyDZ beta" + } +}; +// vim:ts=4 diff --git a/test/server.js b/test/server.js index 3c7b54d39..11313b553 100644 --- a/test/server.js +++ b/test/server.js @@ -7,21 +7,46 @@ console.log("server.js>"); +var config = require("./config.js"); var utils = require("./utils.js"); +var fs = require("fs"); +var path = require("path"); +var util = require("util"); // var child = require("child"); var serverPath = function(name) { return "tmp/server/" + name; }; +// Return a server's newcoind.cfg as string. +var serverConfig = function(name) { + var cfg = config.servers[name]; + + return Object.keys(cfg).map(function (o) { + return util.format("[%s]\n%s\n", o, cfg[o]); + }).join(""); +}; + +// Write a server's newcoind.cfg. +var writeConfig = function(name, done) { + fs.writeFile(path.join(serverPath(name), "newcoind.cfg"), serverConfig(name), 'utf8', done); +}; + var makeBase = function(name, done) { var path = serverPath(name); console.log("start> %s: %s", name, path); - // Remove the existing dir. - utils.resetPath(path, parseInt('0777', 8), done); + // Reset the server directory, build it if needed. + utils.resetPath(path, parseInt('0777', 8), function (e) { + if (e) { + throw e; + } + else { + writeConfig(name, done); + } + }); console.log("start< %s", name); };