Skip to content

Commit

Permalink
Add deployment tests. Closes #21.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 4, 2015
1 parent 5469269 commit b6f2e7a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ before_install:
- if [ -a nodejs-docs-samples.json ]; then
gcloud auth activate-service-account --key-file nodejs-docs-samples.json;
fi
- openssl aes-256-cbc -K $encrypted_4e84c7c7ab67_key -iv $encrypted_4e84c7c7ab67_iv -in test/encrypted/express-demo.json.enc -out test/encrypted/express-demo.json -d
- if [ -a test/encrypted/express-demo.json ]; then
gcloud auth activate-service-account --key-file test/encrypted/express-demo.json;
fi

install:
#Add app specific setup here
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"googleapis": "~2.1.3"
},
"devDependencies": {
"async": "^1.5.0",
"coveralls": "^2.11.4",
"istanbul": "^0.4.0",
"jshint": "~2.8.0",
Expand Down
76 changes: 60 additions & 16 deletions test/appengine/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
'use strict';

var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var request = require('request');
var async = require('async');

var cwd = process.cwd();

Expand All @@ -25,6 +27,7 @@ function getPath(dir) {
var sampleTests = [
{
dir: 'express',
projectId: 'express-demo',
cmd: 'node',
arg1: './bin/www',
msg: 'Hello World! Express.js on Google App Engine.'
Expand Down Expand Up @@ -93,6 +96,27 @@ if (process.env.TRAVIS_NODE_VERSION !== 'stable') {
});
}

function end(timeoutId, intervalId, proc) {
clearTimeout(timeoutId);
clearInterval(intervalId);
proc.kill('SIGKILL');
}

function testRequest(url, sample, cb) {
request(url, function (err, res, body) {
if (err) {
cb(err, false);
} else {
if (body && body.indexOf(sample.msg) !== -1 &&
(res.statusCode === 200 || res.statusCode === sample.code)) {
cb(null, true);
} else {
cb(null, false);
}
}
});
}

describe('appengine/', function () {
sampleTests.forEach(function (sample) {
it(sample.dir + ': dependencies should install', function (done) {
Expand Down Expand Up @@ -166,24 +190,44 @@ describe('appengine/', function () {
}
});

timeoutId = setTimeout(end, 5000);
intervalId = setInterval(testRequest, 1000);

function end() {
clearTimeout(timeoutId);
clearInterval(intervalId);
proc.kill('SIGKILL');
}

function testRequest() {
request('http://localhost:8080', function (err, res, body) {
if (body && body.indexOf(sample.msg) !== -1 &&
(res.statusCode === 200 || res.statusCode === sample.code)) {
success = true;
end();
timeoutId = setTimeout(function () {
end(timeoutId, intervalId, proc);
}, 5000);
intervalId = setInterval(function () {
testRequest('http://localhost:8080', sample, function (err, _success) {
if (err) {
console.log(err);
} else {
success = _success;
}
end(timeoutId, intervalId, proc);
});
}
}, 1000);
});
});

if (!process.env.TRAVIS) {
return;
}

it('should deploy all samples', function (done) {
async.parallel(sampleTests.map(function (sample) {
if (sample.projectId) {
return function (cb) {
exec('npm run deploy', {
cwd: getPath(sample.dir),
maxBuffer: 1000000
}, function (err) {
if (err) {
return cb(err);
} else {
var url = 'http://' + sample.projectId + '.appspot.com';
return testRequest(url, sample, cb);
}
});
};
}
return function (cb) { cb(); };
}), done);
});
});
7 changes: 7 additions & 0 deletions test/encrypted/express-demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private_key_id": "86afabe11b39d5451f9e324a18295fc1dcdc0b67",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDdkLGvD5y49ESR\nTnPLSGOlV3Cy304Rz81z3JTFqGKsN0POupF/mK+nHxEH9UoKAkuChdUR750qH21P\njvBBEcDI9hUqh9oisYXbOFZpelune+6QQ9v7BJZgeJ5hcVCpUASA4d6V087OgP1o\nLlR4IbHOO9GP7ra7tudQ2xDuDgBz9LgGKern1y+1WBOop6zL0f0NCOlutFirZOa9\n1RRRM4C7cQMHW6bbF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YeBg3yFw\nMA7M2JkyGUy+hkkrBaXgFbLGsMKKblXCsiIsBcwduqyxtgAXAg/MKwXfKBci4VrN\nTZSbqPsyLQLcieHHOck4vmc9kBy1BW3ffoddK5ECgYEAx8zQuR9nx/nwFayxmCC3\ntqQQo5bphwh5BVzOM39QwcLRLqY/j7WNcPcwItBf1E3OZr16hRmklMdWFn2WSqqq\nG58j6gkIzaflsYmT+i/R0uWi8EZ69NUz5lvwbPBsuy+rLXSw0qkB5JqQag9Zjd6O\nukcH/qn8yIcIZOB3yGrcryI\u003d\n-----END PRIVATE KEY-----\n",
"client_email": "331060524961-5tu4fsd2sej6cdc6iv6kuvv5p0chri0i@developer.gserviceaccount.com",
"client_id": "331060524961-5tu4fsd2sej6cdc6iv6kuvv5p0chri0i.apps.googleusercontent.com",
"type": "service_account"
}
Binary file added test/encrypted/express-demo.json.enc
Binary file not shown.

0 comments on commit b6f2e7a

Please sign in to comment.