Skip to content

Commit abaa183

Browse files
Ace Nassrifhinkel
Ace Nassri
andauthored
Add snippet-test-labeling enforcement script (#1796)
* Add snippet-test-labeling enforcement script * Add Kokoro configs * Use clearer filenames * Update region-tags-tests.sh * Fix typo * Add firestore test * Whitelist region tags for functions * Whitelist/add region tags for appengine * Revert gitignore change * Fix trampoline typo * Add color + use (zsh-friendly) single quotes Co-authored-by: F. Hinkelmann <[email protected]>
1 parent e48a5cf commit abaa183

File tree

20 files changed

+238
-121
lines changed

20 files changed

+238
-121
lines changed

.kokoro/region-tags-tests.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Tell the trampoline which build file to use.
4+
env_vars: {
5+
key: "TRAMPOLINE_BUILD_FILE"
6+
value: "github/nodejs-docs-samples/.kokoro/region-tags-tests.sh"
7+
}

.kokoro/region-tags-tests.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Copyright 2018 Google LLC.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
export GCLOUD_PROJECT=nodejs-docs-samples-tests
18+
export NODE_ENV=development
19+
20+
cd github/nodejs-docs-samples/
21+
22+
# Display link to docs
23+
echo '================================================================='
24+
echo -e 'Test failing? See \e[36mgo/drift-test-tracker-onboarding\e[0m for more info!'
25+
echo '================================================================='
26+
27+
# Fetch XUnit CI enforcer script
28+
# curl-ing it ensures we get the latest version
29+
curl "https://raw.githubusercontent.com/GoogleCloudPlatform/repo-automation-playground/master/xunit-ci-enforcer/region_tag_enforcer.sh" > enforcer.sh
30+
chmod +x enforcer.sh
31+
32+
# Run enforcer on appropriate directories
33+
STATUS=0
34+
35+
# Functions
36+
DIRS_LIST_FUNCTIONS=$(find functions -type d -name "*est" -not -path "*/node_modules/*" | xargs -I @ dirname @)
37+
./enforcer.sh $DIRS_LIST_FUNCTIONS || STATUS=$?
38+
39+
# App Engine
40+
DIRS_LIST_APPENGINE=$(find appengine -type d -name "*est" -not -path "*/node_modules/*" | xargs -I @ dirname @)
41+
./enforcer.sh $DIRS_LIST_APPENGINE || STATUS=$?
42+
43+
# Fail if any directory-label attempts failed
44+
exit $STATUS

appengine/analytics/test/app.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const supertest = require('supertest');
22
const path = require('path');
33
const app = require(path.join(__dirname, '../', 'app.js'));
44

5-
it('should be listening', async () => {
6-
await supertest(app).get('/').expect(200);
5+
describe('gae_flex_analytics_track_event', () => {
6+
it('should be listening', async () => {
7+
await supertest(app).get('/').expect(200);
8+
});
79
});

appengine/building-an-app/update/test/server.test.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,30 @@ it('should send greetings', async () => {
4545
});
4646
});
4747

48-
it('should display form', async () => {
49-
await requestObj
50-
.get('/submit')
51-
.expect(200)
52-
.expect((response) => {
53-
assert.strictEqual(
54-
response.text.includes('textarea name="message" placeholder="Message"'),
55-
true
56-
);
57-
});
48+
describe('add_display_form', () => {
49+
it('should display form', async () => {
50+
await requestObj
51+
.get('/submit')
52+
.expect(200)
53+
.expect((response) => {
54+
assert.strictEqual(
55+
response.text.includes('textarea name="message" placeholder="Message"'),
56+
true
57+
);
58+
});
59+
});
5860
});
5961

60-
it('should record message', async () => {
61-
await requestObj
62-
.post('/submit', {
63-
name: 'sample-user',
64-
message: 'sample-message',
65-
})
66-
.expect(200)
67-
.expect((response) => {
68-
assert.strictEqual(response.text, 'Thanks for your message!');
69-
});
62+
describe('add_post_handler enable_parser', () => {
63+
it('should record message', async () => {
64+
await requestObj
65+
.post('/submit', {
66+
name: 'sample-user',
67+
message: 'sample-message',
68+
})
69+
.expect(200)
70+
.expect((response) => {
71+
assert.strictEqual(response.text, 'Thanks for your message!');
72+
});
73+
});
7074
});

appengine/cloudsql_postgresql/test/serverListening.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const childProcess = require('child_process');
55
const path = require('path');
66
const appPath = path.join(__dirname, '../server.js');
77

8-
describe('server listening', () => {
8+
describe('gae_flex_postgres_connect', () => {
99
it('should be listening', async () => {
1010
const child = childProcess.exec(`node ${appPath}`);
1111
const isOpen = await waitPort({port: PORT});

appengine/datastore/test/app.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const supertest = require('supertest');
22
const path = require('path');
33
const app = require(path.join(__dirname, '../', 'app.js'));
44

5-
it('should be listening', async () => {
6-
await supertest(app).get('/').expect(200);
5+
describe('gae_flex_datastore_app', () => {
6+
it('should be listening', async () => {
7+
await supertest(app).get('/').expect(200);
8+
});
79
});

appengine/mailjet/test/app.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const app = require('../app');
22

33
const request = require('supertest');
44

5-
describe('start app', () => {
5+
describe('gae_flex_mailjet_send_message gae_flex_mailjet_config', () => {
66
describe('GET /', () => {
77
it('should get 200', (done) => {
88
request(app).get('/').expect(200, done);

appengine/memcached/test/app.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {expect} = require('chai');
33

44
const PORT = process.env.PORT || 8080;
55

6-
describe('server listening', () => {
6+
describe('gae_flex_redislabs_memcache', () => {
77
it('should be listening', async () => {
88
const server = require('../app.js');
99
const isOpen = await waitPort({port: PORT});

appengine/metadata/flexible/test/server.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const supertest = require('supertest');
22
const path = require('path');
33
const app = require(path.join(__dirname, '../', 'server.js'));
44

5-
it('should be listening', async () => {
6-
await supertest(app).get('/').expect(200);
5+
describe('gae_flex_metadata', () => {
6+
it('should be listening', async () => {
7+
await supertest(app).get('/').expect(200);
8+
});
79
});

appengine/redis/test/server.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ after(() => {
66
process.exitCode(0);
77
});
88

9-
it('should be listening', async () => {
10-
await supertest(app).get('/').expect(200);
9+
describe('gae_flex_node_redis', () => {
10+
it('should be listening', async () => {
11+
await supertest(app).get('/').expect(200);
12+
});
1113
});

appengine/static-files/test/app.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const supertest = require('supertest');
22
const path = require('path');
33
const app = require(path.join(__dirname, '../', 'app.js'));
44

5-
it('should be listening', async () => {
6-
await supertest(app).get('/').expect(200);
5+
describe('gae_flex_node_static_files', () => {
6+
it('should be listening', async () => {
7+
await supertest(app).get('/').expect(200);
8+
});
79
});

appengine/storage/flexible/system-test/app.test.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,29 @@ after(async () => {
4949
} catch (err) {} // ignore error
5050
});
5151

52-
it('should load', async () => {
53-
await requestObj
54-
.get('/')
55-
.expect(200)
56-
.expect((response) => {
57-
assert.strictEqual(
58-
new RegExp(/<input type="file" name="file">/).test(response.text),
59-
true
60-
);
61-
});
62-
});
52+
describe('gae_flex_storage_app', () => {
53+
it('should load', async () => {
54+
await requestObj
55+
.get('/')
56+
.expect(200)
57+
.expect((response) => {
58+
assert.strictEqual(
59+
new RegExp(/<input type="file" name="file">/).test(response.text),
60+
true
61+
);
62+
});
63+
});
6364

64-
it('should upload a file', async () => {
65-
await requestObj
66-
.post('/upload')
67-
.attach('file', path.join(__dirname, 'resources/test.txt'))
68-
.expect(200)
69-
.expect((response) => {
70-
assert.strictEqual(
71-
response.text,
72-
`https://storage.googleapis.com/${bucketName}/test.txt`
73-
);
74-
});
65+
it('should upload a file', async () => {
66+
await requestObj
67+
.post('/upload')
68+
.attach('file', path.join(__dirname, 'resources/test.txt'))
69+
.expect(200)
70+
.expect((response) => {
71+
assert.strictEqual(
72+
response.text,
73+
`https://storage.googleapis.com/${bucketName}/test.txt`
74+
);
75+
});
76+
});
7577
});

appengine/storage/standard/system-test/app.test.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,29 @@ after(async () => {
4545
} catch (err) {} // ignore error
4646
});
4747

48-
it('should load', async () => {
49-
await requestObj
50-
.get('/')
51-
.expect(200)
52-
.expect((response) => {
53-
assert.strictEqual(
54-
new RegExp(/<input type="file" name="file">/).test(response.text),
55-
true
56-
);
57-
});
58-
});
48+
describe('gae_storage_app', () => {
49+
it('should load', async () => {
50+
await requestObj
51+
.get('/')
52+
.expect(200)
53+
.expect((response) => {
54+
assert.strictEqual(
55+
new RegExp(/<input type="file" name="file">/).test(response.text),
56+
true
57+
);
58+
});
59+
});
5960

60-
it('should upload a file', async () => {
61-
await requestObj
62-
.post('/upload')
63-
.attach('file', path.join(__dirname, 'resources/test.txt'))
64-
.expect(200)
65-
.expect((response) => {
66-
assert.strictEqual(
67-
response.text,
68-
`https://storage.googleapis.com/${bucketName}/test.txt`
69-
);
70-
});
61+
it('should upload a file', async () => {
62+
await requestObj
63+
.post('/upload')
64+
.attach('file', path.join(__dirname, 'resources/test.txt'))
65+
.expect(200)
66+
.expect((response) => {
67+
assert.strictEqual(
68+
response.text,
69+
`https://storage.googleapis.com/${bucketName}/test.txt`
70+
);
71+
});
72+
});
7173
});

functions/background/test/index.test.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,25 @@ after(async () => {
4545
}
4646
});
4747

48-
it('should make a promise request', async () => {
49-
const event = {
50-
data: {
51-
endpoint: 'https://example.com',
52-
},
53-
};
48+
describe('functions_background_promise', () => {
49+
it('should make a promise request', async () => {
50+
const event = {
51+
data: {
52+
endpoint: 'https://example.com',
53+
},
54+
};
5455

55-
const response = await request({
56-
url: `${BASE_URL}/`,
57-
method: 'POST',
58-
data: event,
59-
responseType: 'text',
60-
retryConfig: {
61-
httpMethodsToRetry: ['POST'],
62-
},
63-
});
56+
const response = await request({
57+
url: `${BASE_URL}/`,
58+
method: 'POST',
59+
data: event,
60+
responseType: 'text',
61+
retryConfig: {
62+
httpMethodsToRetry: ['POST'],
63+
},
64+
});
6465

65-
assert.strictEqual(response.status, 200);
66-
assert.ok(response.data.includes(`Example Domain`));
66+
assert.strictEqual(response.status, 200);
67+
assert.ok(response.data.includes(`Example Domain`));
68+
});
6769
});

functions/firebase/test/index.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,30 @@ describe('functions_firebase_remote_config', () => {
202202
assert.strictEqual(console.log.calledWith('Version: 1'), true);
203203
});
204204
});
205+
206+
describe('functions_firebase_reactive', () => {
207+
it('should capitalize original value', () => {
208+
const sample = getSample();
209+
210+
const value = {
211+
fields: {
212+
original: {
213+
stringValue: 'abc'
214+
}
215+
}
216+
};
217+
218+
const event = {
219+
resource: 'foo/documents/bar',
220+
eventType: 'type',
221+
data: {
222+
value: value,
223+
},
224+
};
225+
226+
sample.program.makeUpperCase(event, context);
227+
228+
assert.strictEqual(console.log.calledWith('Replacing value: abc --> ABC'), true);
229+
assert.strictEqual(sample.mocks.firestore.doc.calledWith('bar'), true);
230+
});
231+
});

functions/http/test/index.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,7 @@ describe('functions_http_signed_url', () => {
264264
assert.strictEqual(mocks.res.send.calledOnce, true);
265265
});
266266
});
267+
268+
describe('functions_http_cors_auth functions_http_form_data functions_http_xml', () => {
269+
// Whitelist these region tags with the region-tag enforcer
270+
});

0 commit comments

Comments
 (0)