Skip to content

Commit bf26e00

Browse files
committed
Merge pull request GoogleCloudPlatform#43 from GoogleCloudPlatform/tests
Re-organized tests. Added more tests.
2 parents 54f4f6e + 96b5d10 commit bf26e00

Some content is hidden

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

77 files changed

+2377
-713
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ cache:
3030
- 7-gce/node_modules/
3131

3232
env:
33-
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin 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#Other environment variables on same line
33+
global:
34+
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin
35+
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json
36+
- CLOUD_BUCKET=nodejs-docs-samples
37+
- GCLOUD_PROJECT=nodejs-docs-samples
38+
- OAUTH_CLIENT_ID=test-id
39+
- OAUTH_CLIENT_SECRET=test-secret
3440

3541
before_install:
3642
- if [ ! -d $HOME/gcloud/google-cloud-sdk ]; then

1-hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"monitor": "nodemon app.js",
1010
"deploy": "gcloud preview app deploy app.yaml",
1111
"lint": "jshint --exclude-path=../.gitignore .",
12-
"mocha": "mocha test/*.test.js -t 30000",
12+
"mocha": "mocha test/index.js -t 30000",
1313
"test": "npm run lint && npm run mocha"
1414
},
1515
"author": "Google Inc.",
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,14 @@
1414
'use strict';
1515

1616
var assert = require('assert');
17-
var path = require('path');
17+
var config = require('./config');
1818
var request = require('supertest');
1919
var utils = require('../../test/utils');
2020

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);
21+
describe('app.js', function () {
22+
it('should run', function (done) {
23+
utils.testLocalApp(config, done);
3424
});
35-
3625
it('should create an express app', function (done) {
3726
request(require('../app'))
3827
.get('/')
@@ -42,8 +31,4 @@ describe(config.test, function () {
4231
})
4332
.end(done);
4433
});
45-
46-
it('should run', function (done) {
47-
utils.testLocalApp(config, done);
48-
});
4934
});

1-hello-world/test/config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 path = require('path');
17+
18+
module.exports = {
19+
test: '1-hello-world',
20+
path: path.resolve(path.join(__dirname, '../')),
21+
cmd: 'node',
22+
args: ['app.js'],
23+
msg: 'Hello, world!'
24+
};

1-hello-world/test/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 config = require('./config');
17+
var utils = require('../../test/utils');
18+
19+
describe(config.test + '/', function () {
20+
it('should install dependencies', function (done) {
21+
this.timeout(60 * 1000); // Allow 1 minute to test installation
22+
utils.testInstallation(config, done);
23+
});
24+
require('./app.test');
25+
});

2-structured-data/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
var path = require('path');
1717
var express = require('express');
18-
var config = require('./config');
18+
var config = require('./config')();
1919

2020
var app = express();
2121

@@ -25,7 +25,7 @@ app.set('view engine', 'jade');
2525
app.set('trust proxy', true);
2626

2727
// Books
28-
var model = require('./books/model-' + config.dataBackend)(config);
28+
var model = require('./books/model')(config);
2929
app.use('/books', require('./books/crud')(model));
3030
app.use('/api/books', require('./books/api')(model));
3131

2-structured-data/books/model-cloudsql.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
var extend = require('lodash').assign;
1717
var mysql = require('mysql');
1818

19-
2019
module.exports = function(config) {
2120

2221
function getConnection() {
@@ -25,7 +24,6 @@ module.exports = function(config) {
2524
}, config.mysql));
2625
}
2726

