Skip to content

Commit

Permalink
Add snippet-test-labeling enforcement script (#1796)
Browse files Browse the repository at this point in the history
* 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 <franziska.hinkelmann@gmail.com>
  • Loading branch information
Ace Nassri and fhinkel authored May 13, 2020
1 parent e48a5cf commit abaa183
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 121 deletions.
7 changes: 7 additions & 0 deletions .kokoro/region-tags-tests.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Tell the trampoline which build file to use.
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/region-tags-tests.sh"
}
44 changes: 44 additions & 0 deletions .kokoro/region-tags-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Copyright 2018 Google LLC.
#
# 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.

export GCLOUD_PROJECT=nodejs-docs-samples-tests
export NODE_ENV=development

cd github/nodejs-docs-samples/

# Display link to docs
echo '================================================================='
echo -e 'Test failing? See \e[36mgo/drift-test-tracker-onboarding\e[0m for more info!'
echo '================================================================='

# Fetch XUnit CI enforcer script
# curl-ing it ensures we get the latest version
curl "https://raw.githubusercontent.com/GoogleCloudPlatform/repo-automation-playground/master/xunit-ci-enforcer/region_tag_enforcer.sh" > enforcer.sh
chmod +x enforcer.sh

# Run enforcer on appropriate directories
STATUS=0

# Functions
DIRS_LIST_FUNCTIONS=$(find functions -type d -name "*est" -not -path "*/node_modules/*" | xargs -I @ dirname @)
./enforcer.sh $DIRS_LIST_FUNCTIONS || STATUS=$?

# App Engine
DIRS_LIST_APPENGINE=$(find appengine -type d -name "*est" -not -path "*/node_modules/*" | xargs -I @ dirname @)
./enforcer.sh $DIRS_LIST_APPENGINE || STATUS=$?

# Fail if any directory-label attempts failed
exit $STATUS
6 changes: 4 additions & 2 deletions appengine/analytics/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const supertest = require('supertest');
const path = require('path');
const app = require(path.join(__dirname, '../', 'app.js'));

it('should be listening', async () => {
await supertest(app).get('/').expect(200);
describe('gae_flex_analytics_track_event', () => {
it('should be listening', async () => {
await supertest(app).get('/').expect(200);
});
});
44 changes: 24 additions & 20 deletions appengine/building-an-app/update/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,30 @@ it('should send greetings', async () => {
});
});

it('should display form', async () => {
await requestObj
.get('/submit')
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text.includes('textarea name="message" placeholder="Message"'),
true
);
});
describe('add_display_form', () => {
it('should display form', async () => {
await requestObj
.get('/submit')
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text.includes('textarea name="message" placeholder="Message"'),
true
);
});
});
});

