Skip to content

Commit af8b8fa

Browse files
committed
Closes #20
1 parent 04a6d8c commit af8b8fa

File tree

5 files changed

+215
-27
lines changed

5 files changed

+215
-27
lines changed

.travis.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ node_js:
77
cache:
88
directories:
99
- $HOME/gcloud/
10+
- appengine/express/node_modules/
11+
- appengine/geddy/node_modules/
12+
- appengine/grunt/node_modules/
13+
- appengine/hapi/node_modules/
14+
- appengine/kraken/node_modules/
15+
- appengine/loopback/node_modules/
16+
- appengine/mailgun/node_modules/
17+
- appengine/redis/node_modules/
18+
- appengine/restify/node_modules/
19+
- appengine/sails/node_modules/
20+
21+
services:
22+
- redis-server
23+
1024
env:
1125
- PATH=$PATH:$HOME/gcloud/google-cloud-sdk/bin GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/nodejs-docs-samples.json TEST_BUCKET_NAME=cloud-samples-tests TEST_PROJECT_ID=cloud-samples-tests #Other environment variables on same line
1226

@@ -38,6 +52,3 @@ before_install:
3852
install:
3953
#Add app specific setup here
4054
#Use '-q' to disable interactive prompts
41-
42-
script:
43-
- jshint --exclude-path=.jshintignore .

appengine/redis/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ For convenience, you can use an npm script to run the deploy command. Modify you
4949

5050
```json
5151
"scripts": {
52-
"start": "node ./bin/www",
52+
"start": "node server.js",
5353
"deploy": "gcloud preview app deploy app.yaml --promote --project <your-project-id>"
5454
}
5555
```

