From cb1879dfa633701c26f329ce9e0f7eb87542fd7d Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 4 Nov 2015 14:56:12 -0800 Subject: [PATCH] Add deployment tests. Closes #21. --- .travis.yml | 5 ++ package.json | 1 + test/appengine/test.js | 76 +++++++++++++++++++++------ test/encrypted/express-demo.json | 7 +++ test/encrypted/express-demo.json.enc | Bin 0 -> 2048 bytes 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 test/encrypted/express-demo.json create mode 100644 test/encrypted/express-demo.json.enc diff --git a/.travis.yml b/.travis.yml index dce4356f0c0..e19a260ffb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,10 +44,15 @@ before_install: printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh && cd $TRAVIS_BUILD_DIR; fi +- gcloud components update preview - openssl aes-256-cbc -K $encrypted_95e832a36b06_key -iv $encrypted_95e832a36b06_iv -in nodejs-docs-samples.json.enc -out nodejs-docs-samples.json -d - 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 diff --git a/package.json b/package.json index ddf938af216..1ff43530246 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/appengine/test.js b/test/appengine/test.js index 74c3030e18d..d523ece7e64 100644 --- a/test/appengine/test.js +++ b/test/appengine/test.js @@ -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(); @@ -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.' @@ -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) { @@ -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); + }); }); diff --git a/test/encrypted/express-demo.json b/test/encrypted/express-demo.json new file mode 100644 index 00000000000..a3233fbfefb --- /dev/null +++ b/test/encrypted/express-demo.json @@ -0,0 +1,7 @@ +{ + "private_key_id": "86afabe11b39d5451f9e324a18295fc1dcdc0b67", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDdkLGvD5y49ESR\nTnPLSGOlV3Cy304Rz81z3JTFqGKsN0POupF/mK+nHxEH9UoKAkuChdUR750qH21P\njvBBEcDI9hUqh9oisYXbOFZpelune+6QQ9v7BJZgeJ5hcVCpUASA4d6V087OgP1o\nLlR4IbHOO9GP7ra7tudQ2xDuDgBz9LgGKern1y+1WBOop6zL0f0NCOlutFirZOa9\n1RRRM4C7cQMHW6bbFb5PtvmEhfeLXjMeXal5lxS2wrucNcJHpi/jVbHGC3+57uFr\nPpi06tjJu/Tr1RPHt6Hd4pwCoetjXaVQTFcbEoPL3dYzj6E32WpEqRCKa6ZMTegD\nSaI0Iq6PAgMBAAECggEAJmtEpDpszpVsnlWgNoui27TB0gJuoyAJXCHPmkaMdZhP\npbUsLZfoPW5hoaOi5wFm3oceXzHRatBwP+9lMaNGbpJdMTbFWGa38z9dnISfB/ex\nckqSBoDRIoFH1VW0yucZINAJrKlBnwU266287+fH0R8GQ5L9FKeujJKv6Nd8tJ5U\nAlCLAv9Fw3EbQpbi8poQdL31dycwuqinzmY9suwih/zsv2U9PZTC2fNJOstiweDe\nd5Zvlabbw0H8ER2gVCnKppFcC6sMde7bCya3hmvihaBfLJJKORL885GNK8dW+nsv\nyV1Rh1a4Q5BUASEJqOHRaFWIhIjjyXblUkNfMgFSoQKBgQDuvx++7+CHbw/ySTd0\nuHcen+I/36Pmq2euH24qvuBl/2uxohUJQfI2aUuTtj0VAFOVPSnHU/YIXJd4gR6s\nt8lpDViQjcesDMsumlPaDrALXfnSPDiOtgSezEwPZBOwPFtnJyGBwgOmomvjriec\nJRBKsyUkQydU+W6l4UhlI1bfUwKBgQDtk7XMu88sIhVWi0XsWbUW3I/FG3CBGLzq\n90soFMLlqEyT45BmkW82eHAxIpzr+eJUhUViGZbslg1ccl4l1NaV/RiN3kQvNH+t\ni2c3GX4XuhaMuSFHFqDDqhYgjG6hea4es0eaZtbTMs2ZGZzCzMhZ0g6r++dobcEZ\nYJ10c6JYVQKBgAa11HyXXWYxFu+mYyqirKZts/w7mu22z5kzRPNqnf//59T8Sz8R\nXW9uEjO6oYjfk3nUWEJD99xQTemTJ3uPRtfvChg2A/CwA13x9H1igEwxff4Mt0I7\nl3GnKFQeafdAGwmRLf3pqBSc6A9kK7TVzdlro5WbVZWr1RJQfKprDdwFAoGAGkoC\nEAmoPyX2XoFC14iFtWXqstD6fg6SuR1sP58sgeVBtAu2auMk/04MfCNsYeBg3yFw\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" +} \ No newline at end of file diff --git a/test/encrypted/express-demo.json.enc b/test/encrypted/express-demo.json.enc new file mode 100644 index 0000000000000000000000000000000000000000..c8a52142e6b05c0754eeb858c40be2d775668f51 GIT binary patch literal 2048 zcmV+b2>HJr#wfT}hH8x)5Vvzy2Mhi z2gw8GqN-~&kq?Z*#WAk)A|6)u1(tx!(XsR(t|1#wz-#oraw?u~JsO9t``Yk$^ppl} z)wuYbGS{f$Afc|z;gz`=upfo(=Es0vuj4i9iJU^c)|ud2o^W@zVAtb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