Skip to content

Commit df3a7b6

Browse files
committed
Merge pull request GoogleCloudPlatform#35 from GoogleCloudPlatform/test
Added tests.
2 parents 0d14250 + 445bb39 commit df3a7b6

File tree

115 files changed

+1955
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1955
-194
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
.DS_Store
22
node_modules
3+
**/node_modules/**
34
*.log
5+
coverage/
6+
test/encrypted/nodejs-docs-samples.json
7+
*.iml
8+
.idea/

.jshintrc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
"camelcase" : true,
33
"curly": true,
44
"eqeqeq": true,
5-
"globalstrict": true,
65
"indent": 2,
76
"newcap": true,
87
"maxlen": 80,
98
"node": true,
109
"quotmark": "single",
11-
"strict": true,
10+
"strict": "global",
1211
"trailing": true,
1312
"undef": true,
14-
"unused": true
13+
"unused": true,
14+
"globals": {
15+
"after": false,
16+
"afterEach": false,
17+
"before": false,
18+
"beforeEach": false,
19+
"describe": false,
20+
"it": false
21+
}
1522
}

.travis.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
1+
# Copyright 2015-2016, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
114
sudo: false
215
language: node_js
316
node_js:
417
- "stable"
518
- "0.12"
619
- "0.10"
20+
21+
cache:
22+
directories:
23+
- $HOME/gcloud/
24+
- 1-hello-world/node_modules/
25+
- 2-structured-data/node_modules/
26+
- 3-binary-data/node_modules/
27+
- 4-auth/node_modules/
28+
- 5-logging/node_modules/
29+
- 6-pubsub/node_modules/
30+
- 7-gce/node_modules/
31+
32+
env:
33+
- 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
34+
35+
before_install:
36+
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then
37+
mkdir -p $HOME/gcloud &&
38+
wget https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz --directory-prefix=$HOME/gcloud &&
39+
cd $HOME/gcloud &&
40+
tar xzf google-cloud-sdk.tar.gz &&
41+
printf '\ny\n\ny\ny\n' | ./google-cloud-sdk/install.sh &&
42+
source $HOME/.bashrc &&
43+
cd $TRAVIS_BUILD_DIR;
44+
fi
45+
- 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
46+
- if [ -a test/encrypted/nodejs-docs-samples.json ]; then
47+
gcloud auth activate-service-account --key-file test/encrypted/nodejs-docs-samples.json;
48+
fi
49+
50+
after_success:
51+
- npm run coveralls

1-hello-world/app.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015, Google, Inc.
1+
// Copyright 2015-2016, Google, Inc.
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -25,13 +25,16 @@ app.get('/', function(req, res) {
2525
});
2626
// [END hello_world]
2727

28+
if (module === require.main) {
29+
// [START server]
30+
// Start the server
31+
var server = app.listen(process.env.PORT || 8080, function () {
32+
var host = server.address().address;
33+
var port = server.address().port;
2834

29-
// [START server]
30-
// Start the server
31-
var server = app.listen(process.env.PORT || 8080, function () {
32-
var host = server.address().address;
33-
var port = server.address().port;
35+
console.log('App listening at http://%s:%s', host, port);
36+
});
37+
// [END server]
38+
}
3439

35-
console.log('App listening at http://%s:%s', host, port);
36-
});
37-
// [END server]
40+
module.exports = app;

1-hello-world/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015, Google, Inc.
1+
# Copyright 2015-2016, Google, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at

1-hello-world/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"start": "node app.js",
99
"monitor": "nodemon app.js",
1010
"deploy": "gcloud preview app deploy app.yaml",
11-
"lint": "jshint --exclude-path=.gitignore .",
12-
"test": "npm run lint"
11+
"lint": "jshint --exclude-path=../.gitignore .",
12+
"mocha": "mocha test/*.test.js -t 30000",
13+
"test": "npm run lint && npm run mocha"
1314
},
1415
"author": "Google Inc.",
1516
"contributors": [
@@ -28,10 +29,12 @@
2829
],
2930
"license": "Apache Version 2.0",
3031
"dependencies": {
31-
"express": "^4.13.3"
32+
"express": "^4.13.4"
3233
},
3334
"devDependencies": {
34-
"jshint": "^2.9.1"
35+
"jshint": "^2.9.1",
36+
"mocha": "^2.4.5",
37+
"supertest": "^1.1.0"
3538
},
3639
"engines": {
3740
"node": ">=0.12.7"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2015-2016, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var assert = require('assert');
17+
var path = require('path');
18+
var request = require('supertest');
19+
var utils = require('../../test/utils');
20+
21+
var config = {
22+
test: '1-hello-world',
23+
path: path.resolve(path.join(__dirname, '../')),
24+
cmd: 'node',
25+
args: ['app.js'],
26+
msg: 'Hello, world!'
27+
};
28+
29+
describe(config.test, function () {
30+
31+
it('should install dependencies', function (done) {
32+
this.timeout(60 * 1000); // Allow 1 minute to test installation
33+
utils.testInstallation(config, done);
34+
});
35+
36+
it('should create an express app', function (done) {
37+
request(require('../app'))
38+
.get('/')
39+
.expect(200)
40+
.expect(function (response) {
41+
assert.equal(response.text, config.msg);
42+
})
43+
.end(done);
44+
});
45+
46+
it('should run', function (done) {
47+
utils.testLocalApp(config, done);
48+
});
49+
});

2-structured-data/app.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015, Google, Inc.
1+
// Copyright 2015-2016, Google, Inc.
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -44,11 +44,14 @@ app.use(function(err, req, res, next) {
4444
res.status(500).send('Something broke!');
4545
});
4646

47+
if (module === require.main) {
48+
// Start the server
49+
var server = app.listen(config.port, function () {
50+
var host = server.address().address;
51+
var port = server.address().port;
4752

48-
// Start the server
49-
var server = app.listen(config.port, function () {
50-
var host = server.address().address;
51-
var port = server.address().port;
53+
console.log('App listening at http://%s:%s', host, port);
54+
});
55+
}
5256

53-
console.log('App listening at http://%s:%s', host, port);
54-
});
57+
module.exports = app;

2-structured-data/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015, Google, Inc.
1+
# Copyright 2015-2016, Google, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at

2-structured-data/books/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015, Google, Inc.
1+
// Copyright 2015-2016, Google, Inc.
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at

0 commit comments

Comments
 (0)