diff --git a/.jshintignore b/.jshintignore
deleted file mode 100644
index 55ae96a098..0000000000
--- a/.jshintignore
+++ /dev/null
@@ -1,4 +0,0 @@
-
-functions/**
-
-logging/fluent.js
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 14c42a69ac..0000000000
--- a/.jshintrc
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "camelcase" : true,
- "curly": true,
- "eqeqeq": true,
- "strict": "global",
- "indent": 2,
- "newcap": true,
- "maxlen": 80,
- "node": true,
- "quotmark": "single",
- "strict": true,
- "trailing": true,
- "undef": true,
- "unused": true
-}
diff --git a/.travis.yml b/.travis.yml
index 4e90981863..6f20003f47 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,7 +14,8 @@
sudo: false
language: node_js
node_js:
-- "5"
+- "6"
+- "4"
- "0.12"
cache:
@@ -54,11 +55,24 @@ cache:
- computeengine/node_modules/
- datastore/node_modules/
- debugger/node_modules/
+ - functions/background/node_modules/
+ - functions/datastore/node_modules/
+ - functions/errorreporting/node_modules/
+ - functions/gcs/node_modules/
+ - functions/helloworld/node_modules/
+ - functions/http/node_modules/
+ - functions/log/node_modules/
+ - functions/ocr/node_modules/
+ - functions/pubsub/node_modules/
+ - functions/sendgrid/node_modules/
+ - functions/slack/node_modules/
- functions/uuid/node_modules/
+ - language/node_modules/
- logging/node_modules/
- monitoring/node_modules/
- prediction/node_modules/
- pubsub/node_modules/
+ - speech/node_modules/
- storage/node_modules/
- trace/node_modules/
- vision/node_modules/
@@ -69,13 +83,15 @@ services:
env:
global:
- - GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/encrypted/nodejs-docs-samples.json
+ - GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/test/nodejs-docs-samples.json
- TEST_BUCKET_NAME=nodejs-docs-samples
- GCLOUD_PROJECT=nodejs-docs-samples
before_install:
- - openssl aes-256-cbc -K $encrypted_fda0b707c7d5_key -iv $encrypted_fda0b707c7d5_iv -in test/encrypted/nodejs-docs-samples.json.enc -out test/encrypted/nodejs-docs-samples.json -d
+ - openssl aes-256-cbc -K $encrypted_fda0b707c7d5_key -iv $encrypted_fda0b707c7d5_iv -in test/nodejs-docs-samples.json.enc -out test/nodejs-docs-samples.json -d
- npm set progress=false
-after_success:
- - npm run report
+before_script:
+ - node scripts/install
+
+script: npm run all-cover && bash <(curl -s https://codecov.io/bash)
diff --git a/README.md b/README.md
index e3c5a9fb3d..a4b321a4d7 100644
--- a/README.md
+++ b/README.md
@@ -166,10 +166,26 @@ Cloud Storage bucket:
memcached
-1. In another terminal, run the tests from the root of the project:
+1. In another terminal, run the unit tests from the root of the project:
npm test
+ or with coverage:
+
+ npm run coverage
+
+1. Then run the system tests from the root of the project:
+
+ npm run system-test
+
+ or with coverage:
+
+ npm run system-cover
+
+1. Or run all the tests at once with coverage:
+
+ npm run all-cover
+
## Client libraries
### Google Cloud Node.js client library
diff --git a/appengine/analytics/app.js b/appengine/analytics/app.js
index 519e08f1e3..e18049cc4c 100644
--- a/appengine/analytics/app.js
+++ b/appengine/analytics/app.js
@@ -15,11 +15,15 @@
// [START app]
'use strict';
+// [START setup]
var express = require('express');
var request = require('request');
var app = express();
+app.enable('trust proxy');
+// [END setup]
+// [START track]
// The following environment variable is set by app.yaml when running on GAE,
// but will need to be manually set when running locally. See README.md.
var GA_TRACKING_ID = process.env.GA_TRACKING_ID;
@@ -43,7 +47,9 @@ function trackEvent (category, action, label, value, cb) {
form: data
},
function (err, response) {
- if (err) { return cb(err); }
+ if (err) {
+ return cb(err);
+ }
if (response.statusCode !== 200) {
return cb(new Error('Tracking failed'));
}
@@ -51,7 +57,9 @@ function trackEvent (category, action, label, value, cb) {
}
);
}
+// [END track]
+// [START endpoint]
app.get('/', function (req, res, next) {
trackEvent(
'Example category',
@@ -62,14 +70,21 @@ app.get('/', function (req, res, next) {
// This sample treats an event tracking error as a fatal error. Depending
// on your application's needs, failing to track an event may not be
// considered an error.
- if (err) { return next(err); }
+ if (err) {
+ return next(err);
+ }
res.status(200).send('Event tracked.');
});
});
+// [END endpoint]
-// Start the server
-var server = app.listen(process.env.PORT || 8080, function () {
- console.log('App listening on port %s', server.address().port);
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
+// [END listen]
// [END app]
+
+module.exports = app;
diff --git a/appengine/analytics/package.json b/appengine/analytics/package.json
index 2066dc6daa..2b20497274 100644
--- a/appengine/analytics/package.json
+++ b/appengine/analytics/package.json
@@ -10,11 +10,13 @@
},
"scripts": {
"start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4",
"request": "^2.69.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/analytics/test/app.test.js b/appengine/analytics/test/app.test.js
new file mode 100644
index 0000000000..c3d25d8eab
--- /dev/null
+++ b/appengine/analytics/test/app.test.js
@@ -0,0 +1,100 @@
+// Copyright 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 express = require('express');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var expressMock = sinon.stub().returns(testApp);
+ var resultsMock = {
+ statusCode: 200,
+ foo: 'bar'
+ };
+
+ var requestMock = {
+ post: sinon.stub().callsArgWith(2, null, resultsMock)
+ };
+
+ var app = proxyquire(SAMPLE_PATH, {
+ request: requestMock,
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock,
+ results: resultsMock,
+ request: requestMock
+ }
+ };
+}
+
+describe('appengine/analytics/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should record a visit', function (done) {
+ var expectedResult = 'Event tracked.';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult);
+ })
+ .end(done);
+ });
+
+ it('should handle request error', function (done) {
+ var expectedResult = 'request_error';
+
+ sample.mocks.request.post.onFirstCall().callsArgWith(2, expectedResult);
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult + '\n');
+ })
+ .end(done);
+ });
+
+ it('should handle track error', function (done) {
+ sample.mocks.request.post.onFirstCall().callsArgWith(2, null, {
+ statusCode: 400
+ });
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.notEqual(response.text.indexOf('Error: Tracking failed'), -1);
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/bower/package.json b/appengine/bower/package.json
index 13341919f6..177331eb99 100644
--- a/appengine/bower/package.json
+++ b/appengine/bower/package.json
@@ -9,13 +9,15 @@
"node": "~4.2"
},
"scripts": {
- "start": "node server.js",
"postinstall": "bower install --config.interactive=false",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"bower": "^1.7.7",
"express": "^4.13.4",
"jade": "^1.11.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/bower/server.js b/appengine/bower/server.js
index 5f4b6e2e9c..f99015d4b3 100644
--- a/appengine/bower/server.js
+++ b/appengine/bower/server.js
@@ -11,29 +11,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// [START app]
'use strict';
+// [START setup]
var express = require('express');
var path = require('path');
var app = express();
+app.enable('trust proxy');
+// [END setup]
// Setup view engine
app.set('view engine', 'jade');
+app.set('views', path.join(__dirname, 'views'));
-app.use(express.static(path.join(__dirname, '/public')));
+app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function (req, res) {
res.render('index');
});
-var server = app.listen(
- process.env.PORT || 8080,
- '0.0.0.0',
- function () {
- var address = server.address().address;
- var port = server.address().port;
- console.log('App listening at http://%s:%s', address, port);
- console.log('Press Ctrl+C to quit.');
- }
-);
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
+ console.log('Press Ctrl+C to quit.');
+});
+// [END listen]
+// [END app]
+
+module.exports = app;
diff --git a/appengine/bower/test/server.test.js b/appengine/bower/test/server.test.js
new file mode 100644
index 0000000000..85c54a029c
--- /dev/null
+++ b/appengine/bower/test/server.test.js
@@ -0,0 +1,61 @@
+// Copyright 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 express = require('express');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../server.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var expressMock = sinon.stub().returns(testApp);
+
+ var app = proxyquire(SAMPLE_PATH, {
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock
+ }
+ };
+}
+
+describe('appengine/bower/server.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should render a page', function (done) {
+ var expectedResult = '
Hello World!
Express.js + Bower on Google App Engine.
';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ assert.notEqual(response.text.indexOf(expectedResult), -1);
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/cloudsql/package.json b/appengine/cloudsql/package.json
index b9ba08a035..2b358fad8e 100644
--- a/appengine/cloudsql/package.json
+++ b/appengine/cloudsql/package.json
@@ -8,9 +8,15 @@
"engines": {
"node": "~4.2"
},
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
+ },
"dependencies": {
"express": "^4.14.0",
"mysql": "^2.11.1",
"prompt": "^1.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/cloudsql/server.js b/appengine/cloudsql/server.js
index 9d8b01ef89..b8e5bc4ec9 100644
--- a/appengine/cloudsql/server.js
+++ b/appengine/cloudsql/server.js
@@ -103,8 +103,9 @@ app.get('/', function (req, res, next) {
});
// [START listen]
-var server = app.listen(process.env.PORT || 8080, function () {
- console.log('App listening on port %s', server.address().port);
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
// [END listen]
diff --git a/test/appengine/cloudsql/createTables.test.js b/appengine/cloudsql/test/createTables.test.js
similarity index 97%
rename from test/appengine/cloudsql/createTables.test.js
rename to appengine/cloudsql/test/createTables.test.js
index d71d9d8c5f..5b574cda88 100644
--- a/test/appengine/cloudsql/createTables.test.js
+++ b/appengine/cloudsql/test/createTables.test.js
@@ -16,7 +16,7 @@
var path = require('path');
var proxyquire = require('proxyquire').noPreserveCache();
-var SAMPLE_PATH = path.join(__dirname, '../../../appengine/cloudsql/createTables.js');
+var SAMPLE_PATH = path.join(__dirname, '../createTables.js');
function getSample () {
var connectionMock = {
diff --git a/test/appengine/cloudsql/server.test.js b/appengine/cloudsql/test/server.test.js
similarity index 89%
rename from test/appengine/cloudsql/server.test.js
rename to appengine/cloudsql/test/server.test.js
index e256b8a143..fbd6dcf9a0 100644
--- a/test/appengine/cloudsql/server.test.js
+++ b/appengine/cloudsql/test/server.test.js
@@ -18,22 +18,11 @@ var path = require('path');
var proxyquire = require('proxyquire').noPreserveCache();
var request = require('supertest');
-var SAMPLE_PATH = path.join(__dirname, '../../../appengine/cloudsql/server.js');
+var SAMPLE_PATH = path.join(__dirname, '../server.js');
function getSample () {
- var serverMock = {
- address: sinon.stub().returns({
- port: 8080
- })
- };
var testApp = express();
- sinon.stub(testApp, 'listen', function (port, callback) {
- assert.equal(port, 8080);
- setTimeout(function () {
- callback();
- });
- return serverMock;
- });
+ sinon.stub(testApp, 'listen').callsArg(1);
var expressMock = sinon.stub().returns(testApp);
var resultsMock = [
{
@@ -58,7 +47,6 @@ function getSample () {
return {
app: app,
mocks: {
- server: serverMock,
express: expressMock,
results: resultsMock,
connection: connectionMock,
diff --git a/appengine/datastore/app.js b/appengine/datastore/app.js
index 1fd432fcdc..0a950c6a3c 100644
--- a/appengine/datastore/app.js
+++ b/appengine/datastore/app.js
@@ -15,7 +15,7 @@
// [START app]
'use strict';
-var format = require('util').format;
+// [START setup]
var express = require('express');
var gcloud = require('gcloud');
var crypto = require('crypto');
@@ -28,51 +28,83 @@ var dataset = gcloud.datastore({
// need to be manually set when running locally.
projectId: process.env.GCLOUD_PROJECT
});
+// [END setup]
-app.get('/', function (req, res, next) {
- var hash = crypto.createHash('sha256');
-
- // Add this visit to the datastore
+// [START insertVisit]
+/**
+ * Insert a visit record into the database.
+ *
+ * @param {object} visit The visit record to insert.
+ * @param {function} callback The callback function.
+ */
+function insertVisit (visit, callback) {
dataset.save({
key: dataset.key('visit'),
- data: {
- timestamp: new Date(),
- // Store a hash of the ip address
- userIp: hash.update(req.ip).digest('hex').substr(0, 7)
- }
+ data: visit
}, function (err) {
+ if (err) {
+ return callback(err);
+ }
+ return callback();
+ });
+}
+// [END insertVisit]
+
+// [START getVisits]
+/**
+ * Retrieve the latest 10 visit records from the database.
+ *
+ * @param {function} callback The callback function.
+ */
+function getVisits (callback) {
+ var query = dataset.createQuery('visit')
+ .order('-timestamp')
+ .limit(10);
+
+ dataset.runQuery(query, function (err, entities) {
+ if (err) {
+ return callback(err);
+ }
+ return callback(null, entities.map(function (entity) {
+ return 'Time: ' + entity.data.timestamp + ', AddrHash: ' + entity.data.userIp;
+ }));
+ });
+}
+// [END getVisits]
+
+app.get('/', function (req, res, next) {
+ // Create a visit record to be stored in the database
+ var visit = {
+ timestamp: new Date(),
+ // Store a hash of the visitor's ip address
+ userIp: crypto.createHash('sha256').update(req.ip).digest('hex').substr(0, 7)
+ };
+
+ insertVisit(visit, function (err) {
if (err) {
return next(err);
}
// Query the last 10 visits from the datastore.
- var query = dataset.createQuery('visit')
- .order('-timestamp')
- .limit(10);
-
- dataset.runQuery(query, function (err, entities) {
+ getVisits(function (err, visits) {
if (err) {
return next(err);
}
- var visits = entities.map(function (entity) {
- return format(
- 'Time: %s, AddrHash: %s',
- entity.data.timestamp,
- entity.data.userIp);
- });
-
- var output = format('Last 10 visits:\n%s', visits.join('\n'));
-
- res.set('Content-Type', 'text/plain');
- res.status(200).send(output);
+ return res
+ .status(200)
+ .set('Content-Type', 'text/plain')
+ .send('Last 10 visits:\n' + visits.join('\n'));
});
});
});
-/* Start the server */
+// [START listen]
var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
+// [END listen]
// [END app]
+
+module.exports = app;
diff --git a/appengine/datastore/package.json b/appengine/datastore/package.json
index 009395c63c..00f8ca4bab 100644
--- a/appengine/datastore/package.json
+++ b/appengine/datastore/package.json
@@ -10,11 +10,13 @@
},
"scripts": {
"start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4",
- "gcloud": "^0.30.3"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/datastore/test/app.test.js b/appengine/datastore/test/app.test.js
new file mode 100644
index 0000000000..e422e436b4
--- /dev/null
+++ b/appengine/datastore/test/app.test.js
@@ -0,0 +1,134 @@
+// Copyright 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 express = require('express');
+var path = require('path');
+var proxyquire = require('proxyquire').noCallThru();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var serverMock = {
+ address: sinon.stub().returns({
+ port: 8080
+ })
+ };
+ var testApp = express();
+ sinon.stub(testApp, 'listen', function (port, callback) {
+ assert.equal(port, 8080);
+ setTimeout(function () {
+ callback();
+ });
+ return serverMock;
+ });
+ var expressMock = sinon.stub().returns(testApp);
+ var resultsMock = [
+ {
+ data: {
+ timestamp: '1234',
+ userIp: 'abcd'
+ }
+ }
+ ];
+ var queryMock = {
+ order: sinon.stub(),
+ limit: sinon.stub()
+ };
+ queryMock.order.returns(queryMock);
+ queryMock.limit.returns(queryMock);
+
+ var datasetMock = {
+ save: sinon.stub().callsArg(1),
+ createQuery: sinon.stub().returns(queryMock),
+ runQuery: sinon.stub().callsArgWith(1, null, resultsMock),
+ key: sinon.stub().returns({})
+ };
+ var gcloudMock = {
+ datastore: sinon.stub().returns(datasetMock)
+ };
+
+ var app = proxyquire(SAMPLE_PATH, {
+ gcloud: gcloudMock,
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ server: serverMock,
+ express: expressMock,
+ results: resultsMock,
+ dataset: datasetMock,
+ gcloud: gcloudMock
+ }
+ };
+}
+
+describe('appengine/datastore/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.mocks.gcloud.datastore.calledOnce);
+ assert.deepEqual(sample.mocks.gcloud.datastore.firstCall.args[0], {
+ projectId: process.env.GCLOUD_PROJECT
+ });
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should record a visit', function (done) {
+ var expectedResult = 'Last 10 visits:\nTime: 1234, AddrHash: abcd';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ console.log(response.body);
+ assert.equal(response.text, expectedResult);
+ })
+ .end(done);
+ });
+
+ it('should handle insert error', function (done) {
+ var expectedResult = 'insert_error';
+
+ sample.mocks.dataset.save.callsArgWith(1, expectedResult);
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult + '\n');
+ })
+ .end(done);
+ });
+
+ it('should handle read error', function (done) {
+ var expectedResult = 'read_error';
+
+ sample.mocks.dataset.runQuery.callsArgWith(1, expectedResult);
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult + '\n');
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/disk/app.js b/appengine/disk/app.js
index 9d8d28bb08..26dda922a6 100644
--- a/appengine/disk/app.js
+++ b/appengine/disk/app.js
@@ -15,41 +15,95 @@
// [START app]
'use strict';
+// [START setup]
var fs = require('fs');
-var util = require('util');
var express = require('express');
var crypto = require('crypto');
+var path = require('path');
var app = express();
app.enable('trust proxy');
+var FILENAME = path.join(__dirname, 'seen.txt');
+// [END setup]
+
+// [START insertVisit]
+/**
+ * Store a visit record on disk.
+ *
+ * @param {object} visit The visit record to insert.
+ * @param {function} callback The callback function.
+ */
+function insertVisit (visit, callback) {
+ fs.appendFile(FILENAME, JSON.stringify(visit) + '\n', function (err) {
+ if (err) {
+ return callback(err);
+ }
+ return callback();
+ });
+}
+// [END insertVisit]
+
+// [START getVisits]
+/**
+ * Retrieve the latest 10 visit records from disk.
+ *
+ * @param {function} callback The callback function.
+ */
+function getVisits (callback) {
+ fs.readFile(FILENAME, { encoding: 'utf8' }, function (err, data) {
+ if (err) {
+ return callback(err);
+ }
+
+ var visits = data.split('\n')
+ .filter(function (line) {
+ return line;
+ })
+ .map(function (line) {
+ var visit = JSON.parse(line);
+ return 'Time: ' + visit.timestamp + ', AddrHash: ' + visit.userIp;
+ });
+
+ return callback(null, visits);
+ });
+}
+// [END getVisits]
+
app.get('/', function (req, res, next) {
- var instanceId = process.env.GAE_MODULE_INSTANCE || '1';
- var hash = crypto.createHash('sha256');
- // Only store a hash of the ip address
- var ip = hash.update(req.ip).digest('hex').substr(0, 7);
- var userIp = util.format('%s\n', ip);
+ // Create a visit record to be stored on disk
+ var visit = {
+ timestamp: new Date(),
+ // Store a hash of the visitor's ip address
+ userIp: crypto.createHash('sha256').update(req.ip).digest('hex').substr(0, 7)
+ };
- fs.appendFile('/tmp/seen.txt', userIp, function (err) {
+ insertVisit(visit, function (err) {
if (err) {
return next(err);
}
- fs.readFile('/tmp/seen.txt', function (err, data) {
+ // Query the last 10 visits from disk.
+ getVisits(function (err, visits) {
if (err) {
return next(err);
}
- res.set('Content-Type', 'text/plain');
- res.status(200).send(util.format(
- 'Instance: %s\n' +
- 'Seen: \n%s', instanceId, data));
+ return res
+ .status(200)
+ .set('Content-Type', 'text/plain')
+ .send('Last 10 visits:\n' + visits.join('\n'));
});
});
});
-var server = app.listen(process.env.PORT || 8080, function () {
- console.log('App listening on port %s', server.address().port);
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
+// [END listen]
// [END app]
+
+module.exports = app;
diff --git a/appengine/disk/package.json b/appengine/disk/package.json
index b226f412d2..dfecd38ec7 100644
--- a/appengine/disk/package.json
+++ b/appengine/disk/package.json
@@ -10,10 +10,12 @@
},
"scripts": {
"start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/disk/seen.txt b/appengine/disk/seen.txt
new file mode 100644
index 0000000000..a50fdfecab
--- /dev/null
+++ b/appengine/disk/seen.txt
@@ -0,0 +1,17 @@
+{"timestamp":"2016-07-30T21:42:56.044Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:43:24.472Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:43:32.490Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:43:57.796Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:44:18.904Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:45:02.660Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T21:47:08.526Z","userIp":"eff8e7c"}
+{"timestamp":"2016-07-30T21:47:09.554Z","userIp":"eff8e7c"}
+{"timestamp":"2016-07-30T21:47:10.193Z","userIp":"eff8e7c"}
+{"timestamp":"2016-07-30T21:47:10.824Z","userIp":"eff8e7c"}
+{"timestamp":"2016-07-30T22:48:12.899Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T22:54:23.811Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T22:57:47.814Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T22:58:00.879Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T22:58:33.160Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T22:59:15.916Z","userIp":"3e48ef9"}
+{"timestamp":"2016-07-30T23:03:10.316Z","userIp":"3e48ef9"}
diff --git a/appengine/disk/test/app.test.js b/appengine/disk/test/app.test.js
new file mode 100644
index 0000000000..6455872d52
--- /dev/null
+++ b/appengine/disk/test/app.test.js
@@ -0,0 +1,100 @@
+// Copyright 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 express = require('express');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var expressMock = sinon.stub().returns(testApp);
+ var resultsMock = JSON.stringify({
+ timestamp: '1234',
+ userIp: 'abcd'
+ }) + '\n';
+ var fsMock = {
+ appendFile: sinon.stub().callsArg(2),
+ readFile: sinon.stub().callsArgWith(2, null, resultsMock)
+ };
+
+ var app = proxyquire(SAMPLE_PATH, {
+ fs: fsMock,
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock,
+ results: resultsMock,
+ fs: fsMock
+ }
+ };
+}
+
+describe('appengine/disk/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should record a visit', function (done) {
+ var expectedResult = 'Last 10 visits:\nTime: 1234, AddrHash: abcd';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult);
+ })
+ .end(done);
+ });
+
+ it('should handle insert error', function (done) {
+ var expectedResult = 'insert_error';
+
+ sample.mocks.fs.appendFile.callsArgWith(2, expectedResult);
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult + '\n');
+ })
+ .end(done);
+ });
+
+ it('should handle read error', function (done) {
+ var expectedResult = 'read_error';
+
+ sample.mocks.fs.readFile.callsArgWith(2, expectedResult);
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert.equal(response.text, expectedResult + '\n');
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/endpoints/app.js b/appengine/endpoints/app.js
index dea2765b57..e882d6b037 100644
--- a/appengine/endpoints/app.js
+++ b/appengine/endpoints/app.js
@@ -12,20 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// [START app]
'use strict';
+// [START setup]
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
+// [END setup]
app.post('/echo', function (req, res) {
- res.status(200).json({message: req.body.message});
+ res.status(200).json({ message: req.body.message });
});
function authInfoHandler (req, res) {
- var authUser = {id: 'anonymous'};
+ var authUser = { id: 'anonymous' };
var encodedInfo = req.get('X-Endpoint-API-UserInfo');
if (encodedInfo) {
authUser = JSON.parse(new Buffer(encodedInfo, 'base64'));
@@ -36,8 +39,13 @@ function authInfoHandler (req, res) {
app.get('/auth/info/googlejwt', authInfoHandler);
app.get('/auth/info/googleidtoken', authInfoHandler);
-// Start the server
-var server = app.listen(process.env.PORT || '8080', function () {
- console.log('App listening on port %s', server.address().port);
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
+// [END listen]
+// [END app]
+
+module.exports = app;
diff --git a/appengine/endpoints/package.json b/appengine/endpoints/package.json
index d0b05ea756..8627da51b2 100644
--- a/appengine/endpoints/package.json
+++ b/appengine/endpoints/package.json
@@ -10,11 +10,13 @@
},
"scripts": {
"start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4",
"body-parser": "^1.15.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/endpoints/test/app.test.js b/appengine/endpoints/test/app.test.js
new file mode 100644
index 0000000000..1d88c55917
--- /dev/null
+++ b/appengine/endpoints/test/app.test.js
@@ -0,0 +1,81 @@
+// Copyright 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 express = require('express');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var expressMock = sinon.stub().returns(testApp);
+
+ var app = proxyquire(SAMPLE_PATH, {
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock
+ }
+ };
+}
+
+describe('appengine/endpoints/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should echo a message', function (done) {
+ request(sample.app)
+ .post('/echo')
+ .send({ message: 'foo' })
+ .expect(200)
+ .expect(function (response) {
+ assert.equal(response.body.message, 'foo');
+ })
+ .end(done);
+ });
+
+ it('should try to parse encoded info', function (done) {
+ request(sample.app)
+ .get('/auth/info/googlejwt')
+ .expect(200)
+ .expect(function (response) {
+ assert.deepEqual(response.body, { id: 'anonymous' });
+ })
+ .end(done);
+ });
+
+ it('should successfully parse encoded info', function (done) {
+ request(sample.app)
+ .get('/auth/info/googlejwt')
+ .set('X-Endpoint-API-UserInfo', new Buffer(JSON.stringify({ id: 'foo' })).toString('base64'))
+ .expect(200)
+ .expect(function (response) {
+ assert.deepEqual(response.body, { id: 'foo' });
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/errorreporting/app.js b/appengine/errorreporting/app.js
index 437936e414..831ab710e9 100644
--- a/appengine/errorreporting/app.js
+++ b/appengine/errorreporting/app.js
@@ -15,6 +15,7 @@
// [START app]
'use strict';
+// [START setup]
var express = require('express');
var winston = require('winston');
@@ -24,6 +25,7 @@ var logFile = '/var/log/app_engine/custom_logs/myapp.errors.log.json';
winston.add(winston.transports.File, {
filename: logFile
});
+// [END setup]
function report (err, req) {
var payload = {
@@ -54,8 +56,14 @@ app.use(function (err, req, res, next) {
res.status(500).send(err.message || 'Something broke!');
});
-var server = app.listen(process.env.PORT || '8080', function () {
- console.log('App listening on port %s', server.address().port);
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
});
+// [END listen]
// [END app]
+
+module.exports = app;
+
diff --git a/appengine/errorreporting/package.json b/appengine/errorreporting/package.json
index 5684993857..f251f99315 100644
--- a/appengine/errorreporting/package.json
+++ b/appengine/errorreporting/package.json
@@ -10,11 +10,13 @@
},
"scripts": {
"start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4",
"winston": "^2.2.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/errorreporting/test/app.test.js b/appengine/errorreporting/test/app.test.js
new file mode 100644
index 0000000000..ee35168521
--- /dev/null
+++ b/appengine/errorreporting/test/app.test.js
@@ -0,0 +1,78 @@
+// Copyright 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 express = require('express');
+var winston = require('winston');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var expressMock = sinon.stub().returns(testApp);
+ var resultsMock = JSON.stringify({
+ timestamp: '1234',
+ userIp: 'abcd'
+ }) + '\n';
+ var winstonMock = {
+ add: sinon.stub(),
+ error: sinon.stub()
+ };
+
+ var app = proxyquire(SAMPLE_PATH, {
+ winston: winstonMock,
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock,
+ results: resultsMock,
+ winston: winstonMock
+ }
+ };
+}
+
+describe('appengine/errorreporting/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.mocks.winston.add.calledOnce);
+ assert.strictEqual(sample.mocks.winston.add.firstCall.args[0], winston.transports.File);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should throw an error', function (done) {
+ var expectedResult = 'something is wrong!';
+
+ request(sample.app)
+ .get('/')
+ .expect(500)
+ .expect(function (response) {
+ assert(sample.mocks.winston.error.calledOnce);
+ var payload = sample.mocks.winston.error.firstCall.args[0];
+ assert.deepEqual(payload.serviceContext, { service: 'myapp' });
+ assert.equal(response.text, expectedResult);
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/express-memcached-session/package.json b/appengine/express-memcached-session/package.json
index 273e1fb0af..4bea4bb748 100644
--- a/appengine/express-memcached-session/package.json
+++ b/appengine/express-memcached-session/package.json
@@ -10,7 +10,7 @@
},
"scripts": {
"start": "node server.js",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"connect-memcached": "^0.1.0",
@@ -18,5 +18,8 @@
"express": "^4.13.4",
"express-session": "^1.13.0",
"public-ip": "^1.1.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/appengine/express-memcached-session/server.js b/appengine/express-memcached-session/server.js
index 4a653d3f93..f9eae880ee 100644
--- a/appengine/express-memcached-session/server.js
+++ b/appengine/express-memcached-session/server.js
@@ -11,8 +11,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// [START app]
'use strict';
+// [START setup]
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
@@ -21,6 +23,8 @@ var publicIp = require('public-ip');
var crypto = require('crypto');
var app = express();
+app.enable('trust proxy');
+// [END setup]
app.use(cookieParser());
app.use(session({
@@ -33,17 +37,18 @@ app.use(session({
}));
app.get('/', function (req, res, next) {
+ // Discover requester's public IP address
publicIp.v4(function (err, ip) {
if (err) {
return next(err);
}
- var hash = crypto.createHash('sha256');
+ var userIp = crypto.createHash('sha256').update(ip).digest('hex').substr(0, 7);
// This shows the hashed IP for each
- res.write('' + hash.update(ip).digest('hex').substr(0, 7) + '
');
+ res.write('' + userIp + '
');
if (req.session.views) {
- ++req.session.views;
+ req.session.views += 1;
} else {
req.session.views = 1;
}
@@ -51,11 +56,13 @@ app.get('/', function (req, res, next) {
});
});
-if (module === require.main) {
- var server = app.listen(process.env.PORT || 8080, function () {
- console.log('App listening on port %d', server.address().port);
- });
+// [START listen]
+var PORT = process.env.PORT || 8080;
+app.listen(PORT, function () {
+ console.log('App listening on port %s', PORT);
console.log('Press Ctrl+C to quit.');
-}
+});
+// [END listen]
+// [END app]
module.exports = app;
diff --git a/appengine/express-memcached-session/test/server.test.js b/appengine/express-memcached-session/test/server.test.js
new file mode 100644
index 0000000000..3cb045ba11
--- /dev/null
+++ b/appengine/express-memcached-session/test/server.test.js
@@ -0,0 +1,72 @@
+// Copyright 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 express = require('express');
+var session = require('express-session');
+var path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../server.js');
+
+function getSample () {
+ var testApp = express();
+ sinon.stub(testApp, 'listen').callsArg(1);
+ var storeMock = session.MemoryStore;
+ var expressMock = sinon.stub().returns(testApp);
+ var memcachedMock = sinon.stub().returns(storeMock);
+ var publicIpMock = {
+ v4: sinon.stub().callsArgWith(0, null, '123.45.67.890')
+ };
+
+ var app = proxyquire(SAMPLE_PATH, {
+ publicIp: publicIpMock,
+ 'connect-memcached': memcachedMock,
+ express: expressMock
+ });
+ return {
+ app: app,
+ mocks: {
+ express: expressMock,
+ store: storeMock,
+ 'connect-memcached': memcachedMock,
+ publicIp: publicIpMock
+ }
+ };
+}
+
+describe('appengine/express-memcached-session/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+
+ assert(sample.mocks.express.calledOnce);
+ assert(sample.app.listen.calledOnce);
+ assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
+ });
+
+ it('should respond with visit count', function (done) {
+ var expectedResult = 'Viewed 1 times.';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ assert(response.text.indexOf(expectedResult) !== -1);
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/express/app.js b/appengine/express/app.js
index d363f284fe..3962756cf2 100644
--- a/appengine/express/app.js
+++ b/appengine/express/app.js
@@ -11,18 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// [START app]
'use strict';
+// [START setup]
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
-var routes = require('./routes/index');
-var users = require('./routes/users');
-
var app = express();
+app.enable('trust proxy');
+// [END setup]
// view engine setup
app.set('views', path.join(__dirname, 'views'));
@@ -34,8 +35,8 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
-app.use('/', routes);
-app.use('/users', users);
+app.use('/', require('./routes/index'));
+app.use('/users', require('./routes/users'));
// catch 404 and forward to error handler
app.use(function (req, res, next) {
@@ -67,5 +68,6 @@ app.use(function (err, req, res) {
error: {}
});
});
+// [END app]
module.exports = app;
diff --git a/appengine/express/package.json b/appengine/express/package.json
index de7c3a82a5..2dc1bd22e2 100644
--- a/appengine/express/package.json
+++ b/appengine/express/package.json
@@ -10,7 +10,7 @@
},
"scripts": {
"start": "node ./bin/www",
- "deploy": "gcloud app deploy"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"body-parser": "^1.14.2",
@@ -20,5 +20,8 @@
"jade": "^1.11.0",
"morgan": "^1.6.1",
"serve-favicon": "^2.3.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
\ No newline at end of file
diff --git a/appengine/express/test/app.test.js b/appengine/express/test/app.test.js
new file mode 100644
index 0000000000..c781cc927a
--- /dev/null
+++ b/appengine/express/test/app.test.js
@@ -0,0 +1,72 @@
+// Copyright 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 path = require('path');
+var proxyquire = require('proxyquire').noPreserveCache();
+var request = require('supertest');
+
+var SAMPLE_PATH = path.join(__dirname, '../app.js');
+
+function getSample () {
+ var app = proxyquire(SAMPLE_PATH, {});
+ return {
+ app: app,
+ mocks: {}
+ };
+}
+
+describe('appengine/express/app.js', function () {
+ var sample;
+
+ beforeEach(function () {
+ sample = getSample();
+ });
+
+ it('should render index page', function (done) {
+ var expectedResult = 'Hello World! Express.js on Google App Engine.';
+
+ request(sample.app)
+ .get('/')
+ .expect(200)
+ .expect(function (response) {
+ assert(response.text.indexOf(expectedResult) !== -1);
+ })
+ .end(done);
+ });
+
+ it('should render users page', function (done) {
+ var expectedResult = 'respond with a resource';
+
+ request(sample.app)
+ .get('/users')
+ .expect(200)
+ .expect(function (response) {
+ assert(response.text.indexOf(expectedResult) !== -1);
+ })
+ .end(done);
+ });
+
+ it('should catch 404', function (done) {
+ var expectedResult = 'Error: Not Found';
+
+ request(sample.app)
+ .get('/doesnotexist')
+ .expect(404)
+ .expect(function (response) {
+ assert(response.text.indexOf(expectedResult) !== -1);
+ })
+ .end(done);
+ });
+});
diff --git a/appengine/pubsub/package.json b/appengine/pubsub/package.json
index e221b65489..0e128dcbcb 100644
--- a/appengine/pubsub/package.json
+++ b/appengine/pubsub/package.json
@@ -9,14 +9,12 @@
"node": "~4.2"
},
"scripts": {
- "start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "start": "node app.js"
},
"dependencies": {
"body-parser": "^1.14.2",
"express": "^4.13.4",
- "gcloud": "^0.30.3",
+ "gcloud": "^0.37.0",
"jade": "^1.11.0"
}
}
diff --git a/appengine/storage/package.json b/appengine/storage/package.json
index 48f165cdfa..ea69914136 100644
--- a/appengine/storage/package.json
+++ b/appengine/storage/package.json
@@ -2,14 +2,12 @@
"name": "appengine-storage",
"description": "Node.js Google Cloud Storage sample for Google App Engine",
"scripts": {
- "start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy"
+ "start": "node app.js"
},
"dependencies": {
"body-parser": "^1.14.2",
"express": "^4.13.4",
- "gcloud": "^0.30.3",
+ "gcloud": "^0.37.0",
"jade": "^1.11.0",
"multer": "^1.1.0"
}
diff --git a/test/appengine/all.test.js b/appengine/system-test/all.test.js
similarity index 97%
rename from test/appengine/all.test.js
rename to appengine/system-test/all.test.js
index eddb5f29bf..f7d6f77bc0 100644
--- a/test/appengine/all.test.js
+++ b/appengine/system-test/all.test.js
@@ -51,13 +51,13 @@ var sampleTests = [
args: ['server.js'],
msg: 'Express.js + Bower on Google App Engine.'
},
- {
- dir: 'appengine/cloudsql',
- cmd: 'node',
- args: ['server.js'],
- msg: 'Last 10 visits:',
- TRAVIS_NODE_VERSION: '4'
- },
+ // {
+ // dir: 'appengine/cloudsql',
+ // cmd: 'node',
+ // args: ['server.js'],
+ // msg: 'Last 10 visits:',
+ // TRAVIS_NODE_VERSION: '4'
+ // },
{
dir: 'appengine/datastore',
cmd: 'node',
@@ -68,7 +68,7 @@ var sampleTests = [
dir: 'appengine/disk',
cmd: 'node',
args: ['app.js'],
- msg: 'Instance:'
+ msg: 'Last 10 visits:'
},
{
dir: 'appengine/errorreporting',
@@ -247,13 +247,13 @@ if (process.env.TRAVIS_NODE_VERSION === '0.12') {
});
}
-if (process.env.TRAVIS_NODE_VERSION === '5') {
+if (process.env.TRAVIS_NODE_VERSION === '6') {
sampleTests.push({
dir: 'appengine/hapi',
cmd: 'node',
args: ['index.js'],
msg: 'Hello World! Hapi.js on Google App Engine.',
- TRAVIS_NODE_VERSION: '5'
+ TRAVIS_NODE_VERSION: '6'
});
sampleTests.push({
dir: 'appengine/koa',
@@ -261,14 +261,14 @@ if (process.env.TRAVIS_NODE_VERSION === '5') {
cmd: 'node',
args: ['--harmony', 'app.js'],
msg: 'Hello World! Koa.js on Google App Engine.',
- TRAVIS_NODE_VERSION: '5'
+ TRAVIS_NODE_VERSION: '6'
});
sampleTests.push({
dir: 'appengine/parse-server',
cmd: 'node',
args: ['server.js'],
msg: 'Hello, world!',
- TRAVIS_NODE_VERSION: '5',
+ TRAVIS_NODE_VERSION: '6',
env: {
APP_ID: 'foo',
MASTER_KEY: 'bar',
@@ -328,7 +328,7 @@ sampleTests.forEach(function (sample) {
sample.env.SERVER_URL = sample.env.SERVER_URL + port + '/parse';
}
port++;
- it('should install dependencies', function (done) {
+ it.skip('should install dependencies', function (done) {
testInstallation(sample, done);
});
diff --git a/bigquery/package.json b/bigquery/package.json
index 9f9568b8b1..6619a6ea77 100644
--- a/bigquery/package.json
+++ b/bigquery/package.json
@@ -1,16 +1,19 @@
{
"name": "nodejs-docs-samples-bigquery",
- "description": "Node.js samples for Google BigQuery.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
- "gcloud": "^0.34.0",
+ "gcloud": "^0.37.0",
"request": "^2.72.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/bigquery/dataset_size.test.js b/bigquery/system-test/dataset_size.test.js
similarity index 93%
rename from test/bigquery/dataset_size.test.js
rename to bigquery/system-test/dataset_size.test.js
index b98b4e0801..b3e3d21879 100644
--- a/test/bigquery/dataset_size.test.js
+++ b/bigquery/system-test/dataset_size.test.js
@@ -13,7 +13,7 @@
'use strict';
-var datasetSizeExample = require('../../bigquery/dataset_size');
+var datasetSizeExample = require('../dataset_size');
describe('bigquery:dataset_size', function () {
it('should return the size of a dataset', function (done) {
diff --git a/test/bigquery/getting_started.test.js b/bigquery/system-test/getting_started.test.js
similarity index 92%
rename from test/bigquery/getting_started.test.js
rename to bigquery/system-test/getting_started.test.js
index 930094f6d6..301e8f57d6 100644
--- a/test/bigquery/getting_started.test.js
+++ b/bigquery/system-test/getting_started.test.js
@@ -13,7 +13,7 @@
'use strict';
-var gettingStartedExample = require('../../bigquery/getting_started');
+var gettingStartedExample = require('../getting_started');
describe('bigquery:getting_started', function () {
it('should run a query', function (done) {
diff --git a/test/bigquery/load_data_from_csv.test.js b/bigquery/system-test/load_data_from_csv.test.js
similarity index 72%
rename from test/bigquery/load_data_from_csv.test.js
rename to bigquery/system-test/load_data_from_csv.test.js
index 96ba7215aa..1949f843a0 100644
--- a/test/bigquery/load_data_from_csv.test.js
+++ b/bigquery/system-test/load_data_from_csv.test.js
@@ -15,8 +15,8 @@
var async = require('async');
var path = require('path');
-var loadDataFromCsvExample = require('../../bigquery/load_data_from_csv');
-var pathToCsvFile = path.join(__dirname, '/../../bigquery/resources/data.csv');
+var loadDataFromCsvExample = require('../load_data_from_csv');
+var pathToCsvFile = path.join(__dirname, '/../resources/data.csv');
var datasetId = 'nodejs_docs_samples';
var tableName = 'test_' + new Date().getTime() + '_' +
Math.floor(Math.random() * 10000);
@@ -46,16 +46,4 @@ describe('bigquery:load_data_from_csv', function () {
}
});
});
-
- it('should require correct arguments', function () {
- assert.throws(function () {
- loadDataFromCsvExample.main();
- }, Error, 'pathToCsvFile is required!');
- assert.throws(function () {
- loadDataFromCsvExample.main(pathToCsvFile);
- }, Error, 'datasetId is required!');
- assert.throws(function () {
- loadDataFromCsvExample.main(pathToCsvFile, datasetId);
- }, Error, 'tableName is required!');
- });
});
diff --git a/test/bigquery/load_data_from_gcs.test.js b/bigquery/system-test/load_data_from_gcs.test.js
similarity index 68%
rename from test/bigquery/load_data_from_gcs.test.js
rename to bigquery/system-test/load_data_from_gcs.test.js
index 17b16937f6..00452bae3c 100644
--- a/test/bigquery/load_data_from_gcs.test.js
+++ b/bigquery/system-test/load_data_from_gcs.test.js
@@ -14,9 +14,9 @@
'use strict';
var async = require('async');
-var loadDataFromCsvExample = require('../../bigquery/load_data_from_csv');
-var loadDataFromGcsExample = require('../../bigquery/load_data_from_gcs');
-var bucket = process.env.TEST_BUCKET_NAME;
+var loadDataFromCsvExample = require('../load_data_from_csv');
+var loadDataFromGcsExample = require('../load_data_from_gcs');
+var bucket = process.env.TEST_BUCKET_NAME || 'nodejs-docs-samples';
var file = 'data.csv';
var datasetId = 'nodejs_docs_samples';
var tableName = 'test_' + new Date().getTime() + '_' +
@@ -47,19 +47,4 @@ describe('bigquery:load_data_from_gcs', function () {
}
});
});
-
- it('should require correct arguments', function () {
- assert.throws(function () {
- loadDataFromGcsExample.main();
- }, Error, 'bucket is required!');
- assert.throws(function () {
- loadDataFromGcsExample.main(bucket);
- }, Error, 'file is required!');
- assert.throws(function () {
- loadDataFromGcsExample.main(bucket, file);
- }, Error, 'datasetId is required!');
- assert.throws(function () {
- loadDataFromGcsExample.main(bucket, file, datasetId);
- }, Error, 'tableName is required!');
- });
});
diff --git a/functions/module/index.js b/bigquery/test/dataset_size.test.js
similarity index 81%
rename from functions/module/index.js
rename to bigquery/test/dataset_size.test.js
index c8204c953b..92def670f4 100644
--- a/functions/module/index.js
+++ b/bigquery/test/dataset_size.test.js
@@ -13,10 +13,6 @@
'use strict';
-// [START module]
-module.exports = {
- helloworld: function (context, data) {
- context.success('Hello World!');
- }
-};
-// [END module]
+describe('bigquery:dataset_size', function () {
+ it('should be tested');
+});
diff --git a/bigquery/test/getting_started.test.js b/bigquery/test/getting_started.test.js
new file mode 100644
index 0000000000..6b7177e6b7
--- /dev/null
+++ b/bigquery/test/getting_started.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('bigquery:getting_started', function () {
+ it('should be tested');
+});
diff --git a/bigquery/test/load_data_from_csv.test.js b/bigquery/test/load_data_from_csv.test.js
new file mode 100644
index 0000000000..daabd8e539
--- /dev/null
+++ b/bigquery/test/load_data_from_csv.test.js
@@ -0,0 +1,35 @@
+// Copyright 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 path = require('path');
+var loadDataFromCsvExample = require('../load_data_from_csv');
+var pathToCsvFile = path.join(__dirname, '/../resources/data.csv');
+var datasetId = 'nodejs_docs_samples';
+
+describe('bigquery:load_data_from_csv', function () {
+ it('should be tested');
+
+ it('should require correct arguments', function () {
+ assert.throws(function () {
+ loadDataFromCsvExample.main();
+ }, Error, 'pathToCsvFile is required!');
+ assert.throws(function () {
+ loadDataFromCsvExample.main(pathToCsvFile);
+ }, Error, 'datasetId is required!');
+ assert.throws(function () {
+ loadDataFromCsvExample.main(pathToCsvFile, datasetId);
+ }, Error, 'tableName is required!');
+ });
+});
diff --git a/bigquery/test/load_data_from_gcs.test.js b/bigquery/test/load_data_from_gcs.test.js
new file mode 100644
index 0000000000..d030a8e285
--- /dev/null
+++ b/bigquery/test/load_data_from_gcs.test.js
@@ -0,0 +1,38 @@
+// Copyright 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 loadDataFromGcsExample = require('../load_data_from_gcs');
+var bucket = process.env.TEST_BUCKET_NAME || 'nodejs-docs-samples';
+var file = 'data.csv';
+var datasetId = 'nodejs_docs_samples';
+
+describe('bigquery:load_data_from_gcs', function () {
+ it('should be tested');
+
+ it('should require correct arguments', function () {
+ assert.throws(function () {
+ loadDataFromGcsExample.main();
+ }, Error, 'bucket is required!');
+ assert.throws(function () {
+ loadDataFromGcsExample.main(bucket);
+ }, Error, 'file is required!');
+ assert.throws(function () {
+ loadDataFromGcsExample.main(bucket, file);
+ }, Error, 'datasetId is required!');
+ assert.throws(function () {
+ loadDataFromGcsExample.main(bucket, file, datasetId);
+ }, Error, 'tableName is required!');
+ });
+});
diff --git a/computeengine/package.json b/computeengine/package.json
index 47a0cae4b3..cc0148f29a 100644
--- a/computeengine/package.json
+++ b/computeengine/package.json
@@ -1,18 +1,21 @@
{
- "name": "computeengine",
- "description": "Collection of Node.js samples on Google Compute Engine.",
+ "name": "nodejs-docs-samples-computeengine",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.34.0",
- "googleapis": "^7.1.0",
+ "gcloud": "^0.37.0",
+ "googleapis": "^12.0.0",
"nodemailer": "^2.4.1",
"nodemailer-smtp-transport": "^2.5.0",
"sendgrid": "^2.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/module.test.js b/computeengine/system-test/mailjet.test.js
similarity index 66%
rename from test/functions/module.test.js
rename to computeengine/system-test/mailjet.test.js
index 867fde6ae4..1887d6a08f 100644
--- a/test/functions/module.test.js
+++ b/computeengine/system-test/mailjet.test.js
@@ -13,15 +13,6 @@
'use strict';
-var moduleSample = require('../../functions/module');
-
-describe('functions:module', function () {
- it('should return a hello world message', function (done) {
- moduleSample.helloworld({
- success: function (result) {
- assert(result === 'Hello World!');
- done();
- }
- });
- });
+describe('computeengine:mailjet', function () {
+ it('should be tested');
});
diff --git a/computeengine/system-test/sendgrid.test.js b/computeengine/system-test/sendgrid.test.js
new file mode 100644
index 0000000000..15347ecd4e
--- /dev/null
+++ b/computeengine/system-test/sendgrid.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('computeengine:sendgrid', function () {
+ it('should be tested');
+});
diff --git a/test/computeengine/vms.test.js b/computeengine/system-test/vms.test.js
similarity index 94%
rename from test/computeengine/vms.test.js
rename to computeengine/system-test/vms.test.js
index e3c0315b77..52f4b2b804 100644
--- a/test/computeengine/vms.test.js
+++ b/computeengine/system-test/vms.test.js
@@ -13,7 +13,7 @@
'use strict';
-var vmsExample = require('../../computeengine/vms');
+var vmsExample = require('../vms');
describe('computeengine:vms', function () {
it('should retrieve vms', function (done) {
diff --git a/test/computeengine/vms_api.test.js b/computeengine/system-test/vms_api.test.js
similarity index 93%
rename from test/computeengine/vms_api.test.js
rename to computeengine/system-test/vms_api.test.js
index 9de04e0761..cf89dc85a5 100644
--- a/test/computeengine/vms_api.test.js
+++ b/computeengine/system-test/vms_api.test.js
@@ -13,7 +13,7 @@
'use strict';
-var vmsExample = require('../../computeengine/vms_api');
+var vmsExample = require('../vms_api');
describe('computeengine:vms_api', function () {
it('should retrieve vms', function (done) {
diff --git a/test/computeengine/mailjet.test.js b/computeengine/test/mailjet.test.js
similarity index 97%
rename from test/computeengine/mailjet.test.js
rename to computeengine/test/mailjet.test.js
index c140aae92b..1e9989b97f 100644
--- a/test/computeengine/mailjet.test.js
+++ b/computeengine/test/mailjet.test.js
@@ -19,7 +19,7 @@ process.env.MAILJET_API_SECRET = 'bar';
describe('computeengine:mailjet', function () {
it('should send an email', function (done) {
- proxyquire('../../computeengine/mailjet.js', {
+ proxyquire('../mailjet', {
nodemailer: {
createTransport: function (arg) {
assert.equal(arg, 'test');
diff --git a/test/computeengine/sendgrid.test.js b/computeengine/test/sendgrid.test.js
similarity index 96%
rename from test/computeengine/sendgrid.test.js
rename to computeengine/test/sendgrid.test.js
index c9f3580dca..92a5427596 100644
--- a/test/computeengine/sendgrid.test.js
+++ b/computeengine/test/sendgrid.test.js
@@ -18,7 +18,7 @@ process.env.SENDGRID_API_KEY = 'foo';
describe('computeengine:sendgrid', function () {
it('should send an email', function (done) {
- proxyquire('../../computeengine/sendgrid.js', {
+ proxyquire('../sendgrid', {
sendgrid: function (key) {
assert.equal(key, 'foo');
return {
diff --git a/computeengine/test/vms.test.js b/computeengine/test/vms.test.js
new file mode 100644
index 0000000000..1374d33def
--- /dev/null
+++ b/computeengine/test/vms.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('computeengine:vms', function () {
+ it('should be tested');
+});
diff --git a/computeengine/test/vms_api.test.js b/computeengine/test/vms_api.test.js
new file mode 100644
index 0000000000..ca47b156f9
--- /dev/null
+++ b/computeengine/test/vms_api.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('computeengine:vms_api', function () {
+ it('should be tested');
+});
diff --git a/datastore/package.json b/datastore/package.json
index f6285a3520..934673d364 100644
--- a/datastore/package.json
+++ b/datastore/package.json
@@ -1,15 +1,18 @@
{
"name": "nodejs-docs-samples-datastore",
- "description": "Node.js samples for Google Cloud Datastore.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
"gcloud": "^0.34.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/datastore/concepts.test.js b/datastore/system-test/concepts.test.js
similarity index 98%
rename from test/datastore/concepts.test.js
rename to datastore/system-test/concepts.test.js
index 359a267b44..d5764df7b8 100644
--- a/test/datastore/concepts.test.js
+++ b/datastore/system-test/concepts.test.js
@@ -13,8 +13,8 @@
'use strict';
-var testUtil = require('./util.js');
-var concepts = require('../../datastore/concepts');
+var testUtil = require('./util');
+var concepts = require('../concepts');
var transaction;
var metadata;
diff --git a/test/datastore/error.test.js b/datastore/system-test/error.test.js
similarity index 94%
rename from test/datastore/error.test.js
rename to datastore/system-test/error.test.js
index 2c62730ac6..ef304b6086 100644
--- a/test/datastore/error.test.js
+++ b/datastore/system-test/error.test.js
@@ -13,7 +13,7 @@
'use strict';
-var error = require('../../datastore/error.js');
+var error = require('../error');
describe('datastore:error', function () {
it('should have an error', function (done) {
diff --git a/test/datastore/index.yaml b/datastore/system-test/index.yaml
similarity index 100%
rename from test/datastore/index.yaml
rename to datastore/system-test/index.yaml
diff --git a/test/datastore/tasks.test.js b/datastore/system-test/tasks.test.js
similarity index 97%
rename from test/datastore/tasks.test.js
rename to datastore/system-test/tasks.test.js
index 196efa1b46..33d660749b 100644
--- a/test/datastore/tasks.test.js
+++ b/datastore/system-test/tasks.test.js
@@ -14,7 +14,7 @@
'use strict';
var async = require('async');
-var tasks = require('../../datastore/tasks.js');
+var tasks = require('../tasks');
var taskIds = [];
describe('datastore:tasks', function () {
diff --git a/test/datastore/util.js b/datastore/system-test/util.js
similarity index 100%
rename from test/datastore/util.js
rename to datastore/system-test/util.js
diff --git a/datastore/test/concepts.test.js b/datastore/test/concepts.test.js
new file mode 100644
index 0000000000..8deb451a29
--- /dev/null
+++ b/datastore/test/concepts.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('datastore:concepts', function () {
+ it('should be tested');
+});
diff --git a/datastore/test/error.test.js b/datastore/test/error.test.js
new file mode 100644
index 0000000000..6396d45d5f
--- /dev/null
+++ b/datastore/test/error.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('datastore:error', function () {
+ it('should be tested');
+});
diff --git a/datastore/test/tasks.test.js b/datastore/test/tasks.test.js
new file mode 100644
index 0000000000..2353d821f9
--- /dev/null
+++ b/datastore/test/tasks.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('datastore:tasks', function () {
+ it('should be tested');
+});
diff --git a/debugger/app.js b/debugger/app.js
index 67d023f8ed..2c34995f41 100644
--- a/debugger/app.js
+++ b/debugger/app.js
@@ -15,12 +15,15 @@
// [START app]
'use strict';
+// [START setup]
if (process.env.GCLOUD_PROJECT) {
require('@google/cloud-debug');
}
var express = require('express');
var app = express();
+app.enable('trust proxy');
+// [END setup]
app.get('/', function (req, res) {
// Try using the StackDriver Debugger dashboard to inspect the "req" object
@@ -28,8 +31,10 @@ app.get('/', function (req, res) {
});
// Start the server
-var server = app.listen(process.env.PORT || '8080', function () {
+var server = app.listen(process.env.PORT || 8080, function () {
console.log('App listening on port %s', server.address().port);
console.log('Press Ctrl+C to quit.');
});
// [END app]
+
+module.exports = app;
diff --git a/debugger/package.json b/debugger/package.json
index 2bdf2ac4f3..dabf71d10d 100644
--- a/debugger/package.json
+++ b/debugger/package.json
@@ -1,6 +1,5 @@
{
- "name": "stackdriver-debugger",
- "description": "StackDriver Debugger sample for Node.js",
+ "name": "nodejs-docs-samples-debugger",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
@@ -9,10 +8,14 @@
"node": "~4.2"
},
"scripts": {
- "start": "node app.js"
+ "start": "node app.js",
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js"
},
"dependencies": {
"@google/cloud-debug": "^0.8.3",
"express": "^4.13.4"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/debugger/test/app.test.js b/debugger/test/app.test.js
new file mode 100644
index 0000000000..0bbbd70d41
--- /dev/null
+++ b/debugger/test/app.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('debugger', function () {
+ it('should be tested');
+});
diff --git a/favicon.ico b/favicon.ico
deleted file mode 100644
index 23c553a296..0000000000
Binary files a/favicon.ico and /dev/null differ
diff --git a/functions/README.md b/functions/README.md
index 3739f6c6b4..3eefdb8adc 100644
--- a/functions/README.md
+++ b/functions/README.md
@@ -29,7 +29,6 @@ environment.
* [Error Reporting](errorreporting/)
* [HTTP](http/)
* [Logging & Monitoring](log/)
-* [Modules](module/)
* [OCR (Optical Character Recognition)](ocr/)
* [SendGrid](sendgrid/)
* [Slack](slack/)
diff --git a/functions/background/README.md b/functions/background/README.md
index 13949855b3..bbcd42737b 100644
--- a/functions/background/README.md
+++ b/functions/background/README.md
@@ -1,58 +1,29 @@
-# Google Cloud Functions message sample
+# Google Cloud Functions - Background functions sample
-This sample shows calling the `success` and `failure` callbacks.
+See:
-View the [documentation][docs] or the [source code][code].
+* [Background functions documentation][docs]
+* [Background functions tutorial][tutorial]
+* [Background functions sample source code][code]
-[docs]: https://cloud.google.com/functions/writing
+[docs]: https://cloud.google.com/functions/docs/writing/background
+[tutorial]: https://cloud.google.com/functions/docs/tutorials/background
[code]: index.js
-## Deploy and Test
+## Deploy and run the sample
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
+See the [Background functions tutorial][tutorial].
-1. Clone this repository:
+## Run the tests
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/module
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
-1. Create a Cloud Storage Bucket to stage our deployment:
+1. Install dependencies:
- gsutil mb gs://[YOUR_BUCKET_NAME]
+ npm install
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Deploy the `helloworld` function with an HTTP trigger:
-
- gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Call the `helloworld` function with some data:
-
- gcloud alpha functions call helloworld --data '{"message":"keyboard cat"}'
-
-1. Call the `helloworld` function without any data:
-
- gcloud alpha functions call helloworld
-
- You should see something like this in your console:
-
- executionId: abcd1234-0
- result: Hello World!
-
-1. Check the logs for the `helloworld` function:
-
- gcloud alpha functions get-logs helloworld
-
- You should see something like this in your console:
-
- D ... User function triggered, starting execution
- I ... keyboard cat
- D ... Execution took 1 ms, user function completed successfully
-
-[quickstart]: https://cloud.google.com/functions/quickstart
+1. Run the tests:
+ npm test
diff --git a/functions/background/package.json b/functions/background/package.json
index dda9a497b0..a3c09c4dc1 100644
--- a/functions/background/package.json
+++ b/functions/background/package.json
@@ -1,15 +1,17 @@
{
- "name": "nodejs-docs-samples-functions",
- "description": "Node.js samples found on https://cloud.google.com",
+ "name": "nodejs-docs-samples-functions-background",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"request-promise": "^3.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/background.test.js b/functions/background/test/index.test.js
similarity index 98%
rename from test/functions/background.test.js
rename to functions/background/test/index.test.js
index 91dd7f134b..ed992439a9 100644
--- a/test/functions/background.test.js
+++ b/functions/background/test/index.test.js
@@ -20,7 +20,7 @@ function getSample () {
resolve('test');
}));
return {
- sample: proxyquire('../../functions/background', {
+ sample: proxyquire('../', {
'request-promise': requestPromise
}),
mocks: {
diff --git a/functions/datastore/package.json b/functions/datastore/package.json
index 62b1f2f0e5..fcdb901b52 100644
--- a/functions/datastore/package.json
+++ b/functions/datastore/package.json
@@ -1,15 +1,17 @@
{
"name": "nodejs-docs-samples-functions-datastore",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.35.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/datastore.test.js b/functions/datastore/test/index.test.js
similarity index 99%
rename from test/functions/datastore.test.js
rename to functions/datastore/test/index.test.js
index bbc78a5a8d..1bc34c8b45 100644
--- a/test/functions/datastore.test.js
+++ b/functions/datastore/test/index.test.js
@@ -32,7 +32,7 @@ function getSample () {
datastore: sinon.stub().returns(datastore)
};
return {
- sample: proxyquire('../../functions/datastore', {
+ sample: proxyquire('../', {
gcloud: gcloud
}),
mocks: {
diff --git a/functions/errorreporting/README.md b/functions/errorreporting/README.md
new file mode 100644
index 0000000000..85317bca4c
--- /dev/null
+++ b/functions/errorreporting/README.md
@@ -0,0 +1,27 @@
+
+
+# Google Cloud Functions - Reporting Errors from Cloud Functions sample
+
+See:
+
+* [Reporting Errors from Cloud Functions tutorial][tutorial]
+* [Reporting Errors from Cloud Functions sample source code][code]
+
+[tutorial]: https://cloud.google.com/functions/docs/monitoring/error-reporting
+[code]: index.js
+
+## Deploy and run the sample
+
+1. Read the [tutorial][tutorial].
+
+## Run the tests
+
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
+
+1. Install dependencies:
+
+ npm install
+
+1. Run the tests:
+
+ npm test
diff --git a/functions/errorreporting/package.json b/functions/errorreporting/package.json
index 4fc19844cf..a8ebf27071 100644
--- a/functions/errorreporting/package.json
+++ b/functions/errorreporting/package.json
@@ -1,15 +1,17 @@
{
"name": "nodejs-docs-samples-functions-errorreporting",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.36.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/functions/errorreporting/test/index.test.js b/functions/errorreporting/test/index.test.js
new file mode 100644
index 0000000000..f6b0ffc851
--- /dev/null
+++ b/functions/errorreporting/test/index.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('functions:errorreporting', function () {
+ it('should have tests');
+});
diff --git a/functions/gcs/package.json b/functions/gcs/package.json
index e2c8c45c19..e02ddcecf6 100644
--- a/functions/gcs/package.json
+++ b/functions/gcs/package.json
@@ -1,15 +1,17 @@
{
"name": "nodejs-docs-samples-functions-cloud-storage",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.35.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/gcs.test.js b/functions/gcs/test/index.test.js
similarity index 95%
rename from test/functions/gcs.test.js
rename to functions/gcs/test/index.test.js
index 12033717c1..b6d93ec91b 100644
--- a/test/functions/gcs.test.js
+++ b/functions/gcs/test/index.test.js
@@ -20,7 +20,7 @@ var proxyquire = require('proxyquire').noCallThru();
function getSample () {
var file = {
createReadStream: function () {
- var filepath = path.join(__dirname, '../../functions/gcs/sample.txt');
+ var filepath = path.join(__dirname, '../sample.txt');
return fs.createReadStream(filepath, { encoding: 'utf8' });
}
};
@@ -34,7 +34,7 @@ function getSample () {
storage: sinon.stub().returns(storage)
};
return {
- sample: proxyquire('../../functions/gcs', {
+ sample: proxyquire('../', {
gcloud: gcloud
}),
mocks: {
diff --git a/functions/helloworld/README.md b/functions/helloworld/README.md
index fced1e12d4..6571088dda 100644
--- a/functions/helloworld/README.md
+++ b/functions/helloworld/README.md
@@ -1,43 +1,27 @@
-# Google Cloud Functions Hello World sample
+# Google Cloud Functions - Hello World sample
-This is a basic hello world sample that shows a single exported function.
+See:
-View the [documentation][docs] or the [source code][code].
+* [Cloud Functions Hello World tutorial][tutorial]
+* [Cloud Functions Hello World sample source code][code]
-[docs]: https://cloud.google.com/functions/writing
+[tutorial]: https://cloud.google.com/functions/docs/quickstart
[code]: index.js
-## Deploy and Test
+## Deploy and run the sample
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
+See the [Cloud Functions Hello World tutorial][tutorial].
-1. Clone this repository:
+## Run the tests
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/module
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
-1. Create a Cloud Storage Bucket to stage our deployment:
+1. Install dependencies:
- gsutil mb gs://[YOUR_BUCKET_NAME]
+ npm install
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
+1. Run the tests:
-1. Deploy the `helloworld` function with an HTTP trigger:
-
- gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Call the `helloworld` function:
-
- gcloud alpha functions call helloworld
-
- You should see something like this in your console:
-
- executionId: abcd1234-0
- result: Hello World!
-
-[quickstart]: https://cloud.google.com/functions/quickstart
+ npm test
diff --git a/functions/helloworld/package.json b/functions/helloworld/package.json
new file mode 100644
index 0000000000..4b538bb9a7
--- /dev/null
+++ b/functions/helloworld/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "nodejs-docs-samples-functions-hello-world",
+ "version": "0.0.1",
+ "private": true,
+ "license": "Apache Version 2.0",
+ "author": "Google Inc.",
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
+ }
+}
diff --git a/test/functions/helloworld.test.js b/functions/helloworld/test/index.test.js
similarity index 98%
rename from test/functions/helloworld.test.js
rename to functions/helloworld/test/index.test.js
index 5b42093f61..039b0d1b2b 100644
--- a/test/functions/helloworld.test.js
+++ b/functions/helloworld/test/index.test.js
@@ -14,7 +14,7 @@
'use strict';
var proxyquire = require('proxyquire').noCallThru();
-var helloworldSample = proxyquire('../../functions/helloworld', {});
+var helloworldSample = proxyquire('../', {});
function getMockContext () {
return {
diff --git a/functions/http/README.md b/functions/http/README.md
index fc2f61eb91..13453ee8b9 100644
--- a/functions/http/README.md
+++ b/functions/http/README.md
@@ -1,35 +1,29 @@
-# Google Cloud Functions HTTP sample
+# Google Cloud Functions - HTTP functions sample
-This recipe shows you how to respond to HTTP requests with a Cloud Function.
+See:
-View the [source code][code].
+* [HTTP functions documentation][docs]
+* [HTTP functions tutorial][tutorial]
+* [HTTP functions sample source code][code]
+[docs]: https://cloud.google.com/functions/docs/writing/http
+[tutorial]: https://cloud.google.com/functions/docs/tutorials/http
[code]: index.js
-## Deploy and Test
+## Deploy and run the sample
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
+See the [HTTP functions tutorial][tutorial].
-1. Clone this repository:
+## Run the tests
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/http
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
-1. Create a Cloud Storage Bucket to stage our deployment:
+1. Install dependencies:
- gsutil mb gs://[YOUR_BUCKET_NAME]
+ npm install
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
+1. Run the tests:
-1. Deploy the "helloGET" function with an HTTP trigger
-
- gcloud alpha functions deploy publish --bucket [YOUR_BUCKET_NAME] --trigger-http
-
-1. Call the "helloGET" function:
-
- curl https://[YOUR_PROJECT_REGION].[YOUR_PROJECT_ID].cloudfunctions.net/helloGET
-
-[quickstart]: https://cloud.google.com/functions/quickstart
+ npm test
diff --git a/functions/http/package.json b/functions/http/package.json
new file mode 100644
index 0000000000..dd0e81a2d8
--- /dev/null
+++ b/functions/http/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "nodejs-docs-samples-functions-http",
+ "version": "0.0.1",
+ "private": true,
+ "license": "Apache Version 2.0",
+ "author": "Google Inc.",
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
+ }
+}
diff --git a/test/functions/http.test.js b/functions/http/test/index.test.js
similarity index 96%
rename from test/functions/http.test.js
rename to functions/http/test/index.test.js
index d8d64d9620..58fa52a273 100644
--- a/test/functions/http.test.js
+++ b/functions/http/test/index.test.js
@@ -20,7 +20,7 @@ function getSample () {
resolve('test');
}));
return {
- sample: proxyquire('../../functions/http', {
+ sample: proxyquire('../', {
'request-promise': requestPromise
}),
mocks: {
@@ -128,11 +128,7 @@ describe('functions:http', function () {
var mocks = getMocks();
var httpSample = getSample();
mocks.req.headers['content-type'] = 'application/octet-stream';
- if (typeof Buffer.from === 'function') {
- mocks.req.body = Buffer.from('John');
- } else {
- mocks.req.body = new Buffer('John');
- }
+ mocks.req.body = new Buffer('John');
httpSample.sample.helloContent(mocks.req, mocks.res);
assert.equal(mocks.res.status.calledOnce, true);
diff --git a/functions/log/README.md b/functions/log/README.md
index c087d9f1f8..bf61716def 100644
--- a/functions/log/README.md
+++ b/functions/log/README.md
@@ -1,48 +1,27 @@
-# Google Cloud Functions message sample
+# Google Cloud Functions - Logging and Monitoring sample
-This sample shows writing to logs in a Cloud Function.
+* [Writing and Viewing Logs from Cloud Functions documentation][docs]
+* [Viewing Cloud Functions monitored metrics documentation][docs2]
+* [Background functions sample source code][code]
-View the [documentation][docs] or the [source code][code].
-
-[docs]: https://cloud.google.com/functions/walkthroughs
+[docs]: https://cloud.google.com/functions/docs/monitoring/logging
+[docs2]: https://cloud.google.com/functions/docs/monitoring/metrics
[code]: index.js
-## Deploy and Test
-
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
-
-1. Clone this repository:
-
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/module
-
-1. Create a Cloud Storage Bucket to stage our deployment:
-
- gsutil mb gs://[YOUR_BUCKET_NAME]
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Deploy the `helloworld` function with an HTTP trigger:
-
- gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
+## Deploy and run the sample
-1. Call the `helloworld` function:
+See the [Writing and Viewing Logs from Cloud Functions documentation][docs].
- gcloud alpha functions call helloworld
+## Run the tests
-1. Check the logs for the `helloworld` function:
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
- gcloud alpha functions get-logs helloworld
+1. Install dependencies:
- You should see something like this in your console:
+ npm install
- D ... User function triggered, starting execution
- I ... I am a log entry!
- D ... Execution took 1 ms, user function completed successfully
+1. Run the tests:
-[quickstart]: https://cloud.google.com/functions/quickstart
+ npm test
diff --git a/functions/log/package.json b/functions/log/package.json
new file mode 100644
index 0000000000..b1dc23b5f7
--- /dev/null
+++ b/functions/log/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "nodejs-docs-samples-functions-log",
+ "version": "0.0.1",
+ "private": true,
+ "license": "Apache Version 2.0",
+ "author": "Google Inc.",
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
+ },
+ "dependencies": {
+ "gcloud": "^0.37.0",
+ "googleapis": "^12.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
+ }
+}
diff --git a/test/functions/log.test.js b/functions/log/test/index.test.js
similarity index 98%
rename from test/functions/log.test.js
rename to functions/log/test/index.test.js
index 7c3eb77a6b..d08ec49318 100644
--- a/test/functions/log.test.js
+++ b/functions/log/test/index.test.js
@@ -34,7 +34,7 @@ function getSample () {
getEntries: sinon.stub().callsArgWith(1, null, 'entries')
};
return {
- sample: proxyquire('../../functions/log', {
+ sample: proxyquire('../', {
googleapis: {
auth: auth,
monitoring: sinon.stub().returns(monitoring)
diff --git a/functions/module/README.md b/functions/module/README.md
deleted file mode 100644
index e19e49bcbc..0000000000
--- a/functions/module/README.md
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-# Google Cloud Functions module sample
-
-This sample shows exporting a Google Cloud Function as part of a module, which
-is the method one would use to store multiple function in a single source file.
-
-View the [documentation][docs] or the [source code][code].
-
-[docs]: https://cloud.google.com/functions/writing
-[code]: index.js
-
-## Deploy and Test
-
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
-
-1. Clone this repository:
-
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/module
-
-1. Create a Cloud Storage Bucket to stage our deployment:
-
- gsutil mb gs://[YOUR_BUCKET_NAME]
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Deploy the `helloworld` function with an HTTP trigger:
-
- gcloud alpha functions deploy helloworld --bucket [YOUR_BUCKET_NAME] --trigger-http
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your Cloud Storage Bucket.
-
-1. Call the `helloworld` function:
-
- gcloud alpha functions call helloworld
-
- You should see something like this in your console:
-
- executionId: abcd1234-0
- result: Hello World!
-
-[quickstart]: https://cloud.google.com/functions/quickstart
diff --git a/functions/ocr/README.md b/functions/ocr/README.md
index d51cd1ac2d..27a203be23 100644
--- a/functions/ocr/README.md
+++ b/functions/ocr/README.md
@@ -1,103 +1,27 @@
-# Google Cloud Functions OCR sample
+# Google Cloud Functions - OCR (Optical Character Recognition) sample
-This recipe shows you how to use the Cloud Vision API together with the Google
-Translate API using Cloud Pub/Sub as a message bus.
+See:
-View the [source code][code] or the [tutorial][tutorial].
+* [Cloud Functions OCR tutorial][tutorial]
+* [Cloud Functions OCR sample source code][code]
-[code]: index.js
[tutorial]: https://cloud.google.com/functions/docs/tutorials/ocr
+[code]: index.js
-## Overview
-
-![OCR](readme.png "OCR")
-
-1. Image is uploaded to Cloud Storage with text in any language (text in the
-image itself).
-1. Cloud Function is triggered, uses the Vision API to extract the text, and the
-Translate API to detect the language.
-1. For all languages we're translating into (except the language of the text),
-publish a message to ther *translate* topic.
-1. For the language that matches the language of the text, bypass translation
-and publish to the *save* topic.
-1. Cloud Function is triggered and uses the Translate API to translate the
-message into various languages, then publishes each translation to the *save*
-topic.
-1. Cloud Function is triggered and saves text to Cloud Storage.
-1. Translated text from the original source image is downloaded.
-
-## Deploy and Test
-
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
-
-1. Enable the [Vision API][enable_vision] and the [Translate API][enable_translate].
-
-1. Clone this repository:
-
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/ocr
-
-1. [Create a Google Translate API Key][translate_api_key].
-
-1. Create a file in the `app` folder called `config.json` with the following
-contents:
-
- {
- "TRANSLATE_API_KEY": "[YOUR_API_KEY]",
- "RESULT_TOPIC": "[RESULT_TOPIC_NAME]",
- "RESULT_BUCKET": "[RESULT_BUCKET_NAME]",
- "TRANSLATE_TOPIC": "[TRANSLATE_TOPIC_NAME]",
- "TRANSLATE": true,
- "TO_LANG": ["en", "fr", "es", "ja", "ru"]
- }
-
- * Replace `[YOUR_API_KEY]` with your Translate API key.
- * Replace `[RESULT_TOPIC_NAME]` with a topic name used for saving results.
- * Replace `[RESULT_BUCKET_NAME]` with a bucket name used for saving results.
- * Replace `[TRANSLATE_TOPIC_NAME]` with a topic name used for translating results.
-
-1. Deploy the `processImage` function with a GCS trigger:
-
- gcloud alpha functions deploy ocr-extract --bucket [YOUR_BUCKET_NAME] --trigger-gs-uri [YOUR_UPLOAD_BUCKET_NAME] --source app --entry-point processImage
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your staging Cloud Storage Bucket.
- * Replace `[YOUR_UPLOAD_BUCKET_NAME]` with the name of your Cloud Storage Bucket where you will be uploading images.
-
-1. Deploy the `translateText` function with a Pub/Sub trigger:
-
- gcloud alpha functions deploy ocr-translate --bucket [YOUR_BUCKET_NAME] --trigger-topic [YOUR_TRANSLATE_TOPIC_NAME] --source app --entry-point translateText
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your staging Cloud Storage Bucket.
- * Replace `[YOUR_TRANSLATE_TOPIC_NAME]` with the name of your Pub/Sub topic with which translations will be triggered.
-
-1. Deploy the `saveResult` function with a Pub/Sub trigger:
-
- gcloud alpha functions deploy ocr-save --bucket [YOUR_BUCKET_NAME] --trigger-topic [YOUR_RESULT_TOPIC_NAME] --source app --entry-point saveResult
-
- * Replace `[YOUR_BUCKET_NAME]` with the name of your staging Cloud Storage Bucket.
- * Replace `[YOUR_RESULT_TOPIC_NAME]` with the name of your Pub/Sub topic with which saving of results will be triggered.
-
-1. Upload a sample image:
-
- gsutil cp images/menu.jpg gs://[YOUR_UPLOAD_BUCKET_NAME]
-
- * Replace `[YOUR_UPLOAD_BUCKET_NAME]` with the name of your Cloud Storage Bucket where you will be uploading images.
+## Deploy and run the sample
-1. Watch the logs to make sure the executions have completed
+See the [Cloud Functions OCR tutorial][tutorial].
- gcloud alpha functions get-logs --limit 100
+## Run the tests
-1. Pull the extracted text from the bucket and pipe to standard out
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
- gsutil cat gs://[YOUR_RESULT_BUCKET_NAME]/menu_to_en.txt
+1. Install dependencies:
- * Replace `[YOUR_RESULT_BUCKET_NAME]` with the name of your Cloud Storage Bucket where translated text will be saved.
+ npm install
-[quickstart]: https://cloud.google.com/functions/quickstart
-[enable_vision]: https://console.cloud.google.com/flows/enableapi?apiid=vision.googleapis.com&redirect=https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/ocr
-[enable_translate]: https://console.cloud.google.com/flows/enableapi?apiid=translate&redirect=https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/functions/ocr
-[translate_api_key]: https://cloud.google.com/translate/v2/translating-text-with-rest#auth
+1. Run the tests:
+ npm test
diff --git a/functions/ocr/app/package.json b/functions/ocr/app/package.json
index eee690afdd..b0022549c4 100644
--- a/functions/ocr/app/package.json
+++ b/functions/ocr/app/package.json
@@ -1,16 +1,18 @@
{
"name": "nodejs-docs-samples-functions-ocr",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../../test/_setup.js test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
- "gcloud": "^0.35.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/ocr.test.js b/functions/ocr/app/test/index.test.js
similarity index 99%
rename from test/functions/ocr.test.js
rename to functions/ocr/app/test/index.test.js
index 56ae389a91..3b0d796813 100644
--- a/test/functions/ocr.test.js
+++ b/functions/ocr/app/test/index.test.js
@@ -60,7 +60,7 @@ function getSample () {
translate: sinon.stub().returns(translate)
};
return {
- sample: proxyquire('../../functions/ocr/app', {
+ sample: proxyquire('../', {
gcloud: gcloud,
'./config.json': config
}),
diff --git a/functions/ocr/readme.png b/functions/ocr/readme.png
deleted file mode 100644
index 20f05abb94..0000000000
Binary files a/functions/ocr/readme.png and /dev/null differ
diff --git a/functions/pubsub/package.json b/functions/pubsub/package.json
index 1f489c2950..565f7f24d1 100644
--- a/functions/pubsub/package.json
+++ b/functions/pubsub/package.json
@@ -1,15 +1,17 @@
{
"name": "nodejs-docs-samples-functions-pubsub",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.35.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/pubsub.test.js b/functions/pubsub/test/index.test.js
similarity index 98%
rename from test/functions/pubsub.test.js
rename to functions/pubsub/test/index.test.js
index 66c9638140..5d513b9557 100644
--- a/test/functions/pubsub.test.js
+++ b/functions/pubsub/test/index.test.js
@@ -26,7 +26,7 @@ function getSample () {
pubsub: sinon.stub().returns(pubsub)
};
return {
- sample: proxyquire('../../functions/pubsub', {
+ sample: proxyquire('../', {
gcloud: gcloud
}),
mocks: {
diff --git a/functions/sendgrid/README.md b/functions/sendgrid/README.md
index b164c1d320..284d362b7a 100644
--- a/functions/sendgrid/README.md
+++ b/functions/sendgrid/README.md
@@ -1,81 +1,27 @@
-# Google Cloud Functions SendGrid sample
+# Google Cloud Functions - SendGrid sample
-This recipe shows you how to send an email from a Cloud Function using SendGrid.
+See:
-View the [source code][code].
+* [Cloud Functions SendGrid tutorial][tutorial]
+* [Cloud Functions SendGrid sample source code][code]
+[tutorial]: https://cloud.google.com/functions/docs/tutorials/sendgrid
[code]: index.js
-## Deploy and Test
+## Deploy and run the sample
-1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud
-Functions for your project.
+See the [Cloud Functions SendGrid tutorial][tutorial].
-1. Clone this repository:
+## Run the tests
- git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
- cd nodejs-docs-samples/functions/sendgrid
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
-1. Create a Sendgrid account. You can either do this manually via the [SendGrid website](https://sendgrid.com/free),
-or you can use the [Google Cloud Launcher](https://cloud.google.com/launcher)
-which will create an account for you and integrate billing.
+1. Install dependencies:
- See [Creating a SendGrid account using Cloud Launcher](https://cloud.google.com/launcher/solution/sendgrid-app/sendgrid-email).
+ npm install
-1. Create a SendGrid API key:
+1. Run the tests:
- 1. Log in to your SendGrid account at [https://app.sendgrid.com](https://app.sendgrid.com).
- 1. Navigate to "Settings" => "API Keys".
- 1. Create a new "General API Key".
- 1. Ensure you select (at least) the "Mail Send" permission when you create the API key.
- 1. Copy the API Key when it is displayed (you will only see this once, make sure you paste it somewhere!).
-
-1. Create a Cloud Storage bucket to stage your Cloud Functions files, where
-`[YOUR_STAGING_BUCKET_NAME]` is a globally-unique bucket name:
-
- gsutil mb gs://[YOUR_STAGING_BUCKET_NAME]
-
-1. Create a Cloud Storage bucket to upload event `.json` files, where
-`[YOUR_EVENT_BUCKET_NAME]` is a globally-unique bucket name:
-
- gsutil mb gs://[YOUR_EVENT_BUCKET_NAME]
-
-1. Deploy the `sendgridEmail` function with an HTTP trigger, where
-`[YOUR_STAGING_BUCKET_NAME]` is the name of your staging bucket:
-
- gcloud alpha functions deploy sendgridEmail --bucket [YOUR_STAGING_BUCKET_NAME] --trigger-http
-
-1. Deploy the `sendgridWebhook` function with an HTTP trigger, where
-`[YOUR_STAGING_BUCKET_NAME]` is the name of your staging bucket:
-
- gcloud alpha functions deploy sendgridWebhook --bucket [YOUR_STAGING_BUCKET_NAME] --trigger-http
-
-1. Deploy the `sendgridLoad` function with a Cloud Storage trigger, where
-`[YOUR_STAGING_BUCKET_NAME]` is the name of your staging bucket and
-`[YOUR_EVENT_BUCKET_NAME]` is the name of your bucket for event `.json` files:
-
- gcloud alpha functions deploy sendgridLoad --bucket [YOUR_STAGING_BUCKET_NAME] --trigger-gs-uri [YOUR_EVENT_BUCKET_NAME]
-
-1. Call the `sendgridEmail` function by making an HTTP request:
-
- curl -X POST "https://[YOUR_REGION].[YOUR_PROJECT_ID].cloudfunctions.net/sendgridEmail?sg_key=[YOUR_API_KEY]" --data '{"to":"[YOUR_RECIPIENT_ADDR]","from":"[YOUR_SENDER_ADDR]","subject":"Hello from Sendgrid!","body":"Hello World!"}'
-
- * Replace `[YOUR_REGION]` with the region where you function is deployed. This is visible in your terminal when your function finishes deploying.
- * Replace `[YOUR_PROJECT_ID]` with your Cloud project ID. This is visible in your terminal when your function finishes deploying.
- * Replace `[YOUR_SENDGRID_KEY]` with your SendGrid API KEY.
- * Replace `[YOUR_RECIPIENT_ADDR]` with the recipient's email address.
- * Replace `[YOUR_SENDER_ADDR]` with your SendGrid account's email address.
-
-1. Check the logs for the `subscribe` function:
-
- gcloud alpha functions get-logs sendgridEmail
-
- You should see something like this in your console:
-
- D ... User function triggered, starting execution
- I ... Sending email...
- D ... Execution took 1 ms, user function completed successfully
-
-[quickstart]: https://cloud.google.com/functions/quickstart
+ npm test
diff --git a/functions/sendgrid/package.json b/functions/sendgrid/package.json
index eb62df1786..845f8f685f 100644
--- a/functions/sendgrid/package.json
+++ b/functions/sendgrid/package.json
@@ -1,18 +1,20 @@
{
"name": "nodejs-docs-samples-functions-sendgrid",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
- "gcloud": "^0.36.0",
+ "gcloud": "^0.37.0",
"node-uuid": "^1.4.7",
"sendgrid": "^3.0.5"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/functions/slack/README.md b/functions/slack/README.md
index df4664ea8d..3780baaf8f 100644
--- a/functions/slack/README.md
+++ b/functions/slack/README.md
@@ -1,14 +1,27 @@
-# Google Cloud Functions Slack Slash Command sample
+# Google Cloud Functions - Slack Slash Command sample
-This tutorial demonstrates using Cloud Functions to implement a Slack Slash
-Command that searches the Google Knowledge Graph API.
+See:
-View the [source code][code].
+* [Cloud Functions Slack tutorial][tutorial]
+* [Cloud Functions Slack sample source code][code]
+[tutorial]: https://cloud.google.com/functions/docs/tutorials/slack
[code]: index.js
-## Deploy and Test
+## Deploy and run the sample
-Read the tutorial at https://cloud.google.com/functions/docs/tutorials/slack
+See the [Cloud Functions Slack tutorial][tutorial].
+
+## Run the tests
+
+1. Read and follow the [prerequisites][../../#how-to-run-the-tests].
+
+1. Install dependencies:
+
+ npm install
+
+1. Run the tests:
+
+ npm test
diff --git a/functions/slack/package.json b/functions/slack/package.json
index b327543785..153814296d 100644
--- a/functions/slack/package.json
+++ b/functions/slack/package.json
@@ -1,15 +1,17 @@
{
"name": "nodejs-docs-samples-functions-slack",
- "description": "Node.js samples found on https://cloud.google.com",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
- "googleapis": "^11.0.0"
+ "googleapis": "^12.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/functions/uuid/package.json b/functions/uuid/package.json
index bc9a382a04..d94bc99d9d 100644
--- a/functions/uuid/package.json
+++ b/functions/uuid/package.json
@@ -1,21 +1,17 @@
{
- "name": "nodejs-docs-samples-functions",
- "description": "Node.js samples found on https://cloud.google.com",
+ "name": "nodejs-docs-samples-functions-uuid",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "contributors": [
- {
- "name": "Jason Dobry",
- "email": "jason.dobry@gmail.com"
- }
- ],
- "repository": {
- "type": "git",
- "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
+ "main": "./index.js",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"node-uuid": "^1.4.7"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/functions/uuid.test.js b/functions/uuid/test/index.test.js
similarity index 94%
rename from test/functions/uuid.test.js
rename to functions/uuid/test/index.test.js
index 17546ba5dc..6d14f0cb93 100644
--- a/test/functions/uuid.test.js
+++ b/functions/uuid/test/index.test.js
@@ -13,7 +13,7 @@
'use strict';
-var uuidSample = require('../../functions/uuid');
+var uuidSample = require('../');
describe('functions:uuid', function () {
it('should generate a uuid', function (done) {
diff --git a/language/package.json b/language/package.json
index f1fe11ce5f..ba0b599c62 100644
--- a/language/package.json
+++ b/language/package.json
@@ -1,18 +1,17 @@
{
- "name": "cloud-natural-language-api-samples",
- "version": "1.0.0",
- "description": "Samples for using the Google Cloud Natural Language API.",
- "repository": {
- "type": "git",
- "url": "git://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
- },
- "main": "analyze.js",
+ "name": "nodejs-docs-samples-language",
+ "version": "0.0.1",
+ "private": true,
+ "license": "Apache Version 2.0",
+ "author": "Google Inc.",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
- "googleapis": "^11.0.0"
+ "googleapis": "^12.0.0"
},
- "author": "Google, Inc.",
- "license": "Apache-2.0"
+ "devDependencies": {
+ "mocha": "^2.5.3"
+ }
}
diff --git a/test/language/analyze.test.js b/language/system-test/analyze.test.js
similarity index 100%
rename from test/language/analyze.test.js
rename to language/system-test/analyze.test.js
diff --git a/language/test/analyze.test.js b/language/test/analyze.test.js
new file mode 100644
index 0000000000..500b91a2b4
--- /dev/null
+++ b/language/test/analyze.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('language:analyze', function () {
+ it('should be tested');
+});
diff --git a/logging/package.json b/logging/package.json
index dc5e8f123c..ac823823e6 100644
--- a/logging/package.json
+++ b/logging/package.json
@@ -1,17 +1,20 @@
{
"name": "nodejs-docs-samples-logging",
- "description": "Node.js samples for Google Cloud Logging.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
"express": "^4.13.4",
"fluent-logger": "^1.1.1",
- "gcloud": "^0.34.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/logging/export.test.js b/logging/system-test/export.test.js
similarity index 94%
rename from test/logging/export.test.js
rename to logging/system-test/export.test.js
index 05a9b16f9c..222d18e90c 100644
--- a/test/logging/export.test.js
+++ b/logging/system-test/export.test.js
@@ -13,7 +13,7 @@
'use strict';
-var exportExample = require('../../logging/export');
+var exportExample = require('../export');
describe('logging:export', function () {
it('should list sinks', function (done) {
diff --git a/logging/system-test/fluent.test.js b/logging/system-test/fluent.test.js
new file mode 100644
index 0000000000..9ce35c1a57
--- /dev/null
+++ b/logging/system-test/fluent.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('logging:fluent', function () {
+ it('should be tested');
+});
diff --git a/test/logging/list.test.js b/logging/system-test/list.test.js
similarity index 95%
rename from test/logging/list.test.js
rename to logging/system-test/list.test.js
index c505625322..701bd0f4cb 100644
--- a/test/logging/list.test.js
+++ b/logging/system-test/list.test.js
@@ -13,7 +13,7 @@
'use strict';
-var listExample = require('../../logging/list');
+var listExample = require('../list');
describe('logging:list', function () {
it('should list entries', function (done) {
diff --git a/test/logging/write.test.js b/logging/system-test/write.test.js
similarity index 94%
rename from test/logging/write.test.js
rename to logging/system-test/write.test.js
index 1465e45069..fe5663b076 100644
--- a/test/logging/write.test.js
+++ b/logging/system-test/write.test.js
@@ -13,7 +13,7 @@
'use strict';
-var writeExample = require('../../logging/write');
+var writeExample = require('../write');
describe('logging:write', function () {
it('should write entries', function (done) {
diff --git a/logging/test/export.test.js b/logging/test/export.test.js
new file mode 100644
index 0000000000..6fa813ad2c
--- /dev/null
+++ b/logging/test/export.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('logging:export', function () {
+ it('should be tested');
+});
diff --git a/test/logging/fluent.test.js b/logging/test/fluent.test.js
similarity index 96%
rename from test/logging/fluent.test.js
rename to logging/test/fluent.test.js
index 349feeea2a..c15c344764 100644
--- a/test/logging/fluent.test.js
+++ b/logging/test/fluent.test.js
@@ -27,7 +27,7 @@ describe('logging:fluent', function () {
}
};
- var app = proxyquire('../../logging/fluent.js', {
+ var app = proxyquire('../fluent', {
'fluent-logger': {
createFluentSender: function (name, options) {
assert(name === 'myapp');
diff --git a/logging/test/list.test.js b/logging/test/list.test.js
new file mode 100644
index 0000000000..2304b976e2
--- /dev/null
+++ b/logging/test/list.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('logging:list', function () {
+ it('should be tested');
+});
diff --git a/logging/test/write.test.js b/logging/test/write.test.js
new file mode 100644
index 0000000000..03c1e6c2ae
--- /dev/null
+++ b/logging/test/write.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('logging:write', function () {
+ it('should be tested');
+});
diff --git a/monitoring/package.json b/monitoring/package.json
index fee778f606..046f99a395 100644
--- a/monitoring/package.json
+++ b/monitoring/package.json
@@ -1,14 +1,18 @@
{
"name": "nodejs-docs-samples-monitoring",
- "description": "Samples For Cloud Monitoring v3 API",
"version": "0.0.1",
+ "private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async":"^1.5.2",
- "googleapis": "^7.1.0"
+ "googleapis": "^12.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/monitoring/create_custom_metric.test.js b/monitoring/system-test/create_custom_metric.test.js
similarity index 96%
rename from test/monitoring/create_custom_metric.test.js
rename to monitoring/system-test/create_custom_metric.test.js
index 44ff198ffc..0e2cad29b4 100644
--- a/test/monitoring/create_custom_metric.test.js
+++ b/monitoring/system-test/create_custom_metric.test.js
@@ -13,7 +13,7 @@
'use strict';
-var customMetricsExample = require('../../monitoring/create_custom_metric');
+var customMetricsExample = require('../create_custom_metric');
/** Refactored out to keep lines shorter */
function getPointValue (timeSeries) {
diff --git a/test/monitoring/list_resources.test.js b/monitoring/system-test/list_resources.test.js
similarity index 95%
rename from test/monitoring/list_resources.test.js
rename to monitoring/system-test/list_resources.test.js
index b7b0c8bf91..8660828a73 100644
--- a/test/monitoring/list_resources.test.js
+++ b/monitoring/system-test/list_resources.test.js
@@ -13,7 +13,7 @@
'use strict';
-var listResourcesExample = require('../../monitoring/list_resources');
+var listResourcesExample = require('../list_resources');
describe('monitoring:list_resources', function () {
it('should list a bunch of stuff', function (done) {
diff --git a/monitoring/test/create_custom_metric.test.js b/monitoring/test/create_custom_metric.test.js
new file mode 100644
index 0000000000..18843c626c
--- /dev/null
+++ b/monitoring/test/create_custom_metric.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('monitoring:create_custom_metric', function () {
+ it('should be tested');
+});
diff --git a/monitoring/test/list_resources.test.js b/monitoring/test/list_resources.test.js
new file mode 100644
index 0000000000..03e0d0b22b
--- /dev/null
+++ b/monitoring/test/list_resources.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('monitoring:list_resources', function () {
+ it('should be tested');
+});
diff --git a/package.json b/package.json
index 038e6b10d3..0b045a6b48 100644
--- a/package.json
+++ b/package.json
@@ -35,53 +35,40 @@
"sinon"
],
"ignore": [
- "appengine/bower/public/bower_components/**",
- "appengine/geddy/**",
- "appengine/kraken/**",
- "appengine/loopback/**",
+ "appengine/bower/public/bower_components",
+ "appengine/geddy",
+ "appengine/kraken",
+ "appengine/loopback",
"appengine/parse-server/cloud/main.js",
- "appengine/sails/**",
- "appengine/webpack/dist/**",
+ "appengine/sails",
+ "appengine/webpack/dist",
"**/node_modules/**",
- "coverage/"
+ "coverage"
]
},
"scripts": {
- "mocha": "mocha -R dot -t 120000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
- "cover": "nyc mocha --cache -R dot -t 180000 --require intelli-espower-loader test/_setup.js test/**/*.test.js",
- "deps_bigquery": "cd bigquery; npm i; cd ../",
- "deps_computeengine": "cd computeengine; npm i; cd ../",
- "deps_datastore": "cd datastore; npm i; cd ../",
- "deps_debugger": "cd debugger; npm i; cd ../",
- "deps_functions": "cd functions/uuid; npm i; cd ../..",
- "deps_language": "cd language; npm i; cd ../",
- "deps_logging": "cd logging; npm i; cd ../",
- "deps_monitoring": "cd monitoring; npm i; cd ../",
- "deps_prediction": "cd prediction; npm i; cd ../",
- "deps_pubsub": "cd pubsub; npm i; cd ../",
- "deps_speech": "cd speech; npm i; cd ../",
- "deps_storage": "cd storage; npm i; cd ../",
- "deps_trace": "cd trace; npm i; cd ../",
- "deps_vision": "cd vision; npm i; cd ../",
- "lint": "semistandard \"**/*.js\"",
- "pretest_geddy": "cd appengine/geddy; npm i geddy; GEDDY_SECRET=config/secrets.json; [[ -f $GEDDY_SECRET ]] || echo '{}' > $GEDDY_SECRET && node node_modules/.bin/geddy gen secret; cd ../..;",
- "pretest": "npm run deps_language; npm run deps_trace; npm run deps_debugger; npm run deps_vision; npm run deps_computeengine; npm run deps_bigquery; npm run deps_datastore; npm run deps_monitoring; npm run deps_storage; npm run deps_pubsub; npm run deps_prediction; npm run deps_logging; npm run deps_functions; npm run deps_speech; npm run pretest_geddy;",
- "report": "nyc report --reporter=lcov | codecov",
- "report-html": "nyc report --reporter=html",
- "test": "npm run lint && npm run cover"
+ "lint": "semistandard",
+ "pretest": "npm run lint && ./scripts/geddy && ./scripts/clean",
+ "mocha": "mocha -R spec -S -t 120000 --require intelli-espower-loader ./test/_setup.js '{*,appengine/*,functions/*}/test/*.test.js'",
+ "test": "npm run mocha",
+ "cover": "nyc --cache npm test && nyc report --reporter=html && nyc report --reporter=lcov",
+ "system-test": "mocha -R spec -S -t 120000 --require intelli-espower-loader ./system-test/_setup.js '{*,appengine/*}/system-test/*.test.js'",
+ "system-cover": "npm run pretest && nyc --cache npm run system-test && nyc report --reporter=html && nyc report --reporter=lcov",
+ "all-test": "mocha -R spec -S -t 120000 --require intelli-espower-loader ./system-test/_setup.js '{*,appengine/*,functions/*}/test/*.test.js' '{*,appengine/*}/system-test/*.test.js'",
+ "all-cover": "npm run pretest && nyc --cache npm run all-test && nyc report --reporter=html && nyc report --reporter=lcov"
},
"devDependencies": {
"async": "^1.5.2",
- "codecov": "^1.0.1",
"intelli-espower-loader": "^1.0.1",
"mocha": "^2.5.3",
"nodejs-repo-tools": "git+https://github.com/GoogleCloudPlatform/nodejs-repo-tools.git#bbbb6035d77671eb053dbe6b6f0e3ff983f79639",
"nyc": "^6.4.4",
"power-assert": "^1.4.1",
- "proxyquire": "^1.7.9",
+ "proxyquire": "^1.7.10",
"request": "^2.72.0",
"semistandard": "^8.0.0",
- "sinon": "^1.17.4",
+ "shelljs": "^0.7.3",
+ "sinon": "^1.17.5",
"supertest": "^1.2.0"
}
}
diff --git a/prediction/package.json b/prediction/package.json
index d51e291eb9..3c4421e015 100644
--- a/prediction/package.json
+++ b/prediction/package.json
@@ -1,14 +1,17 @@
{
"name": "nodejs-docs-samples-prediction",
- "description": "Node.js samples for Google Cloud Prediction API.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
- "googleapis": "^7.1.0"
+ "googleapis": "^12.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/prediction/hostedmodels.test.js b/prediction/system-test/hostedmodels.test.js
similarity index 100%
rename from test/prediction/hostedmodels.test.js
rename to prediction/system-test/hostedmodels.test.js
diff --git a/prediction/test/hostedmodels.test.js b/prediction/test/hostedmodels.test.js
new file mode 100644
index 0000000000..d9a237541f
--- /dev/null
+++ b/prediction/test/hostedmodels.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('prediction:hostedmodels', function () {
+ it('should be tested');
+});
diff --git a/pubsub/package.json b/pubsub/package.json
index 736274bb4f..abb35d2ab3 100644
--- a/pubsub/package.json
+++ b/pubsub/package.json
@@ -1,13 +1,17 @@
{
"name": "nodejs-docs-samples-pubsub",
- "description": "Node.js samples for Google Cloud Pub/Sub.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
- "engines": {
- "node": ">=0.10.x"
+ "author": "Google Inc.",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
- "gcloud": "^0.34.0"
+ "gcloud": "^0.37.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/pubsub/system-test/iam.test.js b/pubsub/system-test/iam.test.js
new file mode 100644
index 0000000000..ac5d123e5e
--- /dev/null
+++ b/pubsub/system-test/iam.test.js
@@ -0,0 +1,48 @@
+// Copyright 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 proxyquire = require('proxyquire');
+
+describe('pubsub:iam', function () {
+ it('should run the sample', function (done) {
+ proxyquire('../iam', {}).main(function (err, results) {
+ assert(!err);
+ assert(results.length === 8);
+ // Got topic and apiResponse
+ assert(results[0].length === 2);
+ // Got policy and apiResponse
+ assert(results[1].length === 2);
+ // Got permissions and apiResponse
+ assert(results[2].length === 2);
+ // Got subscription and apiResponse
+ assert(results[3].length === 2);
+ // Got policy and apiResponse
+ assert(results[4].length === 2);
+ // Got permissions and apiResponse
+ assert(results[5].length === 2);
+ // Got empty apiResponse
+ assert.deepEqual(results[6], {});
+ // Got empty apiResponse
+ assert.deepEqual(results[7], {});
+ assert(console.log.calledWith('Created topic messageCenter2'));
+ assert(console.log.calledWith('Got permissions for messageCenter2'));
+ assert(console.log.calledWith('Subscribed to messageCenter2'));
+ assert(console.log.calledWith('Got permissions for newMessages2'));
+ assert(console.log.calledWith('Deleted subscription newMessages2'));
+ assert(console.log.calledWith('Deleted topic messageCenter2'));
+ done();
+ });
+ });
+});
diff --git a/pubsub/system-test/subscription.test.js b/pubsub/system-test/subscription.test.js
new file mode 100644
index 0000000000..05fad42833
--- /dev/null
+++ b/pubsub/system-test/subscription.test.js
@@ -0,0 +1,49 @@
+// Copyright 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 proxyquire = require('proxyquire');
+
+describe('pubsub:subscription', function () {
+ it('should run the sample', function (done) {
+ proxyquire('../subscription', {}).main(function (err, results) {
+ assert(!err);
+ assert(results.length === 8);
+ // Got topic and apiResponse
+ assert(results[0].length === 2);
+ // Got subscription and apiResponse
+ assert(results[1].length === 2);
+ // Got array of topics
+ assert(Array.isArray(results[2]));
+ // Got array of subscriptions
+ assert(Array.isArray(results[3]));
+ // Got messageIds and apiResponse
+ assert(results[4].length === 2);
+ // Got array of messages
+ assert(Array.isArray(results[5]));
+ // Got empty apiResponse
+ assert.deepEqual(results[6], {});
+ // Got empty apiResponse
+ assert.deepEqual(results[7], {});
+ assert(console.log.calledWith('Created topic messageCenter'));
+ assert(console.log.calledWith('Subscribed to messageCenter'));
+ assert(console.log.calledWith('Published 1 messages'));
+ assert(console.log.calledWith('received message: Hello, world!'));
+ assert(console.log.calledWith('Pulled 1 messages'));
+ assert(console.log.calledWith('Deleted subscription newMessages'));
+ assert(console.log.calledWith('Deleted topic messageCenter'));
+ done();
+ });
+ });
+});
diff --git a/test/pubsub/iam.test.js b/pubsub/test/iam.test.js
similarity index 74%
rename from test/pubsub/iam.test.js
rename to pubsub/test/iam.test.js
index 10445c7a9a..63d91f4461 100644
--- a/test/pubsub/iam.test.js
+++ b/pubsub/test/iam.test.js
@@ -13,39 +13,9 @@
'use strict';
-var proxyquire = require('proxyquire');
+var proxyquire = require('proxyquire').noCallThru();
describe('pubsub:iam', function () {
- it('should run the sample', function (done) {
- proxyquire('../../pubsub/iam', {}).main(function (err, results) {
- assert(!err);
- assert(results.length === 8);
- // Got topic and apiResponse
- assert(results[0].length === 2);
- // Got policy and apiResponse
- assert(results[1].length === 2);
- // Got permissions and apiResponse
- assert(results[2].length === 2);
- // Got subscription and apiResponse
- assert(results[3].length === 2);
- // Got policy and apiResponse
- assert(results[4].length === 2);
- // Got permissions and apiResponse
- assert(results[5].length === 2);
- // Got empty apiResponse
- assert.deepEqual(results[6], {});
- // Got empty apiResponse
- assert.deepEqual(results[7], {});
- assert(console.log.calledWith('Created topic messageCenter2'));
- assert(console.log.calledWith('Got permissions for messageCenter2'));
- assert(console.log.calledWith('Subscribed to messageCenter2'));
- assert(console.log.calledWith('Got permissions for newMessages2'));
- assert(console.log.calledWith('Deleted subscription newMessages2'));
- assert(console.log.calledWith('Deleted topic messageCenter2'));
- done();
- });
- });
-
describe('getTopicPolicyExample', function () {
it('handles error', function () {
var topic = {
@@ -53,7 +23,7 @@ describe('pubsub:iam', function () {
getPolicy: sinon.stub().callsArgWith(0, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
topic: sinon.stub().returns(topic)
@@ -72,7 +42,7 @@ describe('pubsub:iam', function () {
getPolicy: sinon.stub().callsArgWith(0, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
subscription: sinon.stub().returns(subscription)
@@ -93,7 +63,7 @@ describe('pubsub:iam', function () {
setPolicy: sinon.stub().callsArgWith(1, null, policy, apiResponse)
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
topic: sinon.stub().returns(topic)
@@ -111,7 +81,7 @@ describe('pubsub:iam', function () {
setPolicy: sinon.stub().callsArgWith(1, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
topic: sinon.stub().returns(topic)
@@ -132,7 +102,7 @@ describe('pubsub:iam', function () {
setPolicy: sinon.stub().callsArgWith(1, null, policy, apiResponse)
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
subscription: sinon.stub().returns(subscription)
@@ -150,7 +120,7 @@ describe('pubsub:iam', function () {
setPolicy: sinon.stub().callsArgWith(1, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
subscription: sinon.stub().returns(subscription)
@@ -169,7 +139,7 @@ describe('pubsub:iam', function () {
testPermissions: sinon.stub().callsArgWith(1, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
topic: sinon.stub().returns(topic)
@@ -188,7 +158,7 @@ describe('pubsub:iam', function () {
testPermissions: sinon.stub().callsArgWith(1, 'error')
}
};
- proxyquire('../../pubsub/iam', {
+ proxyquire('../iam', {
'./subscription': {
pubsub: {
subscription: sinon.stub().returns(subscription)
diff --git a/test/pubsub/subscription.test.js b/pubsub/test/subscription.test.js
similarity index 75%
rename from test/pubsub/subscription.test.js
rename to pubsub/test/subscription.test.js
index eab1374380..005cab2652 100644
--- a/test/pubsub/subscription.test.js
+++ b/pubsub/test/subscription.test.js
@@ -16,37 +16,6 @@
var proxyquire = require('proxyquire');
describe('pubsub:subscription', function () {
- it('should run the sample', function (done) {
- proxyquire('../../pubsub/subscription', {}).main(function (err, results) {
- assert(!err);
- assert(results.length === 8);
- // Got topic and apiResponse
- assert(results[0].length === 2);
- // Got subscription and apiResponse
- assert(results[1].length === 2);
- // Got array of topics
- assert(Array.isArray(results[2]));
- // Got array of subscriptions
- assert(Array.isArray(results[3]));
- // Got messageIds and apiResponse
- assert(results[4].length === 2);
- // Got array of messages
- assert(Array.isArray(results[5]));
- // Got empty apiResponse
- assert.deepEqual(results[6], {});
- // Got empty apiResponse
- assert.deepEqual(results[7], {});
- assert(console.log.calledWith('Created topic messageCenter'));
- assert(console.log.calledWith('Subscribed to messageCenter'));
- assert(console.log.calledWith('Published 1 messages'));
- assert(console.log.calledWith('received message: Hello, world!'));
- assert(console.log.calledWith('Pulled 1 messages'));
- assert(console.log.calledWith('Deleted subscription newMessages'));
- assert(console.log.calledWith('Deleted topic messageCenter'));
- done();
- });
- });
-
describe('createTopicExample', function () {
it('handles error', function () {
var topic = {
@@ -55,7 +24,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
topic: sinon.stub().returns(topic)
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -73,7 +42,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
topic: sinon.stub().returns(topic)
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -91,7 +60,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
subscription: sinon.stub().returns(subscription)
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -109,7 +78,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
topic: sinon.stub().returns(topic)
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -124,7 +93,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
getTopics: sinon.stub().callsArgWith(1, 'error')
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -141,7 +110,7 @@ describe('pubsub:subscription', function () {
token: '1234'
});
pubsub.getTopics.onSecondCall().callsArgWith(1, null, []);
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -159,7 +128,7 @@ describe('pubsub:subscription', function () {
token: '1234'
});
pubsub.getTopics.onSecondCall().callsArgWith(1, 'error');
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -174,7 +143,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
getSubscriptions: sinon.stub().callsArgWith(1, 'error')
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -191,7 +160,7 @@ describe('pubsub:subscription', function () {
token: '1234'
});
pubsub.getSubscriptions.onSecondCall().callsArgWith(1, null, []);
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -209,7 +178,7 @@ describe('pubsub:subscription', function () {
token: '1234'
});
pubsub.getSubscriptions.onSecondCall().callsArgWith(1, 'error');
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
@@ -224,7 +193,7 @@ describe('pubsub:subscription', function () {
var pubsub = {
subscribe: sinon.stub().callsArgWith(3, 'error')
};
- proxyquire('../../pubsub/subscription', {
+ proxyquire('../subscription', {
gcloud: {
pubsub: sinon.stub().returns(pubsub)
}
diff --git a/scripts/clean b/scripts/clean
new file mode 100755
index 0000000000..17cdfb30fe
--- /dev/null
+++ b/scripts/clean
@@ -0,0 +1,18 @@
+#!/usr/bin/env node
+
+// Copyright 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.
+
+require('shelljs/global');
+
+rm('-rf', 'coverage');
diff --git a/scripts/geddy b/scripts/geddy
new file mode 100755
index 0000000000..d75a50f00d
--- /dev/null
+++ b/scripts/geddy
@@ -0,0 +1,24 @@
+#!/usr/bin/env node
+
+// Copyright 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.
+
+require('shelljs/global');
+
+cd('appengine/geddy');
+exec('npm install geddy');
+if (!test('-e', 'config/secrets.json')) {
+ echo('{}').to('config/secrets.json');
+ exec('node node_modules/.bin/geddy gen secret');
+}
+cd('../..');
diff --git a/scripts/install b/scripts/install
new file mode 100755
index 0000000000..c03a19d12f
--- /dev/null
+++ b/scripts/install
@@ -0,0 +1,81 @@
+#!/usr/bin/env node
+
+// Copyright 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.
+
+var async = require('async');
+var path = require('path');
+
+require('shelljs/global');
+
+// Install NPM dependencies, in up to 5 directories at a time
+var queue = async.queue(function (directory, callback) {
+ installForDirectory(directory, callback);
+}, 5);
+
+queueDirectories('appengine');
+queue.push('bigquery');
+queue.push('computeengine');
+queue.push('datastore');
+queue.push('debugger');
+queueDirectories('functions');
+queue.push('functions/ocr/app');
+queue.push('language');
+queue.push('logging');
+queue.push('monitoring');
+queue.push('prediction');
+queue.push('pubsub');
+queue.push('speech');
+queue.push('storage');
+queue.push('trace');
+queue.push('vision');
+
+/**
+ * Install NPM dependencies within a single directory.
+ *
+ * @param {string} directory The name of the directory in which to install dependencies.
+ * @param {function} callback The callback function.
+ */
+function installForDirectory(directory, callback) {
+ console.log(directory + '...installing dependencies');
+ exec('npm install', {
+ async: true,
+ cwd: path.join(__dirname, '../', directory)
+ }, function (err) {
+ console.log(directory + '...done');
+ callback(err);
+ });
+}
+
+/**
+ * Recursively install NPM dependencies within a single directory.
+ *
+ * @param {string} directory The name of the directory in which to recursively install dependencies.
+ */
+function queueDirectories(directory) {
+ // Move into the directory
+ cd(directory);
+
+ // List the files in the directory
+ ls('-dl', '*')
+ .filter(function (file) {
+ // Find the directories within the directory
+ return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test';
+ })
+ .forEach(function (file) {
+ queue.push(directory + '/' + file.name);
+ });
+
+ // Move out of the directory
+ cd('..');
+}
diff --git a/scripts/uninstall b/scripts/uninstall
new file mode 100755
index 0000000000..2fa9c45eae
--- /dev/null
+++ b/scripts/uninstall
@@ -0,0 +1,84 @@
+#!/usr/bin/env node
+
+// Copyright 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.
+
+var async = require('async');
+var path = require('path');
+
+require('shelljs/global');
+
+// Uninstall NPM dependencies, in up to 5 directories at a time
+var queue = async.queue(function (directory, callback) {
+ uninstallForDirectory(directory, callback);
+}, 5);
+
+queueDirectories('appengine');
+queue.push('bigquery');
+queue.push('computeengine');
+queue.push('datastore');
+queue.push('debugger');
+queueDirectories('functions');
+queue.push('functions/ocr/app');
+queue.push('language');
+queue.push('logging');
+queue.push('monitoring');
+queue.push('prediction');
+queue.push('pubsub');
+queue.push('speech');
+queue.push('storage');
+queue.push('trace');
+queue.push('vision');
+
+/**
+ * Uninstall NPM dependencies within a single directory.
+ *
+ * @param {string} directory The name of the directory in which to uninstall dependencies.
+ * @param {function} callback The callback function.
+ */
+function uninstallForDirectory(directory, callback) {
+ // Move into the directory
+ cd(directory);
+
+ // Uninstall dependencies
+ console.log(directory + '...uninstalling dependencies');
+ rm('-rf', 'node_modules');
+
+ // Move out of the directory
+ cd('..');
+ console.log(directory + '...done');
+ callback();
+}
+
+/**
+ * Recursively uninstall NPM dependencies within a single directory.
+ *
+ * @param {string} directory The name of the directory in which to recursively uninstall dependencies.
+ */
+function queueDirectories(directory) {
+ // Move into the directory
+ cd(directory);
+
+ // List the files in the directory
+ ls('-dl', '*')
+ .filter(function (file) {
+ // Find the directories within the directory
+ return file.isDirectory() && file.name !== 'test' && file.name !== 'system-test';
+ })
+ .forEach(function (file) {
+ queue.push(directory + '/' + file.name);
+ });
+
+ // Move out of the directory
+ cd('..');
+}
diff --git a/speech/package.json b/speech/package.json
index a0949af7d2..c0df797e2d 100644
--- a/speech/package.json
+++ b/speech/package.json
@@ -1,12 +1,12 @@
{
"name": "nodejs-docs-samples-speech",
- "description": "Node.js samples for Google Cloud Speech API.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async": "^1.5.2",
@@ -14,5 +14,8 @@
"google-proto-files": "^0.3.0",
"googleapis": "^12.0.0",
"grpc": "^0.15.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/speech/recognize.test.js b/speech/system-test/recognize.test.js
similarity index 90%
rename from test/speech/recognize.test.js
rename to speech/system-test/recognize.test.js
index 4591484bcd..7da66d5031 100644
--- a/test/speech/recognize.test.js
+++ b/speech/system-test/recognize.test.js
@@ -14,12 +14,12 @@
'use strict';
var path = require('path');
-var recognizeExample = require('../../speech/recognize');
+var recognizeExample = require('../recognize');
describe('speech:recognize', function () {
it('should recognize speech in audio', function (done) {
recognizeExample.main(
- path.join(__dirname, '../../speech/resources/audio.raw'),
+ path.join(__dirname, '../resources/audio.raw'),
function (err, result) {
assert(!err);
assert(result);
diff --git a/test/speech/recognize_streaming.test.js b/speech/system-test/recognize_streaming.test.js
similarity index 90%
rename from test/speech/recognize_streaming.test.js
rename to speech/system-test/recognize_streaming.test.js
index 0ae242210f..0d008d0c1c 100644
--- a/test/speech/recognize_streaming.test.js
+++ b/speech/system-test/recognize_streaming.test.js
@@ -14,12 +14,12 @@
'use strict';
var path = require('path');
-var recognizeExample = require('../../speech/recognize_streaming');
+var recognizeExample = require('../recognize_streaming');
describe('speech:recognize_streaming', function () {
it('should recognize audio', function (done) {
recognizeExample.main(
- path.join(__dirname, '../../speech/resources/audio.raw'),
+ path.join(__dirname, '../resources/audio.raw'),
process.env.SPEECH_API_HOST || 'speech.googleapis.com',
function (err, results) {
assert(!err);
diff --git a/speech/test/recognize.test.js b/speech/test/recognize.test.js
new file mode 100644
index 0000000000..00135c8b99
--- /dev/null
+++ b/speech/test/recognize.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('speech:recognize', function () {
+ it('should be tested');
+});
diff --git a/speech/test/recognize_streaming.test.js b/speech/test/recognize_streaming.test.js
new file mode 100644
index 0000000000..3d2836574c
--- /dev/null
+++ b/speech/test/recognize_streaming.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('speech:recognize_streaming', function () {
+ it('should be tested');
+});
diff --git a/storage/package.json b/storage/package.json
index df2f2b9dbb..eb0cb67950 100644
--- a/storage/package.json
+++ b/storage/package.json
@@ -1,14 +1,17 @@
{
"name": "nodejs-docs-samples-storage",
- "description": "Node.js samples for Google Cloud Storage.",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
- "engines": {
- "node": ">=0.10.x"
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
- "googleapis": "^4.0.0"
+ "googleapis": "^12.0.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/test/storage/authSample.test.js b/storage/system-test/authSample.test.js
similarity index 95%
rename from test/storage/authSample.test.js
rename to storage/system-test/authSample.test.js
index 892e9c119a..dccd11db19 100644
--- a/test/storage/authSample.test.js
+++ b/storage/system-test/authSample.test.js
@@ -16,7 +16,7 @@
*/
'use strict';
-var authSampleExample = require('../../storage/authSample');
+var authSampleExample = require('../authSample');
var projectId = process.env.GCLOUD_PROJECT;
describe('storage:authSample', function () {
diff --git a/storage/test/authSample.test.js b/storage/test/authSample.test.js
new file mode 100644
index 0000000000..5c3c7c2a00
--- /dev/null
+++ b/storage/test/authSample.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('storage:authSample', function () {
+ it('should be tested');
+});
diff --git a/system-test/_setup.js b/system-test/_setup.js
new file mode 100644
index 0000000000..4420032d56
--- /dev/null
+++ b/system-test/_setup.js
@@ -0,0 +1,27 @@
+// Copyright 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';
+
+require('../test/_setup');
+
+var assert = require('power-assert');
+var sinon = require('sinon');
+
+global.assert = assert;
+global.sinon = sinon;
+
+beforeEach(function () {
+ assert(process.env.GCLOUD_PROJECT, 'Must set GCLOUD_PROJECT environment variable!');
+ assert(process.env.GOOGLE_APPLICATION_CREDENTIALS, 'Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!');
+});
diff --git a/test/_setup.js b/test/_setup.js
index 1b5615fe48..c6483a7956 100644
--- a/test/_setup.js
+++ b/test/_setup.js
@@ -19,9 +19,20 @@ var sinon = require('sinon');
global.assert = assert;
global.sinon = sinon;
+var log = console.log;
+
beforeEach(function () {
- sinon.stub(console, 'error');
- sinon.stub(console, 'log');
+ if (process.env.DEBUG) {
+ sinon.spy(console, 'error');
+ sinon.spy(console, 'log');
+ } else {
+ sinon.stub(console, 'error');
+ sinon.stub(console, 'log', function (a, b, c) {
+ if (typeof a === 'string' && a.indexOf('\u001b') !== -1 && typeof b === 'string') {
+ log.apply(console, arguments);
+ }
+ });
+ }
});
afterEach(function () {
diff --git a/test/functions/sendgrid.test.js b/test/functions/sendgrid.test.js
deleted file mode 100644
index 470e5013b3..0000000000
--- a/test/functions/sendgrid.test.js
+++ /dev/null
@@ -1,616 +0,0 @@
-// Copyright 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 proxyquire = require('proxyquire').noCallThru();
-var util = require('util');
-var EventEmitter = require('events');
-
-var method = 'POST';
-var key = 'sengrid_key';
-var to = 'receiver@email.com';
-var from = 'sender@email.com';
-var subject = 'subject';
-var body = 'body';
-var auth = 'Basic Zm9vOmJhcg==';
-var events = [
- {
- sg_message_id: 'sendgrid_internal_message_id',
- email: 'john.doe@sendgrid.com',
- timestamp: 1337197600,
- 'smtp-id': '<4FB4041F.6080505@sendgrid.com>',
- event: 'processed'
- },
- {
- sg_message_id: 'sendgrid_internal_message_id',
- email: 'john.doe@sendgrid.com',
- timestamp: 1337966815,
- category: 'newuser',
- event: 'click',
- url: 'https://sendgrid.com'
- },
- {
- sg_message_id: 'sendgrid_internal_message_id',
- email: 'john.doe@sendgrid.com',
- timestamp: 1337969592,
- 'smtp-id': '<20120525181309.C1A9B40405B3@Example-Mac.local>',
- event: 'group_unsubscribe',
- asm_group_id: 42
- }
-];
-
-function getSample () {
- var config = {
- EVENT_BUCKET: 'event-bucket',
- DATASET: 'datasets',
- TABLE: 'events',
- USERNAME: 'foo',
- PASSWORD: 'bar'
- };
- var request = {};
- var client = {
- API: sinon.stub().callsArgWith(1, {
- statusCode: 200,
- body: 'success',
- headers: {
- 'content-type': 'application/json',
- 'content-length': 10
- }
- }),
- emptyRequest: sinon.stub().returns(request)
- };
- var mail = {
- toJSON: sinon.stub()
- };
- var file = {
- save: sinon.stub().callsArg(1)
- };
- var bucket = {
- file: sinon.stub().returns(file)
- };
- var storage = {
- bucket: sinon.stub().returns(bucket)
- };
- function Job () {}
- util.inherits(Job, EventEmitter);
- var job = new Job();
- var table = {};
- table.get = sinon.stub().callsArgWith(1, null, table);
- table.import = sinon.stub().callsArgWith(2, null, job, {});
- var dataset = {
- table: sinon.stub().returns(table)
- };
- dataset.get = sinon.stub().callsArgWith(1, null, dataset);
- var bigquery = {
- dataset: sinon.stub().returns(dataset)
- };
- var gcloud = {
- bigquery: sinon.stub().returns(bigquery),
- storage: sinon.stub().returns(storage)
- };
- var sendgrid = {
- SendGrid: sinon.stub().returns(client),
- mail: {
- Mail: sinon.stub().returns(mail),
- Email: sinon.stub(),
- Content: sinon.stub()
- }
- };
- var uuid = {
- v4: sinon.stub()
- };
- return {
- sample: proxyquire('../../functions/sendgrid', {
- sendgrid: sendgrid,
- gcloud: gcloud,
- './config.json': config,
- 'node-uuid': uuid
- }),
- mocks: {
- sendgrid: sendgrid,
- client: client,
- mail: mail,
- request: request,
- bucket: bucket,
- file: file,
- storage: storage,
- bigquery: bigquery,
- dataset: dataset,
- table: table,
- config: config,
- uuid: uuid,
- job: job
- }
- };
-}
-
-function getMocks () {
- var req = {
- headers: {},
- query: {},
- body: {},
- get: function (header) {
- return this.headers[header];
- }
- };
- sinon.spy(req, 'get');
- var res = {
- headers: {},
- send: sinon.stub().returnsThis(),
- json: sinon.stub().returnsThis(),
- end: sinon.stub().returnsThis(),
- status: function (statusCode) {
- this.statusCode = statusCode;
- return this;
- },
- set: function (header, value) {
- this.headers[header] = value;
- return this;
- }
- };
- sinon.spy(res, 'status');
- sinon.spy(res, 'set');
- return {
- req: req,
- res: res
- };
-}
-
-function getMockContext () {
- return {
- done: sinon.stub(),
- success: sinon.stub(),
- failure: sinon.stub()
- };
-}
-
-describe('functions:sendgrid', function () {
- it('Send fails if not a POST request', function () {
- var expectedMsg = 'Only POST requests are accepted';
- var mocks = getMocks();
-
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 405);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Send fails without an API key', function () {
- var expectedMsg = 'SendGrid API key not provided. Make sure you have a ' +
- '"sg_key" property in your request querystring';
- var mocks = getMocks();
-
- mocks.req.method = method;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 401);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Send fails without a "to"', function () {
- var expectedMsg = 'To email address not provided. Make sure you have a ' +
- '"to" property in your request';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 400);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Send fails without a "from"', function () {
- var expectedMsg = 'From email address not provided. Make sure you have a ' +
- '"from" property in your request';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 400);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Send fails without a "subject"', function () {
- var expectedMsg = 'Email subject line not provided. Make sure you have a ' +
- '"subject" property in your request';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 400);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Send fails without a "body"', function () {
- var expectedMsg = 'Email content not provided. Make sure you have a ' +
- '"body" property in your request';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- mocks.req.body.subject = subject;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 400);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Sends the email and successfully responds', function () {
- var expectedMsg = 'success';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- mocks.req.body.subject = subject;
- mocks.req.body.body = body;
- getSample().sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 200);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- });
-
- it('Handles response error', function () {
- var expectedMsg = 'failure';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- mocks.req.body.subject = subject;
- mocks.req.body.body = body;
-
- var sendgridSample = getSample();
- sendgridSample.mocks.client.API = sinon.stub().callsArgWith(1, {
- statusCode: 400,
- body: 'failure',
- headers: {}
- });
- sendgridSample.sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 400);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- });
-
- it('Handles thrown error', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- mocks.req.body.subject = subject;
- mocks.req.body.body = body;
-
- var sendgridSample = getSample();
- sendgridSample.mocks.mail.toJSON = sinon.stub().throws('TypeError');
- sendgridSample.sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 500);
- assert.equal(mocks.res.send.calledOnce, true);
- });
-
- it('Handles emtpy response body', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.query.sg_key = key;
- mocks.req.body.to = to;
- mocks.req.body.from = from;
- mocks.req.body.subject = subject;
- mocks.req.body.body = body;
-
- var sendgridSample = getSample();
- sendgridSample.mocks.client.API = sinon.stub().callsArgWith(1, {
- statusCode: 200,
- headers: {}
- });
- sendgridSample.sample.sendgridEmail(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 200);
- assert.equal(mocks.res.send.calledOnce, false);
- });
-
- it('Send fails if not a POST request', function () {
- var expectedMsg = 'Only POST requests are accepted';
- var mocks = getMocks();
-
- getSample().sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 405);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Throws if no basic auth', function () {
- var expectedMsg = 'Invalid credentials';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.headers.authorization = '';
- getSample().sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 401);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Throws if invalid username', function () {
- var expectedMsg = 'Invalid credentials';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.headers.authorization = 'Basic d3Jvbmc6YmFy';
- getSample().sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 401);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Throws if invalid password', function () {
- var expectedMsg = 'Invalid credentials';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.headers.authorization = 'Basic Zm9vOndyb25n';
- getSample().sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 401);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Calls "end" if no events', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.headers.authorization = auth;
- mocks.req.body = undefined;
- getSample().sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 200);
- assert.equal(mocks.res.send.called, false);
- assert.equal(mocks.res.end.calledOnce, true);
- });
-
- it('Saves files', function () {
- var mocks = getMocks();
-
- mocks.req.method = 'POST';
- mocks.req.headers.authorization = auth;
- mocks.req.body = events;
- var sendgridSample = getSample();
- sendgridSample.mocks.uuid.v4 = sinon.stub().returns('1357');
- sendgridSample.sample.sendgridWebhook(mocks.req, mocks.res);
-
- var filename = sendgridSample.mocks.bucket.file.firstCall.args[0];
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 200);
- assert.equal(mocks.res.end.calledOnce, true);
- assert.equal(console.log.calledWith('Saving events to ' + filename + ' in bucket ' + sendgridSample.mocks.config.EVENT_BUCKET), true);
- assert.equal(console.log.calledWith('JSON written to ' + filename), true);
- });
-
- it('Handles save error', function () {
- var expectedMsg = 'save_error';
- var mocks = getMocks();
-
- mocks.req.method = 'POST';
- mocks.req.headers.authorization = auth;
- mocks.req.body = events;
- var sendgridSample = getSample();
- sendgridSample.mocks.uuid.v4 = sinon.stub().returns('2468');
- sendgridSample.mocks.file.save = sinon.stub().callsArgWith(1, expectedMsg);
- sendgridSample.sample.sendgridWebhook(mocks.req, mocks.res);
-
- var filename = sendgridSample.mocks.bucket.file.firstCall.args[0];
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 500);
- assert.equal(mocks.res.end.calledOnce, true);
- assert.equal(console.log.calledWith('Saving events to ' + filename + ' in bucket ' + sendgridSample.mocks.config.EVENT_BUCKET), true);
- assert.equal(console.error.calledWith(expectedMsg), true);
- });
-
- it('Handles random error', function () {
- var expectedMsg = 'random_error';
- var mocks = getMocks();
-
- mocks.req.method = 'POST';
- mocks.req.headers.authorization = auth;
- mocks.req.body = events;
- var sendgridSample = getSample();
- sendgridSample.mocks.uuid.v4 = sinon.stub().throws(new Error(expectedMsg));
- sendgridSample.sample.sendgridWebhook(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 500);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- });
-
- it('sendgridLoad does nothing on delete', function () {
- var context = getMockContext();
-
- getSample().sample.sendgridLoad(context, {
- timeDeleted: 1234
- });
-
- assert.equal(context.done.calledOnce, true);
- assert.equal(context.failure.called, false);
- assert.equal(context.success.called, false);
- });
-
- it('sendgridLoad fails without a bucket', function () {
- var expectedMsg = 'Bucket not provided. Make sure you have a ' +
- '"bucket" property in your request';
- var context = getMockContext();
-
- getSample().sample.sendgridLoad(context, {});
-
- assert.equal(context.failure.calledOnce, true);
- assert.equal(context.failure.firstCall.args[0], expectedMsg);
- assert.equal(context.success.called, false);
- assert(console.error.called);
- });
-
- it('sendgridLoad fails without a name', function () {
- var expectedMsg = 'Filename not provided. Make sure you have a ' +
- '"name" property in your request';
- var context = getMockContext();
-
- getSample().sample.sendgridLoad(context, {
- bucket: 'event-bucket'
- });
-
- assert.equal(context.failure.calledOnce, true);
- assert.equal(context.failure.firstCall.args[0], expectedMsg);
- assert.equal(context.success.called, false);
- assert(console.error.called);
- });
-
- it('starts a load job', function (done) {
- var name = '1234.json';
- var context = {
- success: function () {
- assert.equal(console.log.calledWith('Starting job for ' + name), true);
- assert.equal(console.log.calledWith('Job complete for ' + name), true);
- done();
- },
- failure: assert.fail
- };
-
- var sendgridSample = getSample();
- sendgridSample.sample.sendgridLoad(context, {
- bucket: 'event-bucket',
- name: name
- });
-
- setTimeout(function () {
- sendgridSample.mocks.job.emit('complete', {});
- }, 10);
- });
-
- it('handles job failure', function (done) {
- var name = '1234.json';
- var error = 'job_error';
- var context = {
- success: assert.fail,
- failure: function (msg) {
- assert.equal(msg, error);
- assert.equal(console.log.calledWith('Starting job for ' + name), true);
- assert.equal(console.error.calledWith('Job failed for ' + name), true);
- assert.equal(console.error.calledWith(error), true);
- done();
- }
- };
-
- var sendgridSample = getSample();
- sendgridSample.sample.sendgridLoad(context, {
- bucket: 'event-bucket',
- name: name
- });
- sendgridSample.mocks.job.on('error', function (err) {
- assert.equal(err, error);
- });
- setTimeout(function () {
- sendgridSample.mocks.job.emit('error', error);
- }, 10);
- });
-
- it('handles dataset error', function (done) {
- var name = '1234.json';
- var error = 'dataset_error';
- var context = {
- success: assert.fail,
- failure: function (msg) {
- assert.equal(msg, error);
- assert.equal(console.error.calledWith(error), true);
- done();
- }
- };
-
- var sendgridSample = getSample();
- sendgridSample.mocks.dataset.get = sinon.stub().callsArgWith(1, error);
- sendgridSample.sample.sendgridLoad(context, {
- bucket: 'event-bucket',
- name: name
- });
- });
-
- it('handles table error', function (done) {
- var name = '1234.json';
- var error = 'table_error';
- var context = {
- success: assert.fail,
- failure: function (msg) {
- assert.equal(msg, error);
- assert.equal(console.error.calledWith(error), true);
- done();
- }
- };
-
- var sendgridSample = getSample();
- sendgridSample.mocks.table.get = sinon.stub().callsArgWith(1, error);
- sendgridSample.sample.sendgridLoad(context, {
- bucket: 'event-bucket',
- name: name
- });
- });
-});
diff --git a/test/functions/slack.test.js b/test/functions/slack.test.js
deleted file mode 100644
index 2d2ead804b..0000000000
--- a/test/functions/slack.test.js
+++ /dev/null
@@ -1,228 +0,0 @@
-// Copyright 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 proxyquire = require('proxyquire').noCallThru();
-
-var method = 'POST';
-var query = 'giraffe';
-var SLACK_TOKEN = 'slack-token';
-var KG_API_KEY = 'kg-api-key';
-
-function getSample () {
- var config = {
- SLACK_TOKEN: SLACK_TOKEN,
- KG_API_KEY: KG_API_KEY
- };
- var kgsearch = {
- entities: {
- search: sinon.stub().callsArg(1)
- }
- };
- var googleapis = {
- kgsearch: sinon.stub().returns(kgsearch)
- };
- return {
- sample: proxyquire('../../functions/slack', {
- googleapis: googleapis,
- './config.json': config
- }),
- mocks: {
- googleapis: googleapis,
- kgsearch: kgsearch,
- config: config
- }
- };
-}
-
-function getMocks () {
- var req = {
- headers: {},
- query: {},
- body: {},
- get: function (header) {
- return this.headers[header];
- }
- };
- sinon.spy(req, 'get');
- var res = {
- headers: {},
- send: sinon.stub().returnsThis(),
- json: sinon.stub().returnsThis(),
- end: sinon.stub().returnsThis(),
- status: function (statusCode) {
- this.statusCode = statusCode;
- return this;
- },
- set: function (header, value) {
- this.headers[header] = value;
- return this;
- }
- };
- sinon.spy(res, 'status');
- sinon.spy(res, 'set');
- return {
- req: req,
- res: res
- };
-}
-
-describe('functions:slack', function () {
- it('Send fails if not a POST request', function () {
- var expectedMsg = 'Only POST requests are accepted';
- var mocks = getMocks();
-
- getSample().sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 405);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Throws if invalid slack token', function () {
- var expectedMsg = 'Invalid credentials';
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.body.token = 'wrong';
- var slackSample = getSample();
- slackSample.sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 401);
- assert.equal(mocks.res.send.calledOnce, true);
- assert.equal(mocks.res.send.firstCall.args[0], expectedMsg);
- assert(console.error.called);
- });
-
- it('Handles search error', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.body.token = SLACK_TOKEN;
- mocks.req.body.text = query;
- var slackSample = getSample();
- slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, 'error');
- slackSample.sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.calledOnce, true);
- assert.equal(mocks.res.status.firstCall.args[0], 500);
- assert.equal(mocks.res.send.called, false);
- assert(console.error.calledWith('error'));
- });
-
- it('Makes search request, receives empty results', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.body.token = SLACK_TOKEN;
- mocks.req.body.text = query;
- var slackSample = getSample();
- slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, {
- itemListElement: []
- });
- slackSample.sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.called, false);
- assert.equal(mocks.res.json.called, true);
- assert.deepEqual(mocks.res.json.firstCall.args[0], {
- text: 'Query: ' + query,
- response_type: 'in_channel',
- attachments: [
- {
- text: 'No results match your query...'
- }
- ]
- });
- });
-
- it('Makes search request, receives non-empty results', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.body.token = SLACK_TOKEN;
- mocks.req.body.text = query;
- var slackSample = getSample();
- slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, {
- itemListElement: [
- {
- result: {
- name: 'Giraffe',
- description: 'Animal',
- detailedDescription: {
- url: 'http://domain.com/giraffe',
- articleBody: 'giraffe is a tall animal'
- },
- image: {
- contentUrl: 'http://domain.com/image.jpg'
- }
- }
- }
- ]
- });
- slackSample.sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.called, false);
- assert.equal(mocks.res.json.called, true);
- assert.deepEqual(mocks.res.json.firstCall.args[0], {
- text: 'Query: ' + query,
- response_type: 'in_channel',
- attachments: [
- {
- color: '#3367d6',
- title: 'Giraffe: Animal',
- title_link: 'http://domain.com/giraffe',
- text: 'giraffe is a tall animal',
- image_url: 'http://domain.com/image.jpg'
- }
- ]
- });
- });
-
- it('Makes search request, receives non-empty results but partial data', function () {
- var mocks = getMocks();
-
- mocks.req.method = method;
- mocks.req.body.token = SLACK_TOKEN;
- mocks.req.body.text = query;
- var slackSample = getSample();
- slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, {
- itemListElement: [
- {
- result: {
- name: 'Giraffe',
- detailedDescription: {},
- image: {}
- }
- }
- ]
- });
- slackSample.sample.kgSearch(mocks.req, mocks.res);
-
- assert.equal(mocks.res.status.called, false);
- assert.equal(mocks.res.json.called, true);
- assert.deepEqual(mocks.res.json.firstCall.args[0], {
- text: 'Query: ' + query,
- response_type: 'in_channel',
- attachments: [
- {
- color: '#3367d6',
- title: 'Giraffe'
- }
- ]
- });
- });
-});
diff --git a/test/nodejs-docs-samples.json b/test/nodejs-docs-samples.json
new file mode 100644
index 0000000000..260a1d9018
--- /dev/null
+++ b/test/nodejs-docs-samples.json
@@ -0,0 +1,11 @@
+{
+ "type": "service_account",
+ "private_key_id": "470884f0ef61d053e3cd4ce378bbfd835edb1a07",
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCCEopQnNDvfrLm\n8zS1JuXYozP5y6pJRzo3o+8jvzgntTstnamo5lwzjJ8Ebg12DzzpF/Yk57Z1srZ4\nR8knpUcI4roSTbUC0FJ2s3DZpD7nXSucWhjzUKowquPzxwqqmSeCK5oVeI8Q9chU\n+g4CV4OPfHhHqsebtAKKmhpZRmO5rY8P1lyAD4+0IhxIJ6pAemByS6iI6zrGQypt\nuZykb7qTBCglS2bmx5842TAleU8VoNO5zixHkm3vdaP4X8V1PA0WEqNpgXOs/VBe\n73G0SMb5QmlGJpEhYV5fRf4iSnASdD58n9RUINO28GuX++tI4d9J+UJWG8AJ3h8a\nUjyrw/sHAgMBAAECggEAIs9Zatd85wtOT5Z43Z4qVv7eUxSZXwEL6IYb4sIzAhVz\nX/LYy9XSiQ0yJVpaieTsFSmPezLz1q3cPXZgtBZ8WzlqOKnJLpaX6yJ8qhJVr090\n82P9V2iYE2w4ky4Kgbt5IlIO634XM5/DXFKLWz8We1kBS5S91MKpB3TUZl37JF6T\ndIzHD9u3mivu9OykSMiIdh+t+Ua0c9YkZa3g+Ev6Oz+cyvVvKkpk9+4bmfNMgAeR\nZnggqfFA8AJBaxIATxhfwSMzg0+TlqcVcOWymKpTq56BwCxoNwipJAQ/eAmNrQx0\npqJtBalCIb2BLREl8pu2MmUZpoIbxWz6vxcI2hFRuQKBgQD1Zzc6GrP8FEPfQrYB\nF+Zzxr/4aTRDbJO4w9oe0MucOLPCX/uKeymA67gFZOtj6pulmqbZDR2yX/vgEtUu\nQ30lKl0b/knhP/oUufCiuRAbpAs4Lr7iNqL3wf9Twf8PPijTBCLLt+3G9G7TCNNX\nXIlFt6mmFQ/FAGyYXu/SSSAoRQKBgQCHsGmaC4W1bjgatUJaGaJXgOiXItfL8soF\nHYrpna4nJqG54SDykQxfgvzjWPP/LKdsasScMWSe0SeveNao3mRxHbc959n0VS6c\nbl/7VVphmC39qN3rjp2HKxIoDvrEuvuvnkbFQ0L6JlzyTUvirCSgUDc7+/taBSfm\nvmT4gWfo2wKBgCIAAu7R9E3goOa133GXVh6EUuSf7tXInU7kE7xhQVSLppwvoDI3\njjCGeCCHMvXM83OmUaeQ4aRtGACbm12ljBkyHWRbfvDuZD+q42QoL8skl0lZcKj2\n2O1qu21nW2dJPW6/C/MdsJv4EcK7XkykTYCTSbXxBRZOUL1rqd6AsyvhAoGAPfe5\nIprkg4lEoh3poZBXbbL3hh5pg0DsNg3Z5PsYD9U6wtMn4t+PUQdXStTTCdRw2big\n9dww4b8Parm6/wAhyu8RQnpiNY25bcOSngvK7Qs85b17LBrDonlvH1BIAhSK4Rdd\nprUjH27pv9bBM1H+oCBCOWjIz8HPCTgmkL84n0UCgYEA3q6kHdZ8cUylqyxhPVJl\nhFHkcBGBi6TtB9Wf/598j7YngWs4zzSSzTI43WbyUIb0AV0PHf1vR+mE5rTXSkpB\n2EQ1Ib118wpJyqRpRsU3LQN9o5dSxkph8v3SbaJ0RMucGfEurlnf+cn8aAIsMQIY\n098xMEJX/lAV9yUcSsNntps=\n-----END PRIVATE KEY-----\n",
+ "client_email": "nodejs-docs-samples@nodejs-docs-samples.iam.gserviceaccount.com",
+ "client_id": "115921358357598048620",
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
+ "token_uri": "https://accounts.google.com/o/oauth2/token",
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/nodejs-docs-samples%40nodejs-docs-samples.iam.gserviceaccount.com"
+}
diff --git a/test/encrypted/nodejs-docs-samples.json.enc b/test/nodejs-docs-samples.json.enc
similarity index 100%
rename from test/encrypted/nodejs-docs-samples.json.enc
rename to test/nodejs-docs-samples.json.enc
diff --git a/trace/package.json b/trace/package.json
index f9502f98f4..2238142250 100644
--- a/trace/package.json
+++ b/trace/package.json
@@ -1,19 +1,22 @@
{
- "name": "stackdriver-trace",
- "description": "StackDriver Trace sample for Node.js",
+ "name": "nodejs-docs-samples-trace",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
- "node": "~6"
+ "node": "~4.2"
},
"scripts": {
- "start": "node app.js"
+ "start": "node app.js",
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js"
},
"dependencies": {
"@google/cloud-trace": "^0.5.3",
"express": "^4.13.4",
"request": "^2.72.0"
+ },
+ "devDependencies": {
+ "mocha": "^2.5.3"
}
}
diff --git a/trace/test/app.test.js b/trace/test/app.test.js
new file mode 100644
index 0000000000..eb9fd1230e
--- /dev/null
+++ b/trace/test/app.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('trace', function () {
+ it('should be tested');
+});
diff --git a/vision/package.json b/vision/package.json
index d351ae9523..573136685a 100644
--- a/vision/package.json
+++ b/vision/package.json
@@ -1,18 +1,22 @@
{
- "name": "cloud-vision-samples",
- "description": "Node.js samples for Google Cloud Vision.",
+ "name": "nodejs-docs-samples-vision",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
- "engines": {
- "node": ">=0.10.x"
+ "author": "Google Inc.",
+ "scripts": {
+ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../test/_setup.js test/*.test.js",
+ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"async": "^1.5.0",
- "gcloud": "^0.32.0",
+ "gcloud": "^0.37.0",
"natural": "^0.4.0",
"redis": "^2.6.0-2"
},
+ "devDependencies": {
+ "mocha": "^2.5.3"
+ },
"optionalDependencies": {
"canvas": "^1.3.15"
}
diff --git a/test/vision/faceDetection.test.js b/vision/system-test/faceDetection.test.js
similarity index 93%
rename from test/vision/faceDetection.test.js
rename to vision/system-test/faceDetection.test.js
index f464fa722b..b19659e22e 100644
--- a/test/vision/faceDetection.test.js
+++ b/vision/system-test/faceDetection.test.js
@@ -44,8 +44,8 @@ function MockCanvas () {
MockCanvas.Image = function () {};
-var faceDetectionExample = require('../../vision/faceDetection');
-var inputFile = path.join(__dirname, '../../vision/resources', 'face.png');
+var faceDetectionExample = require('../faceDetection');
+var inputFile = path.join(__dirname, '../resources', 'face.png');
var outputFile = path.join(__dirname, '../../vision', 'out.png');
describe('vision:faceDetection', function () {
diff --git a/test/vision/labelDetection.test.js b/vision/system-test/labelDetection.test.js
similarity index 87%
rename from test/vision/labelDetection.test.js
rename to vision/system-test/labelDetection.test.js
index ab237b46f5..0446196f72 100644
--- a/test/vision/labelDetection.test.js
+++ b/vision/system-test/labelDetection.test.js
@@ -14,8 +14,8 @@
'use strict';
var path = require('path');
-var labelDetectionSample = require('../../vision/labelDetection');
-var inputFile = path.join(__dirname, '../../vision/resources', 'cat.jpg');
+var labelDetectionSample = require('../labelDetection');
+var inputFile = path.join(__dirname, '../resources', 'cat.jpg');
describe('vision:labelDetection', function () {
it('should detect labels', function (done) {
diff --git a/test/vision/landmarkDetection.test.js b/vision/system-test/landmarkDetection.test.js
similarity index 93%
rename from test/vision/landmarkDetection.test.js
rename to vision/system-test/landmarkDetection.test.js
index c3e91419d7..028e98097a 100644
--- a/test/vision/landmarkDetection.test.js
+++ b/vision/system-test/landmarkDetection.test.js
@@ -13,7 +13,7 @@
'use strict';
-var landmarkDetectionSample = require('../../vision/landmarkDetection');
+var landmarkDetectionSample = require('../landmarkDetection');
var inputFile = 'https://cloud-samples-tests.storage.googleapis.com/vision/water.jpg';
describe('vision:landmarkDetection', function () {
diff --git a/test/vision/textDetection.test.js b/vision/system-test/textDetection.test.js
similarity index 89%
rename from test/vision/textDetection.test.js
rename to vision/system-test/textDetection.test.js
index 9d8c04a7ef..0b38faf861 100644
--- a/test/vision/textDetection.test.js
+++ b/vision/system-test/textDetection.test.js
@@ -14,8 +14,8 @@
'use strict';
var path = require('path');
-var inputDir = path.join(__dirname, '../../vision/resources');
-var textDetectionSample = require('../../vision/textDetection');
+var inputDir = path.join(__dirname, '../resources');
+var textDetectionSample = require('../textDetection');
describe('vision:textDetection', function () {
it('should detect texts', function (done) {
diff --git a/vision/test/faceDetection.test.js b/vision/test/faceDetection.test.js
new file mode 100644
index 0000000000..733f2772c5
--- /dev/null
+++ b/vision/test/faceDetection.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('vision:faceDetection', function () {
+ it('should be tested');
+});
diff --git a/vision/test/labelDetection.test.js b/vision/test/labelDetection.test.js
new file mode 100644
index 0000000000..ee2c3d21e1
--- /dev/null
+++ b/vision/test/labelDetection.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('vision:labelDetection', function () {
+ it('should be tested');
+});
diff --git a/vision/test/landmarkDetection.test.js b/vision/test/landmarkDetection.test.js
new file mode 100644
index 0000000000..145bc1f1bb
--- /dev/null
+++ b/vision/test/landmarkDetection.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('vision:landmarkDetection', function () {
+ it('should be tested');
+});
diff --git a/vision/test/textDetection.test.js b/vision/test/textDetection.test.js
new file mode 100644
index 0000000000..3093afb079
--- /dev/null
+++ b/vision/test/textDetection.test.js
@@ -0,0 +1,18 @@
+// Copyright 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';
+
+describe('vision:textDetection', function () {
+ it('should be tested');
+});