mirror of
https://github.com/Netflix/dial-reference.git
synced 2026-06-08 10:59:59 +00:00
ability to write logs of test run to a file for nodejs tests
This commit is contained in:
3
README
3
README
@@ -119,3 +119,6 @@ Options:
|
|||||||
running [string] [required]
|
running [string] [required]
|
||||||
--application, --app Application to test [string] [required]
|
--application, --app Application to test [string] [required]
|
||||||
--help, -h Show help [boolean]
|
--help, -h Show help [boolean]
|
||||||
|
|
||||||
|
Log file of test run is written in log.txt in the server/tests/js_tests/tests
|
||||||
|
folder.
|
||||||
|
|||||||
@@ -2,19 +2,63 @@
|
|||||||
|
|
||||||
const colors = require("colors/safe");
|
const colors = require("colors/safe");
|
||||||
const sprintf = require("sprintf-js").sprintf;
|
const sprintf = require("sprintf-js").sprintf;
|
||||||
|
const winston = require("winston");
|
||||||
|
const moment = require("moment");
|
||||||
|
|
||||||
function printTestInfo(test, msg) {
|
const levels = { error: 0, warn: 1, info: 2, verbose: 3, debug: 4 };
|
||||||
return console.log(sprintf("%-20s : %-s\n%-20s : %-s", "Test", test, "Description", msg));
|
const transports = [
|
||||||
|
new (winston.transports.Console)({
|
||||||
|
level: "info",
|
||||||
|
formatter: consoleFormatter
|
||||||
|
}),
|
||||||
|
new (winston.transports.File)({
|
||||||
|
level: "debug",
|
||||||
|
name: "log_file",
|
||||||
|
filename: "log.txt",
|
||||||
|
json: false,
|
||||||
|
formatter: fileFormatter,
|
||||||
|
options: { flags: "w" }
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
winston.configure({ levels: levels, transports: transports });
|
||||||
|
|
||||||
|
function consoleFormatter(options) {
|
||||||
|
let str = options.message;
|
||||||
|
|
||||||
|
switch (options.level) {
|
||||||
|
case "error": return colors.red(str);
|
||||||
|
case "warn": return colors.yellow(str);
|
||||||
|
case "debug": return colors.blue(str);
|
||||||
|
case "info":
|
||||||
|
default: return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileFormatter(options) {
|
||||||
|
let str = options.message;
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
function printTestInfo(testFile, description) {
|
||||||
|
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "TEST", testFile));
|
||||||
|
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DESCRIPTION", description));
|
||||||
}
|
}
|
||||||
|
|
||||||
function printTestSuccess() {
|
function printTestSuccess() {
|
||||||
return console.log(colors.green("TEST PASSED\n"));
|
winston.info(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "RESULT", "TEST PASSED\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function printTestFailure(err) {
|
function printTestFailure(err) {
|
||||||
return console.log(colors.red(sprintf("%-20s : %-s\n", "TEST FAILED", err)));
|
winston.error(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "RESULT", "TEST FAILED " + err + "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function printDebug(msg) {
|
||||||
|
winston.debug(sprintf("[%-s] %-20s : %-s", moment().format("YYYY-MM-DDTHH:mm:ssZ"), "DEBUG", msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.printTestInfo = printTestInfo;
|
module.exports.printTestInfo = printTestInfo;
|
||||||
module.exports.printTestSuccess = printTestSuccess;
|
module.exports.printTestSuccess = printTestSuccess;
|
||||||
module.exports.printTestFailure = printTestFailure;
|
module.exports.printTestFailure = printTestFailure;
|
||||||
|
module.exports.printDebug = printDebug;
|
||||||
|
|||||||
@@ -12,10 +12,12 @@
|
|||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
|
"moment": "^2.17.1",
|
||||||
"node-ssdp": "^3.2.0",
|
"node-ssdp": "^3.2.0",
|
||||||
"q": "~1.4.1",
|
"q": "~1.4.1",
|
||||||
"request": "^2.78.0",
|
"request": "^2.78.0",
|
||||||
"sprintf-js": "~1.0.3",
|
"sprintf-js": "~1.0.3",
|
||||||
|
"winston": "^2.3.1",
|
||||||
"yargs": "^6.3.0"
|
"yargs": "^6.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,20 @@ function test() {
|
|||||||
.then(function () {
|
.then(function () {
|
||||||
utils.printTestInfo(__filename.slice(__dirname.length + 1) , "Perform DIAL discovery and ensure that the server under test is discovered");
|
utils.printTestInfo(__filename.slice(__dirname.length + 1) , "Perform DIAL discovery and ensure that the server under test is discovered");
|
||||||
})
|
})
|
||||||
.then(dial.discover)
|
.then(function discover() {
|
||||||
|
utils.printDebug("Performing discovery ..");
|
||||||
|
return dial.discover();
|
||||||
|
})
|
||||||
.then(function findServerInList(servers) {
|
.then(function findServerInList(servers) {
|
||||||
var found = false;
|
var found = false;
|
||||||
servers.forEach(function (server) {
|
servers.forEach(function (server) {
|
||||||
if(server.host === testServer) {
|
if(server.host === testServer) {
|
||||||
|
utils.printDebug("Found " + server.host + " in discovered list of servers");
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!found) {
|
if(!found) {
|
||||||
|
utils.printDebug("Did not find " + testServer + " in discovered list of servers");
|
||||||
return Q.reject(new Error("DIAL client was not able to discover the server under test : " + testServer));
|
return Q.reject(new Error("DIAL client was not able to discover the server under test : " + testServer));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,25 +39,36 @@ function test() {
|
|||||||
if(!result || !result.state) {
|
if(!result || !result.state) {
|
||||||
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
||||||
}
|
}
|
||||||
|
utils.printDebug("Application status is " + result.state);
|
||||||
if(result.state !== "hidden") {
|
if(result.state !== "hidden") {
|
||||||
if(result.state === "stopped") {
|
if(result.state === "stopped") {
|
||||||
// Launch and hide app
|
// Launch and hide app
|
||||||
return dial.launchApplication(host, app)
|
return dial.launchApplication(host, app)
|
||||||
|
.then(function () {
|
||||||
|
utils.printDebug("Requested server to launch application ..");
|
||||||
|
})
|
||||||
.delay(timeToWaitForStateChange)
|
.delay(timeToWaitForStateChange)
|
||||||
.then(dial.getApplicationStatus.bind(null, host, app))
|
.then(dial.getApplicationStatus.bind(null, host, app))
|
||||||
.then(function checkAppStatus(result) {
|
.then(function checkAppStatus(result) {
|
||||||
if(!result || !result.state) {
|
if(!result || !result.state) {
|
||||||
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
||||||
}
|
}
|
||||||
|
utils.printDebug("Application status is " + result.state);
|
||||||
if(result.state !== "running") {
|
if(result.state !== "running") {
|
||||||
return Q.reject(new Error("Expected " + app + " app status to be running but the state was " + result.state));
|
return Q.reject(new Error("Expected " + app + " app status to be running but the state was " + result.state));
|
||||||
}
|
}
|
||||||
console.log("app was running");
|
})
|
||||||
|
.then(function () {
|
||||||
|
utils.printDebug("Hide application ..");
|
||||||
})
|
})
|
||||||
.then(dial.hideApplication.bind(null, host, app))
|
.then(dial.hideApplication.bind(null, host, app))
|
||||||
.delay(timeToWaitForStateChange);
|
.delay(timeToWaitForStateChange);
|
||||||
}
|
}
|
||||||
return dial.hideApplication(host, app)
|
return new Q()
|
||||||
|
.then(function () {
|
||||||
|
utils.printDebug("Hide application ..");
|
||||||
|
return dial.hideApplication(host, app);
|
||||||
|
})
|
||||||
.delay(timeToWaitForStateChange);
|
.delay(timeToWaitForStateChange);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -68,11 +79,15 @@ function test() {
|
|||||||
if(!result || !result.state) {
|
if(!result || !result.state) {
|
||||||
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
||||||
}
|
}
|
||||||
|
utils.printDebug("Application status is now " + result.state);
|
||||||
if(result.state !== "hidden") {
|
if(result.state !== "hidden") {
|
||||||
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
|
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
.then(function () {
|
||||||
|
utils.printDebug("Hide application ..");
|
||||||
|
})
|
||||||
.then(dial.hideApplication.bind(null, host, app))
|
.then(dial.hideApplication.bind(null, host, app))
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
if(response.statusCode !== 200) {
|
if(response.statusCode !== 200) {
|
||||||
@@ -85,6 +100,7 @@ function test() {
|
|||||||
if(!result || !result.state) {
|
if(!result || !result.state) {
|
||||||
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
return Q.reject(new Error("Could not retrieve current " + app + " application state"));
|
||||||
}
|
}
|
||||||
|
utils.printDebug("Application status is " + result.state);
|
||||||
if(result.state !== "hidden") {
|
if(result.state !== "hidden") {
|
||||||
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
|
return Q.reject(new Error("Expected " + app + " app status to be hidden but the state was " + result.state));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user