it('should record message', async () => {
await requestObj
.post('/submit', {
name: 'sample-user',
message: 'sample-message',
})
.expect(200)
.expect((response) => {
assert.strictEqual(response.text, 'Thanks for your message!');
});
describe('add_post_handler enable_parser', () => {
it('should record message', async () => {
await requestObj
.post('/submit', {
name: 'sample-user',
message: 'sample-message',
})
.expect(200)
.expect((response) => {
assert.strictEqual(response.text, 'Thanks for your message!');
});
});
});
2 changes: 1 addition & 1 deletion appengine/cloudsql_postgresql/test/serverListening.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const childProcess = require('child_process');
const path = require('path');
const appPath = path.join(__dirname, '../server.js');

describe('server listening', () => {
describe('gae_flex_postgres_connect', () => {
it('should be listening', async () => {
const child = childProcess.exec(`node ${appPath}`);
const isOpen = await waitPort({port: PORT});
Expand Down
6 changes: 4 additions & 2 deletions appengine/datastore/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const supertest = require('supertest');
const path = require('path');
const app = require(path.join(__dirname, '../', 'app.js'));

it('should be listening', async () => {
await supertest(app).get('/').expect(200);
describe('gae_flex_datastore_app', () => {
it('should be listening', async () => {
await supertest(app).get('/').expect(200);
});
});
2 changes: 1 addition & 1 deletion appengine/mailjet/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const app = require('../app');

const request = require('supertest');

describe('start app', () => {
describe('gae_flex_mailjet_send_message gae_flex_mailjet_config', () => {
describe('GET /', () => {
it('should get 200', (done) => {
request(app).get('/').expect(200, done);
Expand Down
2 changes: 1 addition & 1 deletion appengine/memcached/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {expect} = require('chai');

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

describe('server listening', () => {
describe('gae_flex_redislabs_memcache', () => {
it('should be listening', async () => {
const server = require('../app.js');
const isOpen = await waitPort({port: PORT});
Expand Down
6 changes: 4 additions & 2 deletions appengine/metadata/flexible/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const supertest = require('supertest');
const path = require('path');
const app = require(path.join(__dirname, '../', 'server.js'));

it('should be listening', async () => {
await supertest(app).get('/').expect(200);
describe('gae_flex_metadata', () => {
it('should be listening', async () => {
await supertest(app).get('/').expect(200);
});
});
6 changes: 4 additions & 2 deletions appengine/redis/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ after(() => {
process.exitCode(0);
});

it('should be listening', async () => {
await supertest(app).get('/').expect(200);
describe('gae_flex_node_redis', () => {
it('should be listening', async () => {
await supertest(app).get('/').expect(200);
});
});
6 changes: 4 additions & 2 deletions appengine/static-files/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const supertest = require('supertest');
const path = require('path');
const app = require(path.join(__dirname, '../', 'app.js'));

it('should be listening', async () => {
await supertest(app).get('/').expect(200);
describe('gae_flex_node_static_files', () => {
it('should be listening', async () => {
await supertest(app).get('/').expect(200);
});
});
46 changes: 24 additions & 22 deletions appengine/storage/flexible/system-test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,29 @@ after(async () => {
} catch (err) {} // ignore error
});

it('should load', async () => {
await requestObj
.get('/')
.expect(200)
.expect((response) => {
assert.strictEqual(
new RegExp(/<input type="file" name="file">/).test(response.text),
true
);
});
});
describe('gae_flex_storage_app', () => {
it('should load', async () => {
await requestObj
.get('/')
.expect(200)
.expect((response) => {
assert.strictEqual(
new RegExp(/<input type="file" name="file">/).test(response.text),
true
);
});
});

it('should upload a file', async () => {
await requestObj
.post('/upload')
.attach('file', path.join(__dirname, 'resources/test.txt'))
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text,
`https://storage.googleapis.com/${bucketName}/test.txt`
);
});
it('should upload a file', async () => {
await requestObj
.post('/upload')
.attach('file', path.join(__dirname, 'resources/test.txt'))
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text,
`https://storage.googleapis.com/${bucketName}/test.txt`
);
});
});
});
46 changes: 24 additions & 22 deletions appengine/storage/standard/system-test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ after(async () => {
} catch (err) {} // ignore error
});

it('should load', async () => {
await requestObj
.get('/')
.expect(200)
.expect((response) => {
assert.strictEqual(
new RegExp(/<input type="file" name="file">/).test(response.text),
true
);
});
});
describe('gae_storage_app', () => {
it('should load', async () => {
await requestObj
.get('/')
.expect(200)
.expect((response) => {
assert.strictEqual(
new RegExp(/<input type="file" name="file">/).test(response.text),
true
);
});
});

it('should upload a file', async () => {
await requestObj
.post('/upload')
.attach('file', path.join(__dirname, 'resources/test.txt'))
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text,
`https://storage.googleapis.com/${bucketName}/test.txt`
);
});
it('should upload a file', async () => {
await requestObj
.post('/upload')
.attach('file', path.join(__dirname, 'resources/test.txt'))
.expect(200)
.expect((response) => {
assert.strictEqual(
response.text,
`https://storage.googleapis.com/${bucketName}/test.txt`
);
});
});
});
36 changes: 19 additions & 17 deletions functions/background/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,25 @@ after(async () => {
}
});

it('should make a promise request', async () => {
const event = {
data: {
endpoint: 'https://example.com',
},
};
describe('functions_background_promise', () => {
it('should make a promise request', async () => {
const event = {
data: {
endpoint: 'https://example.com',
},
};

const response = await request({
url: `${BASE_URL}/`,
method: 'POST',
data: event,
responseType: 'text',
retryConfig: {
httpMethodsToRetry: ['POST'],
},
});
const response = await request({
url: `${BASE_URL}/`,
method: 'POST',
data: event,
responseType: 'text',
retryConfig: {
httpMethodsToRetry: ['POST'],
},
});

assert.strictEqual(response.status, 200);
assert.ok(response.data.includes(`Example Domain`));
assert.strictEqual(response.status, 200);
assert.ok(response.data.includes(`Example Domain`));
});
});
27 changes: 27 additions & 0 deletions functions/firebase/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,30 @@ describe('functions_firebase_remote_config', () => {
assert.strictEqual(console.log.calledWith('Version: 1'), true);
});
});

describe('functions_firebase_reactive', () => {
it('should capitalize original value', () => {
const sample = getSample();

const value = {
fields: {
original: {
stringValue: 'abc'
}
}
};

const event = {
resource: 'foo/documents/bar',
eventType: 'type',
data: {
value: value,
},
};

sample.program.makeUpperCase(event, context);

assert.strictEqual(console.log.calledWith('Replacing value: abc --> ABC'), true);
assert.strictEqual(sample.mocks.firestore.doc.calledWith('bar'), true);
});
});
4 changes: 4 additions & 0 deletions functions/http/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,7 @@ describe('functions_http_signed_url', () => {
assert.strictEqual(mocks.res.send.calledOnce, true);
});
});

describe('functions_http_cors_auth functions_http_form_data functions_http_xml', () => {
// Whitelist these region tags with the region-tag enforcer
});
Loading

0 comments on commit abaa183

Please sign in to comment.