-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add kokoro config files and unit tests for gce and background (#…
…400) * feat: add tests * feat: add kokoro tests * feat: add unit tests as well * fix: lint
- Loading branch information
Showing
14 changed files
with
328 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 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-getting-started/.kokoro/trampoline.sh" | ||
|
||
# Download secrets from Cloud Storage. | ||
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/nodejs-getting-started" | ||
|
||
# Configure the docker image for kokoro-trampoline. | ||
env_vars: { | ||
key: "TRAMPOLINE_IMAGE" | ||
value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Download resources for system tests (service account key, etc.) | ||
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/nodejs-getting-started" | ||
|
||
env_vars: { | ||
key: "TRAMPOLINE_BUILD_FILE" | ||
value: "github/nodejs-getting-started/.kokoro/presubmit/lint.sh" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2018-2019 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 | ||
# | ||
# https://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. | ||
|
||
set -eo pipefail | ||
|
||
export NPM_CONFIG_PREFIX=/home/node/.npm-global | ||
|
||
cd github/nodejs-getting-started | ||
|
||
npm install | ||
|
||
npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "nodejs-getting-started", | ||
"description": "End to end sample for running Node.js applications on Google Cloud Platform", | ||
"license": "Apache-2.0", | ||
"author": "Google LLC", | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"repository": "https://github.com/GoogleCloudPlatform/nodejs-getting-started", | ||
"main": "app.js", | ||
"private": true, | ||
"scripts": { | ||
"start": "node server/app.js", | ||
"test": "mocha --exit **/*.test.js --timeout=50000" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/firestore": "^3.0.0", | ||
"@google-cloud/pubsub": "1.7.3", | ||
"@google-cloud/storage": "^4.0.0", | ||
"body-parser": "^1.18.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^7.0.0", | ||
"supertest": "^4.0.2", | ||
"chai": "^4.2.0", | ||
"child_process": "^1.0.2", | ||
"express": "^4.16.4", | ||
"superagent": "^5.2.2", | ||
"superagent-retry": "^0.6.0", | ||
"uuid": "^8.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const superagent = require('superagent'); | ||
require('superagent-retry')(superagent); | ||
|
||
const request = require('supertest'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const projectId = process.env.PROJECT_ID; | ||
const regionId = process.env.REGION_ID; | ||
const app = `https://testservice-dot-${projectId}.${regionId}.r.appspot.com`; | ||
const {expect} = require('chai'); | ||
const {v4: uuidv4} = require('uuid'); | ||
|
||
//in kokoro, need to set project id, auth, and region ID | ||
//use gcloud and firebase cli | ||
//how to get cleanup to wait | ||
describe('behavior of cloud function', function() { | ||
this.timeout(240000); | ||
const uniqueID = uuidv4().split('-')[0]; | ||
before(() => { | ||
cp.execSync(`gcloud config set project ${projectId}`); | ||
cp.execSync(`npm install`, {cwd: path.join(__dirname, '../', 'function')}); | ||
cp.execSync( | ||
`gcloud functions deploy translate-${uniqueID} --allow-unauthenticated --set-env-vars=unique_id=${uniqueID} --runtime nodejs8 --trigger-topic translate`, | ||
{cwd: path.join(__dirname, '../', 'function')} | ||
); | ||
cp.execSync(`gcloud app deploy`, { | ||
cwd: path.join(__dirname, '../', 'server'), | ||
}); | ||
}); | ||
|
||
after(() => { | ||
try { | ||
cp.execSync(`gcloud app services delete testservice`); | ||
cp.execSync(`gcloud functions delete translate-${uniqueID}`); | ||
cp.execSync( | ||
`firebase firestore:delete --project ${projectId} -r translations` | ||
); | ||
} catch (err) { | ||
console.log('Was not able to delete resources.'); | ||
} | ||
}); | ||
|
||
it('should get the correct website', async () => { | ||
return await request(app) | ||
.get('/') | ||
.retry(5) | ||
.expect(200); | ||
}); | ||
|
||
it('should ask for a translation', async () => { | ||
return await request(app) | ||
.post('/request-translation') | ||
.type('form') | ||
.send({lang: 'en', v: 'como estas'}) | ||
.retry(5) | ||
.expect(200); | ||
}); | ||
|
||
it("should now contain 'como estas'", async () => { | ||
return await request(app) | ||
.get('/') | ||
.set('Accept-Encoding', 'application/json') | ||
.retry(5) | ||
.end((err, res) => { | ||
expect(res.text.includes('como estas')); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ | |
runtime: nodejs10 | ||
|
||
instance_class: F2 | ||
|
||
# [END bookshelf_app_yml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2017 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. | ||
|
||
'use strict'; | ||
|
||
const express = require('express'); | ||
|
||
const app = express(); | ||
|
||
app.get('/', (req, res) => { | ||
res | ||
.status(200) | ||
.send('Hello, world!') | ||
.end(); | ||
}); | ||
|
||
// Start the server | ||
const PORT = process.env.PORT || 8080; | ||
app.listen(PORT, () => { | ||
console.log(`App listening on port ${PORT}`); | ||
console.log('Press Ctrl+C to quit.'); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "gce-hello-world", | ||
"description": "Simple Hello World Node.js sample for Google Compute Engine.", | ||
"version": "0.0.1", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"author": "Google Inc.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"scripts": { | ||
"start": "node app.js", | ||
"test": "mocha --exit test/*.test.js" | ||
}, | ||
"dependencies": { | ||
"express": "^4.16.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^7.2.0", | ||
"uuid": "^8.1.0", | ||
"chai": "^4.2.0", | ||
"node-fetch": "^2.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.