From ac26da16e2f506e9778c6dc0bf84c53e14fc0e28 Mon Sep 17 00:00:00 2001 From: Shruti Ranganathan Jothi Date: Wed, 8 Mar 2017 09:57:53 -0800 Subject: [PATCH] use sprintf-js to format console logs --- server/tests/js_tests/libs/utils.js | 20 ++++++++++++++++++- server/tests/js_tests/package.json | 9 +++++---- .../js_tests/tests/discoverServerUnderTest.js | 6 +++--- .../tests/hideApplicationInHiddenState.js | 6 +++--- .../tests/hideApplicationInRunningState.js | 6 +++--- .../tests/hideInvalidApplicationInstance.js | 6 +++--- ...chApplicationInHiddenStateWithNoPayload.js | 6 +++--- ...unchApplicationInHiddenStateWithPayload.js | 6 +++--- ...hApplicationInRunningStateWithNoPayload.js | 6 +++--- ...nchApplicationInRunningStateWithPayload.js | 6 +++--- ...hApplicationInStoppedStateWithNoPayload.js | 6 +++--- ...nchApplicationInStoppedStateWithPayload.js | 6 +++--- .../tests/launchApplicationNotRecognized.js | 6 +++--- .../launchApplicationWithExcessPayload.js | 6 +++--- .../tests/stopApplicationInHiddenState.js | 6 +++--- .../tests/stopApplicationInRunningState.js | 6 +++--- .../tests/stopApplicationInStoppedState.js | 6 +++--- .../tests/stopInvalidApplicationInstance.js | 6 +++--- 18 files changed, 72 insertions(+), 53 deletions(-) diff --git a/server/tests/js_tests/libs/utils.js b/server/tests/js_tests/libs/utils.js index 4fb653e..2836324 100644 --- a/server/tests/js_tests/libs/utils.js +++ b/server/tests/js_tests/libs/utils.js @@ -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; diff --git a/server/tests/js_tests/package.json b/server/tests/js_tests/package.json index 5b74bc5..dcd1739 100644 --- a/server/tests/js_tests/package.json +++ b/server/tests/js_tests/package.json @@ -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" } } diff --git a/server/tests/js_tests/tests/discoverServerUnderTest.js b/server/tests/js_tests/tests/discoverServerUnderTest.js index 4bd0d07..64b8f27 100644 --- a/server/tests/js_tests/tests/discoverServerUnderTest.js +++ b/server/tests/js_tests/tests/discoverServerUnderTest.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/hideApplicationInHiddenState.js b/server/tests/js_tests/tests/hideApplicationInHiddenState.js index 8283c4e..9129bd0 100644 --- a/server/tests/js_tests/tests/hideApplicationInHiddenState.js +++ b/server/tests/js_tests/tests/hideApplicationInHiddenState.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/hideApplicationInRunningState.js b/server/tests/js_tests/tests/hideApplicationInRunningState.js index 1349dbb..906b641 100644 --- a/server/tests/js_tests/tests/hideApplicationInRunningState.js +++ b/server/tests/js_tests/tests/hideApplicationInRunningState.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js index 2199b09..852f90d 100644 --- a/server/tests/js_tests/tests/hideInvalidApplicationInstance.js +++ b/server/tests/js_tests/tests/hideInvalidApplicationInstance.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js index 643eccb..0903e34 100644 --- a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithNoPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js index 5c23be5..3f18f89 100644 --- a/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInHiddenStateWithPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js index a5e07c3..a1eb81b 100644 --- a/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithNoPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js index 2fdbcb5..ca7799f 100644 --- a/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInRunningStateWithPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js index 6768ac4..1988d2a 100644 --- a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithNoPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js index 940d838..32fc2b7 100644 --- a/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js +++ b/server/tests/js_tests/tests/launchApplicationInStoppedStateWithPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationNotRecognized.js b/server/tests/js_tests/tests/launchApplicationNotRecognized.js index 1b191a0..43194ff 100644 --- a/server/tests/js_tests/tests/launchApplicationNotRecognized.js +++ b/server/tests/js_tests/tests/launchApplicationNotRecognized.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js index 3a459d9..7be21f9 100644 --- a/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js +++ b/server/tests/js_tests/tests/launchApplicationWithExcessPayload.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInHiddenState.js b/server/tests/js_tests/tests/stopApplicationInHiddenState.js index 8abfe87..a09f17e 100644 --- a/server/tests/js_tests/tests/stopApplicationInHiddenState.js +++ b/server/tests/js_tests/tests/stopApplicationInHiddenState.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInRunningState.js b/server/tests/js_tests/tests/stopApplicationInRunningState.js index 0b55b26..099707c 100644 --- a/server/tests/js_tests/tests/stopApplicationInRunningState.js +++ b/server/tests/js_tests/tests/stopApplicationInRunningState.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/stopApplicationInStoppedState.js b/server/tests/js_tests/tests/stopApplicationInStoppedState.js index 4d9e137..3d7ca1d 100644 --- a/server/tests/js_tests/tests/stopApplicationInStoppedState.js +++ b/server/tests/js_tests/tests/stopApplicationInStoppedState.js @@ -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); }); } diff --git a/server/tests/js_tests/tests/stopInvalidApplicationInstance.js b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js index 4b42cc0..5437267 100644 --- a/server/tests/js_tests/tests/stopInvalidApplicationInstance.js +++ b/server/tests/js_tests/tests/stopInvalidApplicationInstance.js @@ -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); }); }