28-
2927
// [START list]
3028
function list(limit, token, cb) {
3129
token = token ? parseInt(token, 10) : 0;
@@ -42,7 +40,6 @@ module.exports = function(config) {
4240
}
4341
// [END list]
4442

45-
4643
// [START create]
4744
function create(data, cb) {
4845
var connection = getConnection();
@@ -54,7 +51,6 @@ module.exports = function(config) {
5451
}
5552
// [END create]
5653

57-
5854
function read(id, cb) {
5955
var connection = getConnection();
6056
connection.query(
@@ -71,7 +67,6 @@ module.exports = function(config) {
7167
connection.end();
7268
}
7369

74-
7570
// [START update]
7671
function update(id, data, cb) {
7772
var connection = getConnection();
@@ -84,14 +79,12 @@ module.exports = function(config) {
8479
}
8580
// [END update]
8681

87-
8882
function _delete(id, cb) {
8983
var connection = getConnection();
9084
connection.query('DELETE FROM `books` WHERE `id` = ?', id, cb);
9185
connection.end();
9286
}
9387

94-
9588
return {
9689
createSchema: createSchema,
9790
list: list,
@@ -100,7 +93,6 @@ module.exports = function(config) {
10093
update: update,
10194
delete: _delete
10295
};
103-
10496
};
10597

10698

@@ -118,7 +110,6 @@ if (!module.parent) {
118110
});
119111
}
120112

121-
122113
function createSchema(config) {
123114
var connection = mysql.createConnection(extend({
124115
multipleStatements: true

2-structured-data/books/model.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 models = {
17+
cloudsql: require('./model-cloudsql'),
18+
datastore: require('./model-datastore'),
19+
mongodb: require('./model-mongodb')
20+
};
21+
22+
module.exports = function (config) {
23+
return models[config.dataBackend](config);
24+
};

2-structured-data/config.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,35 @@
1313

1414
'use strict';
1515

16-
var config = module.exports = {
17-
port: process.env.PORT || 8080,
18-
19-
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
20-
// configure the appropriate settings for each storage engine below.
21-
// If you are unsure, use datastore as it requires no additional
22-
// configuration.
23-
dataBackend: 'datastore',
24-
25-
// This is the id of your project in the Google Developers Console.
26-
gcloud: {
27-
projectId: process.env.GCLOUD_PROJECT || 'your-project-id'
28-
},
29-
30-
mysql: {
31-
user: process.env.MYSQL_USER || 'your-mysql-user',
32-
password: process.env.MYSQL_PASSWORD || 'your-mysql-password',
33-
host: process.env.MYSQL_HOST || 'your-mysql-host'
34-
},
35-
36-
mongodb: {
37-
url: process.env.MONGO_URL || 'mongodb://localhost:27017',
38-
collection: process.env.MONGO_COLLECTION || 'books'
39-
}
16+
var getConfig = module.exports = function () {
17+
return {
18+
port: process.env.PORT || 8080,
19+
20+
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
21+
// configure the appropriate settings for each storage engine below.
22+
// If you are unsure, use datastore as it requires no additional
23+
// configuration.
24+
dataBackend: process.env.BACKEND || 'datastore',
25+
26+
// This is the id of your project in the Google Developers Console.
27+
gcloud: {
28+
projectId: process.env.GCLOUD_PROJECT || 'your-project-id'
29+
},
30+
31+
mysql: {
32+
user: process.env.MYSQL_USER || 'your-mysql-user',
33+
password: process.env.MYSQL_PASSWORD || 'your-mysql-password',
34+
host: process.env.MYSQL_HOST || 'your-mysql-host'
35+
},
36+
37+
mongodb: {
38+
url: process.env.MONGO_URL || 'mongodb://localhost:27017',
39+
collection: process.env.MONGO_COLLECTION || 'books'
40+
}
41+
};
4042
};
4143

44+
var config = getConfig();
4245
var projectId = config.gcloud.projectId;
4346

4447
if (!projectId || projectId === 'your-project-id') {

2-structured-data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"monitor": "nodemon app.js",
1010
"deploy": "gcloud preview app deploy app.yaml",
1111
"lint": "jshint --exclude-path=../.gitignore .",
12-
"mocha": "mocha test/*.test.js -t 30000",
12+
"mocha": "mocha test/index.js -t 30000",
1313
"test": "npm run lint && npm run mocha",
1414
"init-cloudsql": "node books/model-cloudsql.js"
1515
},

0 commit comments

Comments
 (0)