Send selfhosting test logs as attachments with result mail

This commit is contained in:
Johannes Zellner 2016-09-14 16:19:23 +02:00
parent 0ac94427e7
commit b003fc0190
4 changed files with 44 additions and 11 deletions

View File

@ -8,11 +8,15 @@ var debug = require('debug')('e2e:runner'),
shell = require('./shell.js'), shell = require('./shell.js'),
semver = require('semver'), semver = require('semver'),
mailer = require('./mailer.js'), mailer = require('./mailer.js'),
mkdirp = require('mkdirp'),
rimraf = require('rimraf'),
superagent = require('superagent'), superagent = require('superagent'),
terminate = require('terminate'), terminate = require('terminate'),
util = require('util'), util = require('util'),
_ = require('underscore'); _ = require('underscore');
var LOG_FILE_DIR = '/tmp/testlog/';
// override debug.log to print only as console.log // override debug.log to print only as console.log
debug.log = console.log.bind(console); debug.log = console.log.bind(console);
@ -80,14 +84,19 @@ function getLatestBoxVersion(callback) {
function runTests(latestVersionInfo, callback) { function runTests(latestVersionInfo, callback) {
debug('Running tests for %j', latestVersionInfo); debug('Running tests for %j', latestVersionInfo);
gNpmTest = shell.system('e2etestrunner', 'BOX_VERSION=' + latestVersionInfo.version + ' npm run-script parallel_test', function (error, stdout, stderr) { // The selfhosting tests use a logfile for cli tool output, to avoid spamming the test results with script output
// These will be stored in /tmp/testlog/<testfilename>.log
rimraf.sync(LOG_FILE_DIR);
mkdirp.sync(LOG_FILE_DIR);
gNpmTest = shell.system('e2etestrunner', 'LOG_FILE_DIR=' + LOG_FILE_DIR + ' BOX_VERSION=' + latestVersionInfo.version + ' npm run-script parallel_test', function (error, stdout, stderr) {
gNpmTest = null; gNpmTest = null;
debug('Final test result', error); debug('Final test result', error);
var topic = util.format('E2E Test %s for box version: %s', error ? 'failed': 'passed', latestVersionInfo.version); var topic = util.format('E2E Test %s for box version: %s', error ? 'failed': 'passed', latestVersionInfo.version);
// do not send stderr in mail since it contains the tail log stream // do not send stderr in mail since it contains the tail log stream
mailer.sendEndToEndTestResult(topic, JSON.stringify(latestVersionInfo, null, 4), stdout ? stdout.toString('utf8') : '', '', function () { }); mailer.sendEndToEndTestResult(topic, JSON.stringify(latestVersionInfo, null, 4), stdout ? stdout.toString('utf8') : '', '', LOG_FILE_DIR, function () { });
return callback(error); return callback(error);
}); });
} }

View File

@ -2,6 +2,8 @@
var assert = require('assert'), var assert = require('assert'),
debug = require('debug')('e2e:mailer'), debug = require('debug')('e2e:mailer'),
fs = require('fs'),
path = require('path'),
postmark = require('postmark')(process.env.POSTMARK_API_KEY_TOOLS), postmark = require('postmark')(process.env.POSTMARK_API_KEY_TOOLS),
util = require('util'); util = require('util');
@ -25,7 +27,8 @@ function send(options, callback) {
'Subject': options.subject, 'Subject': options.subject,
'TextBody': options.text, 'TextBody': options.text,
'HtmlBody': options.html, 'HtmlBody': options.html,
'Tag': 'Important' 'Tag': 'Important',
'Attachments': options.attachments || []
}, function (error, success) { }, function (error, success) {
if (error) { if (error) {
console.error('Unable to send via postmark: ', error); console.error('Unable to send via postmark: ', error);
@ -36,16 +39,35 @@ function send(options, callback) {
}); });
} }
function sendEndToEndTestResult(topic, versionInfo, stdout, stderr, callback) { function sendEndToEndTestResult(topic, versionInfo, stdout, stderr, attachmentFolder, callback) {
debug('Sending e2e test result for %s', topic); debug('Sending e2e test result for %s', topic);
fs.readdir(attachmentFolder, function (error, files) {
var attachments = [];
if (!error) {
attachments = files.filter(function (file) {
return fs.statSync(path.join(attachmentFolder, file)).isFile();
}).map(function (file) {
var filePath = path.join(attachmentFolder, file);
return {
Content: fs.readFileSync(filePath).toString('base64'),
Name: file,
ContentType: 'text/plain'
};
});
}
var mailOptions = { var mailOptions = {
to: 'test@cloudron.io', to: 'test@cloudron.io',
subject: util.format('E2E test results for %s', topic), subject: util.format('E2E test results for %s', topic),
text: versionInfo + '\n\nstdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n' text: versionInfo + '\n\nstdout\n------\n' + stdout.toString('utf8') + '\n\nstderr\n------\n' + stderr.toString('utf8') + '\n\n',
attachments: attachments
}; };
send(mailOptions, callback); send(mailOptions, callback);
});
} }
function sendMailToCloudronUser(email, callback) { function sendMailToCloudronUser(email, callback) {

View File

@ -20,6 +20,7 @@
"debug": "^2.2.0", "debug": "^2.2.0",
"dns-sync": "^0.1.3", "dns-sync": "^0.1.3",
"imap": "^0.8.17", "imap": "^0.8.17",
"mkdirp": "^0.5.1",
"mocha": "^2.2.5", "mocha": "^2.2.5",
"nodemailer": "^2.4.2", "nodemailer": "^2.4.2",
"nodemailer-smtp-transport": "^2.5.0", "nodemailer-smtp-transport": "^2.5.0",
@ -27,6 +28,7 @@
"postmark": "^1.0.0", "postmark": "^1.0.0",
"quoted-printable": "^1.0.0", "quoted-printable": "^1.0.0",
"readline-sync": "^1.2.19", "readline-sync": "^1.2.19",
"rimraf": "^2.5.4",
"safetydance": "0.0.17", "safetydance": "0.0.17",
"semver": "^4.3.6", "semver": "^4.3.6",
"should": "^6.0.3", "should": "^6.0.3",

View File

@ -20,7 +20,7 @@ fi
# run tests # run tests
readonly tests=(app-flow-test app-update-test alt-domain-test cloudron-button-test cloudron-user-test new-user-test cloudron-backup-test cloudron-migrate-test cloudron-autoupdate-sfo1-test cloudron-update-ams3-test selfhost-ec2-test selfhost-digitalocean-test) readonly tests=(app-flow-test app-update-test alt-domain-test cloudron-button-test cloudron-user-test new-user-test cloudron-backup-test cloudron-migrate-test cloudron-autoupdate-sfo1-test cloudron-update-ams3-test selfhost-ec2-test selfhost-digitalocean-test)
for t in "${tests[@]}"; do for t in "${tests[@]}"; do
./node_modules/.bin/mocha --bail "test/${t}.js" > "logs/${t}.log" 2>&1 & EXEC_LOG_FILE="${LOG_FILE_DIR}/${t}.log" ./node_modules/.bin/mocha --bail "test/${t}.js" > "logs/${t}.log" 2>&1 &
test_pids+=("$!") test_pids+=("$!")
echo "Starting test ${t} with pid ${test_pids[-1]}" echo "Starting test ${t} with pid ${test_pids[-1]}"
test_logs+=("logs/${t}.log") test_logs+=("logs/${t}.log")