Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#50 from GoogleCloudPlatform/te…
Browse files Browse the repository at this point in the history
…st-deploy

Added deployment tests
  • Loading branch information
jmdobry committed Apr 27, 2016
2 parents e06427d + ea04fba commit 08560e5
Show file tree
Hide file tree
Showing 86 changed files with 2,791 additions and 1,622 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage/
test/encrypted/nodejs-docs-samples.json
*.iml
.idea/
config.json
config.json
key.json
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
sudo: false
language: node_js
node_js:
- "stable"
- "0.12"
- "4"

cache:
directories:
Expand All @@ -34,12 +33,6 @@ env:
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json
- CLOUD_BUCKET=nodejs-docs-samples
- GCLOUD_PROJECT=nodejs-docs-samples
- OAUTH_CLIENT_ID=test-id
- OAUTH_CLIENT_SECRET=test-secret
matrix:
- DATA_BACKEND=datastore
- DATA_BACKEND=mongodb
- DATA_BACKEND=cloudsql

before_install:
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
Expand All @@ -57,4 +50,4 @@ before_install:
fi

after_success:
- npm run coveralls
- npm run codecov
3 changes: 3 additions & 0 deletions 1-hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
config.json
4 changes: 1 addition & 3 deletions 1-hello-world/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ if (module === require.main) {
// [START server]
// Start the server
var server = app.listen(process.env.PORT || 8080, function () {
var host = server.address().address;
var port = server.address().port;

console.log('App listening at http://%s:%s', host, port);
console.log('App listening on port %s', port);
});
// [END server]
}
Expand Down
15 changes: 13 additions & 2 deletions 1-hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud preview app deploy app.yaml",
"lint": "jshint --exclude-path=../.gitignore .",
"mocha": "mocha test/index.js -t 30000",
"lint": "semistandard \"**/*.js\"",
"test": "npm run lint && npm run mocha"
},
"author": "Google Inc.",
Expand All @@ -28,12 +28,23 @@
}
],
"license": "Apache Version 2.0",
"semistandard": {
"globals": [
"after",
"afterEach",
"before",
"beforeEach",
"describe",
"it"
]
},
"dependencies": {
"express": "^4.13.4"
},
"devDependencies": {
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#21daa823090c43fb667157c8b5b0c3b7f45a8357",
"semistandard": "^7.0.5",
"supertest": "^1.2.0"
},
"engines": {
Expand Down
14 changes: 8 additions & 6 deletions 1-hello-world/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@

var assert = require('assert');
var config = require('./config');
var request = require('supertest');
var utils = require('../../test/utils');
var utils = require('nodejs-repo-tools');

describe('app.js', function () {
it('should run', function (done) {
utils.testLocalApp(config, done);
});
if (!process.env.E2E_TESTS) {
it('should run', function (done) {
utils.testLocalApp(config, done);
});
}

it('should create an express app', function (done) {
request(require('../app'))
utils.getRequest(config)
.get('/')
.expect(200)
.expect(function (response) {
Expand Down
2 changes: 1 addition & 1 deletion 1-hello-world/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var path = require('path');

module.exports = {
test: '1-hello-world',
path: path.resolve(path.join(__dirname, '../')),
cwd: path.resolve(path.join(__dirname, '../')),
cmd: 'node',
args: ['app.js'],
msg: 'Hello, world!'
Expand Down
12 changes: 7 additions & 5 deletions 1-hello-world/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
'use strict';

var config = require('./config');
var utils = require('../../test/utils');
var utils = require('nodejs-repo-tools');

describe(config.test + '/', function () {
it('should install dependencies', function (done) {
this.timeout(60 * 1000); // Allow 1 minute to test installation
utils.testInstallation(config, done);
});
if (!process.env.E2E_TESTS) {
it('should install dependencies', function (done) {
this.timeout(120 * 1000); // Allow 2 minutes to test installation
utils.testInstallation(config, done);
});
}
require('./app.test');
});
3 changes: 3 additions & 0 deletions 2-structured-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*.log
config.json
4 changes: 1 addition & 3 deletions 2-structured-data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ app.use(function (err, req, res, next) {
if (module === require.main) {
// Start the server
var server = app.listen(config.get('PORT'), function () {
var host = server.address().address;
var port = server.address().port;

console.log('App listening at http://%s:%s', host, port);
console.log('App listening on port %s', port);
});
}

Expand Down
15 changes: 9 additions & 6 deletions 2-structured-data/books/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
var express = require('express');
var bodyParser = require('body-parser');
var config = require('../config');
var model = require('./model-' + config.get('DATA_BACKEND'));

function getModel () {
return require('./model-' + config.get('DATA_BACKEND'));
}

var router = express.Router();

Expand All @@ -29,7 +32,7 @@ router.use(bodyParser.json());
* Retrieve a page of books (up to ten at a time).
*/
router.get('/', function list (req, res, next) {
model.list(10, req.query.pageToken, function (err, entities, cursor) {
getModel().list(10, req.query.pageToken, function (err, entities, cursor) {
if (err) {
return next(err);
}
Expand All @@ -46,7 +49,7 @@ router.get('/', function list (req, res, next) {
* Create a new book.
*/
router.post('/', function insert (req, res, next) {
model.create(req.body, function (err, entity) {
getModel().create(req.body, function (err, entity) {
if (err) {
return next(err);
}
Expand All @@ -60,7 +63,7 @@ router.post('/', function insert (req, res, next) {
* Retrieve a book.
*/
router.get('/:book', function get (req, res, next) {
model.read(req.params.book, function (err, entity) {
getModel().read(req.params.book, function (err, entity) {
if (err) {
return next(err);
}
Expand All @@ -74,7 +77,7 @@ router.get('/:book', function get (req, res, next) {
* Update a book.
*/
router.put('/:book', function update (req, res, next) {
model.update(req.params.book, req.body, function (err, entity) {
getModel().update(req.params.book, req.body, function (err, entity) {
if (err) {
return next(err);
}
Expand All @@ -88,7 +91,7 @@ router.put('/:book', function update (req, res, next) {
* Delete a book.
*/
router.delete('/:book', function _delete (req, res, next) {
model.delete(req.params.book, function (err) {
getModel().delete(req.params.book, function (err) {
if (err) {
return next(err);
}
Expand Down
17 changes: 10 additions & 7 deletions 2-structured-data/books/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
var express = require('express');
var bodyParser = require('body-parser');
var config = require('../config');
var model = require('./model-' + config.get('DATA_BACKEND'));

function getModel () {
return require('./model-' + config.get('DATA_BACKEND'));
}

var router = express.Router();

Expand All @@ -35,7 +38,7 @@ router.use(function (req, res, next) {
* Display a page of books (up to ten at a time).
*/
router.get('/', function list (req, res, next) {
model.list(10, req.query.pageToken, function (err, entities, cursor) {
getModel().list(10, req.query.pageToken, function (err, entities, cursor) {
if (err) {
return next(err);
}
Expand Down Expand Up @@ -70,7 +73,7 @@ router.post('/add', function insert (req, res, next) {
var data = req.body;

// Save the data to the database.
model.create(data, function (err, savedData) {
getModel().create(data, function (err, savedData) {
if (err) {
return next(err);
}
Expand All @@ -85,7 +88,7 @@ router.post('/add', function insert (req, res, next) {
* Display a book for editing.
*/
router.get('/:book/edit', function editForm (req, res, next) {
model.read(req.params.book, function (err, entity) {
getModel().read(req.params.book, function (err, entity) {
if (err) {
return next(err);
}
Expand All @@ -104,7 +107,7 @@ router.get('/:book/edit', function editForm (req, res, next) {
router.post('/:book/edit', function update (req, res, next) {
var data = req.body;

model.update(req.params.book, data, function (err, savedData) {
getModel().update(req.params.book, data, function (err, savedData) {
if (err) {
return next(err);
}
Expand All @@ -118,7 +121,7 @@ router.post('/:book/edit', function update (req, res, next) {
* Display a book.
*/
router.get('/:book', function get (req, res, next) {
model.read(req.params.book, function (err, entity) {
getModel().read(req.params.book, function (err, entity) {
if (err) {
return next(err);
}
Expand All @@ -134,7 +137,7 @@ router.get('/:book', function get (req, res, next) {
* Delete a book.
*/
router.get('/:book/delete', function _delete (req, res, next) {
model.delete(req.params.book, function (err) {
getModel().delete(req.params.book, function (err) {
if (err) {
return next(err);
}
Expand Down
23 changes: 18 additions & 5 deletions 2-structured-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud preview app deploy app.yaml",
"lint": "jshint --exclude-path=../.gitignore .",
"mocha": "mocha test/index.js -t 30000",
"lint": "semistandard \"**/*.js\"",
"test": "npm run lint && npm run mocha",
"init-cloudsql": "node books/model-cloudsql.js"
},
Expand All @@ -29,21 +29,34 @@
}
],
"license": "Apache Version 2.0",
"semistandard": {
"globals": [
"after",
"afterEach",
"before",
"beforeEach",
"describe",
"it"
]
},
"dependencies": {
"body-parser": "^1.15.0",
"express": "^4.13.4",
"gcloud": "^0.30.2",
"gcloud": "~0.31.0",
"jade": "^1.11.0",
"kerberos": "^0.0.19",
"lodash": "^4.8.2",
"mongodb": "^2.1.15",
"lodash": "^4.11.1",
"mongodb": "^2.1.16",
"mysql": "^2.10.2",
"nconf": "^0.8.4",
"prompt": "^1.0.0"
},
"devDependencies": {
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#21daa823090c43fb667157c8b5b0c3b7f45a8357",
"proxyquire": "^1.7.4",
"semistandard": "^7.0.5",
"sinon": "^1.17.3",
"supertest": "^1.2.0"
},
"engines": {
Expand Down
Loading

0 comments on commit 08560e5

Please sign in to comment.