use sprintf-js to format console logs

This commit is contained in:
Shruti Ranganathan Jothi
2017-03-08 09:57:53 -08:00
parent 44f1acb300
commit ac26da16e2
18 changed files with 72 additions and 53 deletions

View File

@@ -1,5 +1,8 @@
"use strict";
var colors = require("colors/safe");
var sprintf = require("sprintf-js").sprintf;
function getParam(key) {
var value;
var args = process.argv.slice(2);
@@ -11,4 +14,19 @@ function getParam(key) {
return value;
}
module.exports.getParam = getParam;
function printTestInfo(test, msg) {
return console.log(sprintf("%-20s : %-s\n%-20s : %-s", "Test", test, "Description", msg));
}
function printSuccess() {
return console.log(colors.green("TEST PASSED\n"));
}
function printFailure(err) {
return console.log(colors.red(sprintf("%-20s : %-s\n", "TEST FAILED", err)));
}
module.exports.getParam = getParam;
module.exports.printTestInfo = printTestInfo;
module.exports.printSuccess = printSuccess;
module.exports.printFailure = printFailure;

View File

@@ -7,13 +7,14 @@
"url": "https://github.com/Netflix/dial-reference.git"
},
"main": "",
"scripts": {
},
"scripts": {},
"author": "Shruti Ranganathan Jothi",
"license": "BSD-2-Clause",
"dependencies": {
"q": "~1.4.1",
"colors": "^1.1.2",
"node-ssdp": "^3.2.0",
"request": "^2.78.0"
"q": "~1.4.1",
"request": "^2.78.0",
"sprintf-js": "~1.0.3"
}
}

View File

@@ -9,7 +9,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": 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 findServerInList(servers) {
@@ -24,10 +24,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.log("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Try to hide " + app + " when it is already in hidden state and expect response code 200 from the DIAL server");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to hide " + app + " when it is already in hidden state and expect response code 200 from the DIAL server");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) {
@@ -67,10 +67,10 @@ function test() {
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Hide " + app + " application when it is running and expect response code 200");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Hide " + app + " application when it is running and expect response code 200");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
@@ -60,10 +60,10 @@ function test() {
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Try to hide an invalid instance of " + app + " application and expect status code 404");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to hide an invalid instance of " + app + " application and expect status code 404");
})
.then(dial.launchApplication.bind(null, host, app))
.then(function (response) {
@@ -50,10 +50,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + " Launch " + app + " application using DIAL server when app is in hidden state and check for response code 201 ");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when app is in hidden state and check for response code 201 ");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) {
@@ -60,10 +60,10 @@ function test() {
})
.delay(timeToWaitForStateChange)
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + " Launch " + app + " application with payload using DIAL server when app is in hidden state and check for response code 201 ");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when app is in hidden state and check for response code 201 ");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) {
@@ -60,10 +60,10 @@ function test() {
})
.delay(timeToWaitForStateChange)
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Launch " + app + " without payload using DIAL server when application is already running and check for response code 201");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " without payload using DIAL server when application is already running and check for response code 201");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
@@ -58,10 +58,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Launch " + app + " with payload using DIAL server when application is already running and check for response code 201");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " with payload using DIAL server when application is already running and check for response code 201");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
@@ -59,10 +59,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Launch " + app + " application using DIAL server when the application is in STOPPED state and expect response code 201");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application using DIAL server when the application is in STOPPED state and expect response code 201");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) {
@@ -60,10 +60,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Launch " + app + " application with payload using DIAL server when the application is in STOPPED state and expect response code 201");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch " + app + " application with payload using DIAL server when the application is in STOPPED state and expect response code 201");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function stopAppIfNecessary(result) {
@@ -60,10 +60,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -10,7 +10,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Launch an application that is not recognized by DIAL server and check for response code 404");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Launch an application that is not recognized by DIAL server and check for response code 404");
})
.then(dial.launchApplication.bind(null, host, "ApplicationNotRecognized"))
.then(function (response) {
@@ -19,10 +19,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -44,7 +44,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Try to launch " + app + " application with excess payload and ensure DIAL server returns response code 413");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to launch " + app + " application with excess payload and ensure DIAL server returns response code 413");
})
.then(dial.launchApplication.bind(null, host, app, payload))
.then(function (response) {
@@ -53,10 +53,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Stop " + app + " application using DIAL server when the application is in hidden state and expect response code 200");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application using DIAL server when the application is in hidden state and expect response code 200");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function hideApp(result) {
@@ -67,10 +67,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Stop " + app + " application when it is running and check for response code 200 from DIAL server ");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Stop " + app + " application when it is running and check for response code 200 from DIAL server ");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
@@ -59,10 +59,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -12,7 +12,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Try to stop " + app + " application using DIAL server when the application is already stopped and expect response code 200.");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to stop " + app + " application using DIAL server when the application is already stopped and expect response code 200.");
})
.then(dial.getApplicationStatus.bind(null, host, app))
.then(function getCurrentAppState(result) {
@@ -86,10 +86,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}

View File

@@ -11,7 +11,7 @@ function test() {
return new Q()
.then(function () {
console.log("TEST " + __filename + ": Try to stop invalid " + app + " application instance and check for DIAL server response code 404");
utils.printTestInfo(__filename.slice(__dirname.length + 1), "Try to stop invalid " + app + " application instance and check for DIAL server response code 404");
})
.then(dial.launchApplication.bind(null, host, app))
.delay(timeToWaitForStateChange)
@@ -46,10 +46,10 @@ function test() {
}
})
.then(function () {
console.log("TEST PASSED");
utils.printSuccess()
})
.fail(function handleError(err) {
console.error("TEST FAILED " + err);
utils.printFailure(err);
});
}