Skip to content

Commit 14f677d

Browse files
Ace Nassrijmdobry
Ace Nassri
authored andcommitted
Fix docs-samples tests, round 1
1 parent 2ab74db commit 14f677d

File tree

61 files changed

+380
-166
lines changed

Some content is hidden

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

61 files changed

+380
-166
lines changed

appengine/analytics/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"e2e-test": "samples test deploy"
2323
},
2424
"dependencies": {
25-
"express": "4.15.3",
25+
"express": "4.15.4",
2626
"got": "7.1.0"
2727
},
2828
"devDependencies": {
29-
"@google-cloud/nodejs-repo-tools": "1.4.16"
29+
"@google-cloud/nodejs-repo-tools": "1.4.17"
3030
},
3131
"cloud-repo-tools": {
3232
"test": {

appengine/datastore/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
},
2424
"dependencies": {
2525
"@google-cloud/datastore": "1.1.0",
26-
"express": "4.15.3"
26+
"express": "4.15.4"
2727
},
2828
"devDependencies": {
29-
"@google-cloud/nodejs-repo-tools": "1.4.16"
29+
"@google-cloud/nodejs-repo-tools": "1.4.17"
3030
},
3131
"cloud-repo-tools": {
3232
"test": {

appengine/endpoints/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"dependencies": {
2727
"body-parser": "1.17.2",
28-
"express": "4.15.3",
28+
"express": "4.15.4",
2929
"safe-buffer": "5.1.1"
3030
},
3131
"devDependencies": {

appengine/errorreporting/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
},
2525
"dependencies": {
2626
"@google-cloud/error-reporting": "0.2.1",
27-
"express": "4.15.3"
27+
"express": "4.15.4"
2828
},
2929
"devDependencies": {
30-
"@google-cloud/nodejs-repo-tools": "1.4.16",
30+
"@google-cloud/nodejs-repo-tools": "1.4.17",
3131
"ava": "0.21.0",
3232
"proxyquire": "1.8.0",
33-
"sinon": "3.0.0"
33+
"sinon": "3.2.0"
3434
},
3535
"cloud-repo-tools": {
3636
"test": {

appengine/hello-world/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"e2e-test": "samples test deploy"
2323
},
2424
"dependencies": {
25-
"express": "4.15.3"
25+
"express": "4.15.4"
2626
},
2727
"devDependencies": {
28-
"@google-cloud/nodejs-repo-tools": "1.4.16"
28+
"@google-cloud/nodejs-repo-tools": "1.4.17"
2929
},
3030
"cloud-repo-tools": {
3131
"test": {

appengine/mailjet/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
},
2424
"dependencies": {
2525
"body-parser": "1.17.2",
26-
"express": "4.15.3",
26+
"express": "4.15.4",
2727
"jade": "1.11.0",
2828
"node-mailjet": "3.2.1"
2929
},
3030
"devDependencies": {
31-
"@google-cloud/nodejs-repo-tools": "1.4.16"
31+
"@google-cloud/nodejs-repo-tools": "1.4.17"
3232
},
3333
"cloud-repo-tools": {
3434
"test": {

appengine/mongodb/package.json

+25-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,31 @@
88
"engines": {
99
"node": ">=4.3.2"
1010
},
11+
"scripts": {
12+
"start": "node server.js",
13+
"test": "samples test app"
14+
},
15+
"cloud-repo-tools": {
16+
"test": {
17+
"app": {
18+
"requiredEnvVars": [
19+
"mongoHost",
20+
"mongoPort",
21+
"mongoUser",
22+
"mongoPassword"
23+
],
24+
"msg": "IPs:\n::1;",
25+
"args": [
26+
"server.js"
27+
]
28+
}
29+
}
30+
},
1131
"dependencies": {
12-
"nconf": "0.8.4",
13-
"mongodb": "2.2.22"
32+
"mongodb": "2.2.31",
33+
"nconf": "0.8.4"
34+
},
35+
"devDependencies": {
36+
"@google-cloud/nodejs-repo-tools": "^1.4.16"
1437
}
1538
}

appengine/mongodb/server.js

-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ const port = nconf.get('mongoPort');
3434

3535
// [START client]
3636
let uri = `mongodb://${user}:${pass}@${host}:${port}`;
37-
3837
if (nconf.get('mongoDatabase')) {
3938
uri = `${uri}/${nconf.get('mongoDatabase')}`;
4039
}
4140

42-
console.log(uri);
43-
4441
mongodb.MongoClient.connect(uri, (err, db) => {
4542
if (err) {
4643
throw err;

appengine/pubsub/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Before you can run or deploy the sample, you will need to do the following:
99
1. Enable the Cloud Pub/Sub API in the [Google Developers Console](https://console.developers.google.com/project/_/apiui/apiview/pubsub/overview).
1010
1. Create a topic and subscription.
1111

12-
gcloud alpha pubsub topics create <your-topic-name>
13-
gcloud alpha pubsub subcriptions create <your-subscription-name> \
12+
gcloud beta pubsub topics create <your-topic-name>
13+
gcloud beta pubsub subcriptions create <your-subscription-name> \
1414
--topic <your-topic-name> \
1515
--push-endpoint \
1616
https://<your-project-id>.appspot.com/pubsub/push?token=<your-verification-token> \

appengine/pubsub/app.js

+5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
const express = require('express');
2020
const bodyParser = require('body-parser');
21+
const path = require('path');
2122
const Buffer = require('safe-buffer').Buffer;
23+
const process = require('process'); // Required for mocking environment variables
2224

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

3335
const app = express();
3436
app.set('view engine', 'pug');
37+
app.set('views', path.join(__dirname, 'views'));
3538

3639
const formBodyParser = bodyParser.urlencoded({ extended: false });
3740
const jsonBodyParser = bodyParser.json();
@@ -91,3 +94,5 @@ app.listen(PORT, () => {
9194
console.log('Press Ctrl+C to quit.');
9295
});
9396
// [END app]
97+
98+
module.exports = app;

appengine/pubsub/app.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ env: flex
1717

1818
# [START env]
1919
env_variables:
20-
PUBSUB_TOPIC: <your-topic-name>
20+
PUBSUB_TOPIC: YOUR_TOPIC_NAME
2121
# This token is used to verify that requests originate from your
2222
# application. It can be any sufficiently random string.
23-
PUBSUB_VERIFICATION_TOKEN: <your-verification-token>
23+
PUBSUB_VERIFICATION_TOKEN: YOUR_VERIFICATION_TOKEN
2424
# [END env]
2525
# [END app_yaml]

appengine/pubsub/package.json

+22-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99
"node": ">=4.3.2"
1010
},
1111
"scripts": {
12-
"start": "node app.js"
12+
"start": "node app.js",
13+
"test": "samples test app && ava -T 30s */*.test.js"
1314
},
1415
"dependencies": {
15-
"@google-cloud/pubsub": "0.8.0",
16-
"body-parser": "1.16.0",
17-
"express": "4.14.1",
18-
"pug": "2.0.0-beta6",
19-
"safe-buffer": "5.0.1"
16+
"@google-cloud/pubsub": "0.13.2",
17+
"body-parser": "1.17.2",
18+
"express": "4.15.4",
19+
"pug": "2.0.0-rc.3",
20+
"safe-buffer": "5.1.1"
21+
},
22+
"devDependencies": {
23+
"uuid": "3.1.0"
24+
},
25+
"cloud-repo-tools": {
26+
"test": {
27+
"app": {
28+
"requiredEnvVars": [
29+
"PUBSUB_TOPIC",
30+
"PUBSUB_VERIFICATION_TOKEN"
31+
],
32+
"msg": "Messages received by this instance",
33+
"substitutions": "YOUR_TOPIC_NAME=$PUBSUB_TOPIC,YOUR_VERIFICATION_TOKEN=$PUBSUB_VERIFICATION_TOKEN"
34+
}
35+
}
2036
}
2137
}

appengine/pubsub/test/app.test.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2017, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// NOTE:
15+
// This app can only be fully tested when deployed, because
16+
// Pub/Sub requires a live endpoint URL to hit. Nevertheless,
17+
// these tests mock it and partially test it locally.
18+
19+
'use strict';
20+
21+
const test = require(`ava`);
22+
const path = require(`path`);
23+
const utils = require(`@google-cloud/nodejs-repo-tools`);
24+
25+
const message = `This is a test message sent at: `;
26+
const payload = message + Date.now();
27+
28+
const cwd = path.join(__dirname, `../`);
29+
const requestObj = utils.getRequest({ cwd: cwd });
30+
31+
test.serial.cb(`should send a message to Pub/Sub`, (t) => {
32+
requestObj
33+
.post(`/`)
34+
.type('form')
35+
.send({ payload: payload })
36+
.expect(200)
37+
.expect((response) => {
38+
t.is(response.text, `Message sent`);
39+
})
40+
.end(t.end);
41+
});
42+
43+
test.serial.cb(`should receive incoming Pub/Sub messages`, (t) => {
44+
requestObj
45+
.post(`/pubsub/push`)
46+
.query({ token: process.env.PUBSUB_VERIFICATION_TOKEN })
47+
.send({
48+
message: {
49+
data: payload
50+
}
51+
})
52+
.expect(200)
53+
.end(t.end);
54+
});
55+
56+
test.serial.cb(`should check for verification token on incoming Pub/Sub messages`, (t) => {
57+
requestObj
58+
.post(`/pubsub/push`)
59+
.field(`payload`, payload)
60+
.expect(400)
61+
.end(t.end);
62+
});
63+
64+
test.serial.cb(`should list sent Pub/Sub messages`, (t) => {
65+
requestObj
66+
.get(`/`)
67+
.expect(200)
68+
.expect((response) => {
69+
t.regex(response.text, /Messages received by this instance/);
70+
})
71+
.end(t.end);
72+
});

appengine/static-files/package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@
99
"node": ">=4.3.2"
1010
},
1111
"scripts": {
12-
"start": "node app.js"
12+
"start": "node app.js",
13+
"test": "samples test app --url localhost:8080/static/main.css"
14+
},
15+
"cloud-repo-tools": {
16+
"test": {
17+
"app": {
18+
"msg": "background-color",
19+
"port": 8080
20+
}
21+
}
1322
},
1423
"dependencies": {
15-
"express": "4.14.1",
16-
"pug": "2.0.0-beta6"
24+
"express": "4.15.4",
25+
"pug": "2.0.0-rc.3"
26+
},
27+
"devDependencies": {
28+
"@google-cloud/nodejs-repo-tools": "1.4.17"
1729
}
1830
}

appengine/storage/app.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
const format = require('util').format;
2020
const express = require('express');
2121
const Multer = require('multer');
22+
const bodyParser = require('body-parser');
23+
const process = require('process'); // Required to mock environment variables
2224

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

3335
const app = express();
3436
app.set('view engine', 'pug');
37+
app.use(bodyParser.json());
3538

3639
// [START config]
3740
// Multer is required to process file uploads and make them available via
@@ -86,3 +89,5 @@ app.listen(PORT, () => {
8689
console.log('Press Ctrl+C to quit.');
8790
});
8891
// [END app]
92+
93+
module.exports = app;

appengine/storage/app.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ env: flex
1717

1818
# [START env]
1919
env_variables:
20-
GCLOUD_STORAGE_BUCKET: <your-bucket-name>
20+
GCLOUD_STORAGE_BUCKET: YOUR_BUCKET_NAME
2121
# [END env]
2222
# [END app_yaml]

appengine/storage/package.json

+17-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22
"name": "appengine-storage",
33
"description": "Node.js Google Cloud Storage sample for Google App Engine",
44
"scripts": {
5-
"start": "node app.js"
5+
"start": "node app.js",
6+
"test": "ava system-test/*.test.js -T 30s"
67
},
78
"engines": {
89
"node": ">=4.3.2"
910
},
1011
"dependencies": {
11-
"@google-cloud/storage": "0.7.0",
12-
"body-parser": "1.16.0",
13-
"express": "4.14.1",
12+
"@google-cloud/storage": "1.2.1",
13+
"body-parser": "1.17.2",
14+
"express": "4.15.4",
1415
"multer": "1.3.0",
15-
"pug": "2.0.0-beta6"
16+
"pug": "2.0.0-rc.3"
17+
},
18+
"cloud-repo-tools": {
19+
"test": {
20+
"app": {
21+
"requiredEnvVars": [
22+
"GCLOUD_STORAGE_BUCKET"
23+
],
24+
"msg": "<input type=\"file\" name=\"file\">",
25+
"substitutions": "YOUR_BUCKET_NAME=$GCLOUD_STORAGE_BUCKET"
26+
}
27+
}
1628
}
1729
}

0 commit comments

Comments
 (0)