Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System-ify functions tests, part 1 (hello-world + datastore) #529

Merged
merged 25 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .kokoro/common.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Download trampoline resources. These will be in ${KOKORO_GFILE_DIR}
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# All builds use the trampoline script to run in docker.
build_file: "nodejs-docs-samples/.kokoro/trampoline.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-docs-samples/nodejs"
}
10 changes: 10 additions & 0 deletions .kokoro/functions-helloworld.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Download secrets from Cloud Storage.
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/nodejs-docs-samples"

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

# Copyright 2017 Google Inc.
#
# 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
STAGE_BUCKET=$GCLOUD_PROJECT
GCP_REGION=us-central1
FUNCTIONS_TOPIC=integration-test-functions
FUNCTIONS_BUCKET=$FUNCTIONS_TOPIC
export BASE_URL=https://${GCP_REGION}-${GCLOUD_PROJECT}.cloudfunctions.net

cd github/nodejs-docs-samples/functions/helloworld

# Install dependencies
npm install

# Configure gcloud
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secrets-key.json
gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS"
gcloud config set project $GCLOUD_PROJECT

function cleanup {
CODE=$?

gcloud beta functions delete helloHttp -q
gcloud beta functions delete helloGET -q
gcloud beta functions delete helloBackground -q
gcloud beta functions delete helloPubSub -q
gcloud beta functions delete helloGCS -q
gcloud beta functions delete helloError -q
gcloud beta functions delete helloError2 -q
gcloud beta functions delete helloError3 -q
gcloud beta functions delete helloTemplate -q
}
trap cleanup EXIT

set -e

# Deploy + run the functions
npm run e2e-test
15 changes: 15 additions & 0 deletions .kokoro/trampoline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Copyright 2017 Google Inc.
#
# 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.
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
22 changes: 17 additions & 5 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

machine:
node:
version: 6.11.2
version: 6.12.3

# Use for broader build-related configuration
general:
Expand All @@ -31,21 +31,21 @@ dependencies:
override:
- echo $KEYFILE > /home/ubuntu/nodejs-docs-samples/key.json
- gcloud auth activate-service-account --key-file /home/ubuntu/nodejs-docs-samples/key.json || true
- yarn global add ava nyc codecov semistandard @google-cloud/nodejs-repo-tools@1.4.17
- yarn global add ava nyc codecov semistandard @google-cloud/nodejs-repo-tools@1.4.17 @google-cloud/functions-emulator@1.0.0-alpha.29
- yarn install
- yarn run lint
- samples test install -l=functions/background
- samples test install -l=functions/datastore
- samples test install -l=functions/errorreporting
- samples test install -l=functions/gcs
- samples test install -l=functions/datastore
- samples test install -l=functions/helloworld
- samples test install -l=functions/http
- samples test install -l=functions/imagemagick
- samples test install -l=functions/log
- samples test install -l=functions/ocr/app
- samples test install -l=functions/pubsub
- samples test install -l=functions/sendgrid
- samples test install -l=functions/slack
- samples test install -l=functions/spanner
- samples test install -l=functions/uuid
cache_directories:
- ~/.cache/yarn
Expand All @@ -61,12 +61,24 @@ dependencies:
- functions/pubsub/node_modules
- functions/sendgrid/node_modules
- functions/slack/node_modules
- functions/spanner/node_modules
- functions/uuid/node_modules

# Run your tests
test:
override:
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/**/test/**/*.test.js'
- functions start && cd functions/datastore && npm run system-test
- functions start && cd functions/helloworld && npm run system-test
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/background/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/gcs/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/http/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/imagemagick/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/log/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/pubsub/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/sendgrid/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/slack/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/spanner/test/**/*.test.js'
- samples test run --cmd nyc -- --cache ava --verbose -T 30s 'functions/uuid/test/**/*.test.js'
post:
- nyc report --reporter=lcov > coverage.lcov && codecov || true
deployment:
Expand Down
10 changes: 5 additions & 5 deletions functions/background/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"test": "ava -T 20s --verbose test/*.test.js"
},
"dependencies": {
"request": "2.81.0",
"request-promise": "4.2.1"
"request": "2.83.0",
"request-promise": "4.2.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.21.0",
"@google-cloud/nodejs-repo-tools": "2.1.0",
"ava": "0.23.0",
"proxyquire": "1.8.0",
"sinon": "3.2.0"
"sinon": "4.0.2"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
Expand Down
10 changes: 6 additions & 4 deletions functions/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports.set = (req, res) => {
.then(() => res.status(200).send(`Entity ${key.path.join('/')} saved.`))
.catch((err) => {
console.error(err);
res.status(500).send(err);
res.status(500).send(err.message);
return Promise.reject(err);
});
};
Expand All @@ -92,7 +92,7 @@ exports.get = (req, res) => {
return datastore.get(key)
.then(([entity]) => {
// The get operation will not fail for a non-existent entity, it just
// returns null.
// returns an empty dictionary.
if (!entity) {
throw new Error(`No entity found for key ${key.path.join('/')}.`);
}
Expand All @@ -101,7 +101,7 @@ exports.get = (req, res) => {
})
.catch((err) => {
console.error(err);
res.status(500).send(err);
res.status(500).send(err.message);
return Promise.reject(err);
});
};
Expand All @@ -122,11 +122,13 @@ exports.del = (req, res) => {
const key = getKeyFromRequestData(req.body);

// Deletes the entity
// The delete operation will not fail for a non-existent entity, it just
// doesn't delete anything
return datastore.delete(key)
.then(() => res.status(200).send(`Entity ${key.path.join('/')} deleted.`))
.catch((err) => {
console.error(err);
res.status(500).send(err);
return Promise.reject(err);
return Promise.reject(err.message);
});
};
23 changes: 16 additions & 7 deletions functions/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@
"node": ">=4.3.2"
},
"scripts": {
"lint": "samples lint",
"lint": "repo-tools lint",
"pretest": "npm run lint",
"test": "ava -T 20s --verbose test/*.test.js"
"e2e-test": "export FUNCTIONS_CMD='gcloud beta functions' && sh test/updateFunctions.sh && BASE_URL=\"https://$GCF_REGION-$GCLOUD_PROJECT.cloudfunctions.net/\" ava -T 20s --verbose test/*.test.js",
"system-test": "export FUNCTIONS_CMD='functions' && sh test/updateFunctions.sh && BASE_URL=\"http://localhost:8010/$GCLOUD_PROJECT/$GCF_REGION\" ava -T 20s --verbose test/*.test.js",
"test": "npm run system-test"
},
"dependencies": {
"@google-cloud/datastore": "1.1.0"
"@google-cloud/datastore": "1.3.3",
"supertest": "^3.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.21.0",
"@google-cloud/functions-emulator": "^1.0.0-alpha.29",
"@google-cloud/nodejs-repo-tools": "2.1.3",
"ava": "0.24.0",
"proxyquire": "1.8.0",
"sinon": "3.2.0"
"sinon": "4.1.3"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true
"requiresProjectId": true,
"requiredEnvVars": [
"BASE_URL",
"GCF_REGION",
"FUNCTIONS_CMD"
]
}
}
Loading