Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#35 from GoogleCloudPlatform/test
Browse files Browse the repository at this point in the history
Added tests.
  • Loading branch information
jmdobry committed Feb 3, 2016
2 parents 0d14250 + 445bb39 commit df3a7b6
Show file tree
Hide file tree
Showing 115 changed files with 1,955 additions and 194 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.DS_Store
node_modules
**/node_modules/**
*.log
coverage/
test/encrypted/nodejs-docs-samples.json
*.iml
.idea/
13 changes: 10 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
"camelcase" : true,
"curly": true,
"eqeqeq": true,
"globalstrict": true,
"indent": 2,
"newcap": true,
"maxlen": 80,
"node": true,
"quotmark": "single",
"strict": true,
"strict": "global",
"trailing": true,
"undef": true,
"unused": true
"unused": true,
"globals": {
"after": false,
"afterEach": false,
"before": false,
"beforeEach": false,
"describe": false,
"it": false
}
}
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
# Copyright 2015-2016, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sudo: false
language: node_js
node_js:
- "stable"
- "0.12"
- "0.10"

cache:
directories:
- $HOME/gcloud/
- 1-hello-world/node_modules/
- 2-structured-data/node_modules/
- 3-binary-data/node_modules/
- 4-auth/node_modules/
- 5-logging/node_modules/
- 6-pubsub/node_modules/
- 7-gce/node_modules/

env:
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json TEST_BUCKET_NAME=nodejs-docs-samples GCLOUD_PROJECT=nodejs-docs-samples #Other environment variables on same line

before_install:
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
mkdir -p $HOME/gcloud &&
wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz --directory-prefix=$HOME/gcloud &&
cd $HOME/gcloud &&
tar xzf google-cloud-sdk.tar.gz &&
printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh &&
source $HOME/.bashrc &&
cd $TRAVIS_BUILD_DIR;
fi
- openssl aes-256-cbc -K $encrypted_06352980ac5c_key -iv $encrypted_06352980ac5c_iv -in test/encrypted/nodejs-docs-samples.json.enc -out test/encrypted/nodejs-docs-samples.json -d
- if [ -a test/encrypted/nodejs-docs-samples.json ]; then
gcloud auth activate-service-account --key-file test/encrypted/nodejs-docs-samples.json;
fi

after_success:
- npm run coveralls
21 changes: 12 additions & 9 deletions 1-hello-world/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -25,13 +25,16 @@ app.get('/', function(req, res) {
});
// [END hello_world]

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;

// [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);
});
// [END server]
}

console.log('App listening at http://%s:%s', host, port);
});
// [END server]
module.exports = app;
2 changes: 1 addition & 1 deletion 1-hello-world/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google, Inc.
# Copyright 2015-2016, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
11 changes: 7 additions & 4 deletions 1-hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud preview app deploy app.yaml",
"lint": "jshint --exclude-path=.gitignore .",
"test": "npm run lint"
"lint": "jshint --exclude-path=../.gitignore .",
"mocha": "mocha test/*.test.js -t 30000",
"test": "npm run lint && npm run mocha"
},
"author": "Google Inc.",
"contributors": [
Expand All @@ -28,10 +29,12 @@
],
"license": "Apache Version 2.0",
"dependencies": {
"express": "^4.13.3"
"express": "^4.13.4"
},
"devDependencies": {
"jshint": "^2.9.1"
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"supertest": "^1.1.0"
},
"engines": {
"node": ">=0.12.7"
Expand Down
49 changes: 49 additions & 0 deletions 1-hello-world/test/1-hello-world.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

var assert = require('assert');
var path = require('path');
var request = require('supertest');
var utils = require('../../test/utils');

var config = {
test: '1-hello-world',
path: path.resolve(path.join(__dirname, '../')),
cmd: 'node',
args: ['app.js'],
msg: 'Hello, world!'
};

describe(config.test, function () {

it('should install dependencies', function (done) {
this.timeout(60 * 1000); // Allow 1 minute to test installation
utils.testInstallation(config, done);
});

it('should create an express app', function (done) {
request(require('../app'))
.get('/')
.expect(200)
.expect(function (response) {
assert.equal(response.text, config.msg);
})
.end(done);
});

it('should run', function (done) {
utils.testLocalApp(config, done);
});
});
17 changes: 10 additions & 7 deletions 2-structured-data/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -44,11 +44,14 @@ app.use(function(err, req, res, next) {
res.status(500).send('Something broke!');
});

if (module === require.main) {
// Start the server
var server = app.listen(config.port, function () {
var host = server.address().address;
var port = server.address().port;

// Start the server
var server = app.listen(config.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 at http://%s:%s', host, port);
});
module.exports = app;
2 changes: 1 addition & 1 deletion 2-structured-data/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, Google, Inc.
# Copyright 2015-2016, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion 2-structured-data/books/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion 2-structured-data/books/crud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion 2-structured-data/books/model-cloudsql.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
5 changes: 3 additions & 2 deletions 2-structured-data/books/model-datastore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -124,7 +124,8 @@ module.exports = function(config) {
ds.save(
entity,
function(err) {
cb(err, err ? null : fromDatastore(entity));
data.id = entity.key.id;
cb(err, err ? null : data);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion 2-structured-data/books/model-mongodb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down
4 changes: 2 additions & 2 deletions 2-structured-data/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015, Google, Inc.
// Copyright 2015-2016, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -25,7 +25,7 @@ module.exports = {

// This is the id of your project in the Google Developers Console.
gcloud: {
projectId: 'your-project-id'
projectId: process.env.GCLOUD_PROJECT || 'your-project-id'
},

mysql: {
Expand Down
13 changes: 8 additions & 5 deletions 2-structured-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"start": "node app.js",
"monitor": "nodemon app.js",
"deploy": "gcloud preview app deploy app.yaml",
"lint": "jshint --exclude-path=.gitignore .",
"test": "npm run lint",
"lint": "jshint --exclude-path=../.gitignore .",
"mocha": "mocha test/*.test.js -t 30000",
"test": "npm run lint && npm run mocha",
"init-cloudsql": "node books/model-cloudsql.js"
},
"author": "Google Inc.",
Expand All @@ -30,17 +31,19 @@
"license": "Apache Version 2.0",
"dependencies": {
"body-parser": "^1.14.2",
"express": "^4.13.3",
"express": "^4.13.4",
"gcloud": "^0.27.0",
"jade": "^1.11.0",
"kerberos": "^0.0.18",
"lodash": "^4.0.0",
"lodash": "^4.2.1",
"mongodb": "^2.1.4",
"mysql": "^2.10.2",
"prompt": "^0.2.14"
},
"devDependencies": {
"jshint": "^2.9.1"
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"supertest": "^1.1.0"
},
"engines": {
"node": ">=0.12.7"
Expand Down
Loading

0 comments on commit df3a7b6

Please sign in to comment.