-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSERV-1062 Adding diagnostics report to the testengine cli. (#33)
TSERV-1062 Adding diagnostics report to the testengine cli.
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const process = require('process'); | ||
const util = require('./shared_utils'); | ||
const config = require('./config').config; | ||
const request = require('superagent'); | ||
const fs = require('fs'); | ||
const resolve = require('path').resolve; | ||
|
||
module.exports.dispatcher = function (args) { | ||
if (args.length === 0) { | ||
printModuleHelp(); | ||
process.exit(1); | ||
} | ||
switch (args[0].toLowerCase()) { | ||
case 'run': { | ||
const options = util.optionsFromArgs(args.splice(1), ['output', 'reportFileName']); | ||
runDiagnostics(options['output'], options['reportFileName']); | ||
break; | ||
} | ||
case 'help': | ||
printModuleHelp(); | ||
break; | ||
default: | ||
util.printErrorAndExit("Unknown operation"); | ||
} | ||
} | ||
|
||
function runDiagnostics(outputFolder, fileName) { | ||
const endPoint = config.server + '/api/v1/diagnostics'; | ||
let reportFileName = "diagnostics.zip"; | ||
|
||
if (outputFolder) { | ||
if (!fs.existsSync(outputFolder)) { | ||
fs.mkdirSync(outputFolder, {recursive: true}); | ||
} | ||
} | ||
|
||
reportFileName = (outputFolder ? outputFolder + '/' : '') + (fileName ? fileName : reportFileName); | ||
if(!reportFileName.endsWith(".zip")) { | ||
reportFileName += ".zip"; | ||
} | ||
const stream = fs.createWriteStream(reportFileName); | ||
|
||
const req = request.get(endPoint) | ||
.auth(config.username, config.password) | ||
.accept("application/zip") | ||
.on('response', function (response) { | ||
if (response.status !== 200) { | ||
util.printErrorAndExit(`Status code: ${response.status}`); | ||
} else { | ||
util.output('Diagnostics report ' + resolve(reportFileName) + ' created successfully'); | ||
} | ||
}) | ||
.on('error', function (err) { | ||
util.error("Error: " + err.message); | ||
process.exit(1); | ||
}).send(); | ||
|
||
req.pipe(stream); | ||
} | ||
|
||
function printModuleHelp() { | ||
util.error("Usage: testengine diagnostics <command>"); | ||
util.error("Commands: "); | ||
util.error(" run [output=<directory>] [reportFileName=<filename>]"); | ||
util.error(" help"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters