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'),
semver = require('semver'),
mailer = require('./mailer.js'),
mkdirp = require('mkdirp'),
rimraf = require('rimraf'),
superagent = require('superagent'),
terminate = require('terminate'),
util = require('util'),
_ = require('underscore');
var LOG_FILE_DIR = '/tmp/testlog/';
// override debug.log to print only as console.log
debug.log = console.log.bind(console);
@ -80,14 +84,19 @@ function getLatestBoxVersion(callback) {
function runTests(latestVersionInfo, callback) {
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;
debug('Final test result', error);
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
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);
});
}

View File

@ -2,6 +2,8 @@
var assert = require('assert'),
debug = require('debug')('e2e:mailer'),
fs = require('fs'),
path = require('path'),
postmark = require('postmark')(process.env.POSTMARK_API_KEY_TOOLS),
util = require('util');
@ -25,7 +27,8 @@ function send(options, callback) {
'Subject': options.subject,
'TextBody': options.text,
'HtmlBody': options.html,
'Tag': 'Important'
'Tag': 'Important',
'Attachments': options.attachments || []
}, function (error, success) {
if (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);
var mailOptions = {
to: 'test@cloudron.io',
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'
};
fs.readdir(attachmentFolder, function (error, files) {
var attachments = [];
send(mailOptions, callback);
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 = {
to: 'test@cloudron.io',
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',
attachments: attachments
};
send(mailOptions, callback);
});
}
function sendMailToCloudronUser(email, callback) {

View File

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

View File

@ -20,7 +20,7 @@ fi
# 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)
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+=("$!")
echo "Starting test ${t} with pid ${test_pids[-1]}"
test_logs+=("logs/${t}.log")