appengine/redis/package.json

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
{
22
"name": "appengine-redis",
3-
"version": "1.0.0",
4-
"description": "An example of using redis with Google App Engine.",
5-
"main": "server.js",
3+
"description": "An example of using Redis with Node.js on Google App Engine.",
4+
"version": "0.0.1",
5+
"private": true,
6+
"license": "Apache Version 2.0",
7+
"engines": {
8+
"node": "~0.12.7"
9+
},
610
"scripts": {
11+
"start": "node server.js",
712
"deploy": "gcloud preview app deploy app.yaml --promote --project node-redis-demo"
813
},
9-
"repository": {
10-
"type": "git",
11-
"url": "http://github.com/JustinBeckwith/appengine-nodejs-samples"
12-
},
13-
"keywords": [
14-
"nodejs",
15-
"redis",
16-
"appengine",
17-
"google"
18-
],
19-
"author": "Justin Beckwith",
20-
"license": "Apache Version 2.0",
21-
"bugs": {
22-
"url": "https://github.com/JustinBeckwith/appengine-nodejs-samples/issues"
23-
},
24-
"homepage": "https://github.com/JustinBeckwith/appengine-nodejs-samples",
2514
"dependencies": {
2615
"nconf": "^0.8.0",
2716
"redis": "^2.0.1"

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "Samples used in the nodejs documentation on cloud.google.com",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha --recursive",
8-
"jshint": "jshint --exclude-path=.jshintignore ."
7+
"jshint": "jshint --exclude-path=.jshintignore .",
8+
"mocha": "mocha --timeout 10000 --recursive",
9+
"test": "npm run jshint && npm run mocha"
910
},
1011
"author": "[email protected]",
1112
"license": "Apache 2",
@@ -14,9 +15,10 @@
1415
"googleapis": "~2.1.3"
1516
},
1617
"devDependencies": {
17-
"mocha": "~2.2.5",
1818
"jshint": "~2.8.0",
19-
"lodash": "~3.10.1"
19+
"lodash": "~3.10.1",
20+
"mocha": "^2.2.5",
21+
"request": "^2.65.0"
2022
},
2123
"repository": {
2224
"type": "git",

test/appengine/test.js

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// Copyright 2015, Google, Inc.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
'use strict';
15+
16+
var spawn = require('child_process').spawn;
17+
var request = require('request');
18+
19+
var cwd = process.cwd();
20+
21+
function getPath(dir) {
22+
return cwd + '/appengine/' + dir;
23+
}
24+
25+
console.log(process.env);
26+
27+
var sampleTests = [
28+
{
29+
dir: 'express',
30+
cmd: 'node',
31+
arg1: './bin/www',
32+
msg: 'Hello World! Express.js on Google App Engine.'
33+
},
34+
{
35+
dir: 'geddy',
36+
cmd: 'node',
37+
arg1: 'node_modules/geddy/bin/cli.js',
38+
msg: 'Hello, World! Geddy.js on Google App Engine.'
39+
},
40+
{
41+
dir: 'grunt',
42+
cmd: 'node',
43+
arg1: './src/bin/www',
44+
msg: 'Hello World! Express.js + Grunt.js on Google App Engine.'
45+
},
46+
{
47+
dir: 'hapi',
48+
cmd: 'node',
49+
arg1: 'index.js',
50+
msg: 'Hello World! Hapi.js on Google App Engine.'
51+
},
52+
{
53+
dir: 'kraken',
54+
cmd: 'node',
55+
arg1: 'server.js',
56+
msg: 'Hello World! Kraken.js on Google App Engine.',
57+
code: 304
58+
},
59+
{
60+
dir: 'loopback',
61+
cmd: 'node',
62+
arg1: 'server/server.js',
63+
msg: 'LoopBack.js on Google App Engine.',
64+
code: 304
65+
},
66+
{
67+
dir: 'mailgun',
68+
cmd: 'node',
69+
arg1: 'app.js',
70+
msg: 'Express.js + Mailgun on Google App Engine.'
71+
},
72+
{
73+
dir: 'redis',
74+
cmd: 'node',
75+
arg1: 'server.js',
76+
msg: '127.0.0.1'
77+
},
78+
{
79+
dir: 'restify',
80+
cmd: 'node',
81+
arg1: 'server.js',
82+
msg: 'Hello World! Restify.js on Google App Engine.'
83+
},
84+
{
85+
dir: 'sails',
86+
cmd: 'node',
87+
arg1: 'app.js',
88+
msg: 'Hello World! Sails.js on Google App Engine.',
89+
timeout: 240000
90+
}
91+
];
92+
93+
describe('appengine/', function () {
94+
sampleTests.forEach(function (sample) {
95+
it(sample.dir + ': dependencies should install', function (done) {
96+
this.timeout(sample.timeout || 120000);
97+
var calledDone = false;
98+
99+
var proc = spawn('npm', ['install'], {
100+
cwd: getPath(sample.dir)
101+
});
102+
103+
proc.on('error', function (err) {
104+
if (!calledDone) {
105+
calledDone = true;
106+
done(err);
107+
}
108+
});
109+
110+
if (!process.env.TRAVIS) {
111+
proc.stderr.on('data', function (data) {
112+
console.log('stderr: ' + data);
113+
});
114+
}
115+
116+
proc.on('exit', function (code) {
117+
if (!calledDone) {
118+
calledDone = true;
119+
if (code !== 0) {
120+
done(new Error(sample.dir + ': failed to install dependencies!'));
121+
} else {
122+
done();
123+
}
124+
}
125+
});
126+
});
127+
128+
it(sample.dir + ': should return 200 and Hello World', function (done) {
129+
var timeoutId;
130+
var intervalId;
131+
var success = false;
132+
var calledDone = false;
133+
134+
var proc = spawn(sample.cmd, [sample.arg1], {
135+
cwd: getPath(sample.dir)
136+
});
137+
138+
proc.on('error', function (err) {
139+
if (!calledDone) {
140+
calledDone = true;
141+
done(err);
142+
}
143+
});
144+
145+
if (!process.env.TRAVIS) {
146+
proc.stderr.on('data', function (data) {
147+
console.log('stderr: ' + data);
148+
});
149+
}
150+
151+
proc.on('exit', function (code, signal) {
152+
if (!calledDone) {
153+
calledDone = true;
154+
if (code !== 0 && signal !== 'SIGKILL') {
155+
done(new Error(sample.dir + ': failed to run!'));
156+
} else {
157+
if (!success) {
158+
done(new Error(sample.dir + ': failed verification!'));
159+
} else {
160+
done();
161+
}
162+
}
163+
}
164+
});
165+
166+
timeoutId = setTimeout(end, 5000);
167+
intervalId = setInterval(testRequest, 1000);
168+
169+
function end() {
170+
clearTimeout(timeoutId);
171+
clearInterval(intervalId);
172+
proc.kill('SIGKILL');
173+
}
174+
175+
function testRequest() {
176+
request('http://localhost:8080', function (err, res, body) {
177+
if (body && body.indexOf(sample.msg) !== -1 &&
178+
(res.statusCode === 200 || res.statusCode === sample.code)) {
179+
success = true;
180+
end();
181+
}
182+
});
183+
}
184+
});
185+
});
186+
});

0 commit comments

Comments
 (0)