Skip to content

Commit

Permalink
Use nodejs-repo-tools for testing Sendgrid sample (#1285)
Browse files Browse the repository at this point in the history
* Fix sendgrid sample + use .cloud-repo-tools.json

* Add env vars

* Try fixing memcached test (low hanging fruit)
  • Loading branch information
Ace Nassri authored May 15, 2019
1 parent 3535307 commit f700a24
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
8 changes: 8 additions & 0 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export TWILIO_NUMBER="+15005550006" # public placeholder value
export TWILIO_ACCOUNT_SID=$(cat $KOKORO_GFILE_DIR/secrets-twilio-sid.txt)
export TWILIO_AUTH_TOKEN=$(cat $KOKORO_GFILE_DIR/secrets-twilio-auth-token.txt)

# Configure Sendgrid variables
export SENDGRID_SENDER="test@google.com"
export SENDGRID_API_KEY=$(cat $KOKORO_GFILE_DIR/secrets-sendgrid-api-key.txt)

# Configure GCF variables
export FUNCTIONS_TOPIC=integration-tests-instance
export FUNCTIONS_BUCKET=$GCLOUD_PROJECT
Expand Down Expand Up @@ -52,6 +56,10 @@ if [[ $PROJECT == functions/* ]]; then
functions-emulator start
fi

export NODEJS_IOT_EC_PUBLIC_KEY=${KOKORO_GFILE_DIR}/ec_public.pem
export NODEJS_IOT_RSA_PRIVATE_KEY=${KOKORO_GFILE_DIR}/rsa_private.pem
export NODEJS_IOT_RSA_PUBLIC_CERT=${KOKORO_GFILE_DIR}/rsa_cert.pem

npm test

exit $?
14 changes: 14 additions & 0 deletions appengine/memcached/.cloud-repo-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"test": {
"app": {
"msg": "Value:"
}
},
"requiresKeyFile": true,
"requiresProjectId": true,
"requiredEnvVars": [
"MEMCACHE_URL",
"MEMCACHE_USERNAME",
"MEMCACHE_PASSWORD"
]
}
17 changes: 3 additions & 14 deletions appengine/memcached/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,11 @@
"start": "node app.js",
"test": "repo-tools test app"
},
"cloud-repo-tools": {
"test": {
"app": {
"msg": "Value:"
}
},
"requiresKeyFile": true,
"requiresProjectId": true,
"requiredEnvVars": [
"MEMCACHE_URL",
"MEMCACHE_USERNAME",
"MEMCACHE_PASSWORD"
]
},
"dependencies": {
"express": "^4.16.4",
"memjs": "^1.2.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.3.0"
}
}
13 changes: 13 additions & 0 deletions appengine/sendgrid/.cloud-repo-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"test": {
"app": {
"msg": "Hello World!"
}
},
"requiresKeyFile": true,
"requiresProjectId": true,
"requiredEnvVars": [
"SENDGRID_SENDER",
"SENDGRID_API_KEY"
]
}
16 changes: 2 additions & 14 deletions appengine/sendgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,7 @@
},
"scripts": {
"start": "node app.js",
"test": "mocha test/app.test.js"
},
"cloud-repo-tools": {
"test": {
"app": {
"msg": "Value:"
}
},
"requiresKeyFile": true,
"requiresProjectId": true,
"requiredEnvVars": [
"SENDGRID_SENDER",
"SENDGRID_API_KEY"
]
"test": "repo-tools test app && mocha test/*.test.js"
},
"dependencies": {
"body-parser": "^1.19.0",
Expand All @@ -32,6 +19,7 @@
"@sendgrid/client": "^6.3.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.3.0",
"assert": "^1.4.1",
"mocha": "^6.1.4",
"supertest": "^4.0.2"
Expand Down
11 changes: 7 additions & 4 deletions appengine/sendgrid/test/app.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const assert = require('assert');
const Supertest = require('supertest');
const supertest = Supertest('http://localhost:8080');
const path = require('path');
const utils = require('@google-cloud/nodejs-repo-tools');

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

it('GET /: should show homepage template', async () => {
await supertest
await request
.get('/')
.expect(200)
.expect(response => {
Expand All @@ -12,7 +15,7 @@ it('GET /: should show homepage template', async () => {
});

it('POST /hello: should send an email', async () => {
await supertest
await request
.post('/hello?test=true')
.type('form')
.send({email: 'testuser@google.com'})
Expand Down

0 comments on commit f700a24

Please sign in to comment.