Skip to content

Commit

Permalink
Fix docs-samples tests, round 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri authored and jmdobry committed Aug 23, 2017
1 parent 2ab74db commit 14f677d
Show file tree
Hide file tree
Showing 61 changed files with 380 additions and 166 deletions.
4 changes: 2 additions & 2 deletions appengine/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"e2e-test": "samples test deploy"
},
"dependencies": {
"express": "4.15.3",
"express": "4.15.4",
"got": "7.1.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.16"
"@google-cloud/nodejs-repo-tools": "1.4.17"
},
"cloud-repo-tools": {
"test": {
Expand Down
4 changes: 2 additions & 2 deletions appengine/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
},
"dependencies": {
"@google-cloud/datastore": "1.1.0",
"express": "4.15.3"
"express": "4.15.4"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.16"
"@google-cloud/nodejs-repo-tools": "1.4.17"
},
"cloud-repo-tools": {
"test": {
Expand Down
2 changes: 1 addition & 1 deletion appengine/endpoints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"body-parser": "1.17.2",
"express": "4.15.3",
"express": "4.15.4",
"safe-buffer": "5.1.1"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions appengine/errorreporting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
},
"dependencies": {
"@google-cloud/error-reporting": "0.2.1",
"express": "4.15.3"
"express": "4.15.4"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.16",
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.21.0",
"proxyquire": "1.8.0",
"sinon": "3.0.0"
"sinon": "3.2.0"
},
"cloud-repo-tools": {
"test": {
Expand Down
4 changes: 2 additions & 2 deletions appengine/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"e2e-test": "samples test deploy"
},
"dependencies": {
"express": "4.15.3"
"express": "4.15.4"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.16"
"@google-cloud/nodejs-repo-tools": "1.4.17"
},
"cloud-repo-tools": {
"test": {
Expand Down
4 changes: 2 additions & 2 deletions appengine/mailjet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
},
"dependencies": {
"body-parser": "1.17.2",
"express": "4.15.3",
"express": "4.15.4",
"jade": "1.11.0",
"node-mailjet": "3.2.1"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.16"
"@google-cloud/nodejs-repo-tools": "1.4.17"
},
"cloud-repo-tools": {
"test": {
Expand Down
27 changes: 25 additions & 2 deletions appengine/mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,31 @@
"engines": {
"node": ">=4.3.2"
},
"scripts": {
"start": "node server.js",
"test": "samples test app"
},
"cloud-repo-tools": {
"test": {
"app": {
"requiredEnvVars": [
"mongoHost",
"mongoPort",
"mongoUser",
"mongoPassword"
],
"msg": "IPs:\n::1;",
"args": [
"server.js"
]
}
}
},
"dependencies": {
"nconf": "0.8.4",
"mongodb": "2.2.22"
"mongodb": "2.2.31",
"nconf": "0.8.4"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^1.4.16"
}
}
3 changes: 0 additions & 3 deletions appengine/mongodb/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ const port = nconf.get('mongoPort');

// [START client]
let uri = `mongodb://${user}:${pass}@${host}:${port}`;

if (nconf.get('mongoDatabase')) {
uri = `${uri}/${nconf.get('mongoDatabase')}`;
}

console.log(uri);

mongodb.MongoClient.connect(uri, (err, db) => {
if (err) {
throw err;
Expand Down
4 changes: 2 additions & 2 deletions appengine/pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Before you can run or deploy the sample, you will need to do the following:
1. Enable the Cloud Pub/Sub API in the [Google Developers Console](https://console.developers.google.com/project/_/apiui/apiview/pubsub/overview).
1. Create a topic and subscription.

gcloud alpha pubsub topics create <your-topic-name>
gcloud alpha pubsub subcriptions create <your-subscription-name> \
gcloud beta pubsub topics create <your-topic-name>
gcloud beta pubsub subcriptions create <your-subscription-name> \
--topic <your-topic-name> \
--push-endpoint \
https://<your-project-id>.appspot.com/pubsub/push?token=<your-verification-token> \
Expand Down
5 changes: 5 additions & 0 deletions appengine/pubsub/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const Buffer = require('safe-buffer').Buffer;
const process = require('process'); // Required for mocking environment variables

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
Expand All @@ -32,6 +34,7 @@ const pubsub = PubSub();

const app = express();
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));

const formBodyParser = bodyParser.urlencoded({ extended: false });
const jsonBodyParser = bodyParser.json();
Expand Down Expand Up @@ -91,3 +94,5 @@ app.listen(PORT, () => {
console.log('Press Ctrl+C to quit.');
});
// [END app]

module.exports = app;
4 changes: 2 additions & 2 deletions appengine/pubsub/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ env: flex

# [START env]
env_variables:
PUBSUB_TOPIC: <your-topic-name>
PUBSUB_TOPIC: YOUR_TOPIC_NAME
# This token is used to verify that requests originate from your
# application. It can be any sufficiently random string.
PUBSUB_VERIFICATION_TOKEN: <your-verification-token>
PUBSUB_VERIFICATION_TOKEN: YOUR_VERIFICATION_TOKEN
# [END env]
# [END app_yaml]
28 changes: 22 additions & 6 deletions appengine/pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@
"node": ">=4.3.2"
},
"scripts": {
"start": "node app.js"
"start": "node app.js",
"test": "samples test app && ava -T 30s */*.test.js"
},
"dependencies": {
"@google-cloud/pubsub": "0.8.0",
"body-parser": "1.16.0",
"express": "4.14.1",
"pug": "2.0.0-beta6",
"safe-buffer": "5.0.1"
"@google-cloud/pubsub": "0.13.2",
"body-parser": "1.17.2",
"express": "4.15.4",
"pug": "2.0.0-rc.3",
"safe-buffer": "5.1.1"
},
"devDependencies": {
"uuid": "3.1.0"
},
"cloud-repo-tools": {
"test": {
"app": {
"requiredEnvVars": [
"PUBSUB_TOPIC",
"PUBSUB_VERIFICATION_TOKEN"
],
"msg": "Messages received by this instance",
"substitutions": "YOUR_TOPIC_NAME=$PUBSUB_TOPIC,YOUR_VERIFICATION_TOKEN=$PUBSUB_VERIFICATION_TOKEN"
}
}
}
}
72 changes: 72 additions & 0 deletions appengine/pubsub/test/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2017, 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.

// NOTE:
// This app can only be fully tested when deployed, because
// Pub/Sub requires a live endpoint URL to hit. Nevertheless,
// these tests mock it and partially test it locally.

'use strict';

const test = require(`ava`);
const path = require(`path`);
const utils = require(`@google-cloud/nodejs-repo-tools`);

const message = `This is a test message sent at: `;
const payload = message + Date.now();

const cwd = path.join(__dirname, `../`);
const requestObj = utils.getRequest({ cwd: cwd });

test.serial.cb(`should send a message to Pub/Sub`, (t) => {
requestObj
.post(`/`)
.type('form')
.send({ payload: payload })
.expect(200)
.expect((response) => {
t.is(response.text, `Message sent`);
})
.end(t.end);
});

test.serial.cb(`should receive incoming Pub/Sub messages`, (t) => {
requestObj
.post(`/pubsub/push`)
.query({ token: process.env.PUBSUB_VERIFICATION_TOKEN })
.send({
message: {
data: payload
}
})
.expect(200)
.end(t.end);
});

test.serial.cb(`should check for verification token on incoming Pub/Sub messages`, (t) => {
requestObj
.post(`/pubsub/push`)
.field(`payload`, payload)
.expect(400)
.end(t.end);
});

test.serial.cb(`should list sent Pub/Sub messages`, (t) => {
requestObj
.get(`/`)
.expect(200)
.expect((response) => {
t.regex(response.text, /Messages received by this instance/);
})
.end(t.end);
});
18 changes: 15 additions & 3 deletions appengine/static-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@
"node": ">=4.3.2"
},
"scripts": {
"start": "node app.js"
"start": "node app.js",
"test": "samples test app --url localhost:8080/static/main.css"
},
"cloud-repo-tools": {
"test": {
"app": {
"msg": "background-color",
"port": 8080
}
}
},
"dependencies": {
"express": "4.14.1",
"pug": "2.0.0-beta6"
"express": "4.15.4",
"pug": "2.0.0-rc.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17"
}
}
5 changes: 5 additions & 0 deletions appengine/storage/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
const format = require('util').format;
const express = require('express');
const Multer = require('multer');
const bodyParser = require('body-parser');
const process = require('process'); // Required to mock environment variables

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
Expand All @@ -32,6 +34,7 @@ const storage = Storage();

const app = express();
app.set('view engine', 'pug');
app.use(bodyParser.json());

// [START config]
// Multer is required to process file uploads and make them available via
Expand Down Expand Up @@ -86,3 +89,5 @@ app.listen(PORT, () => {
console.log('Press Ctrl+C to quit.');
});
// [END app]

module.exports = app;
2 changes: 1 addition & 1 deletion appengine/storage/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ env: flex

# [START env]
env_variables:
GCLOUD_STORAGE_BUCKET: <your-bucket-name>
GCLOUD_STORAGE_BUCKET: YOUR_BUCKET_NAME
# [END env]
# [END app_yaml]
22 changes: 17 additions & 5 deletions appengine/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
"name": "appengine-storage",
"description": "Node.js Google Cloud Storage sample for Google App Engine",
"scripts": {
"start": "node app.js"
"start": "node app.js",
"test": "ava system-test/*.test.js -T 30s"
},
"engines": {
"node": ">=4.3.2"
},
"dependencies": {
"@google-cloud/storage": "0.7.0",
"body-parser": "1.16.0",
"express": "4.14.1",
"@google-cloud/storage": "1.2.1",
"body-parser": "1.17.2",
"express": "4.15.4",
"multer": "1.3.0",
"pug": "2.0.0-beta6"
"pug": "2.0.0-rc.3"
},
"cloud-repo-tools": {
"test": {
"app": {
"requiredEnvVars": [
"GCLOUD_STORAGE_BUCKET"
],
"msg": "<input type=\"file\" name=\"file\">",
"substitutions": "YOUR_BUCKET_NAME=$GCLOUD_STORAGE_BUCKET"
}
}
}
}
Loading

0 comments on commit 14f677d

Please sign in to comment.