-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chore(ci): migrate datastore/functions to new ci #4046
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,22 +14,26 @@ | |||||||||||||||||||
|
||||||||||||||||||||
'use strict'; | ||||||||||||||||||||
|
||||||||||||||||||||
const assert = require('assert'); | ||||||||||||||||||||
const execPromise = require('child-process-promise').exec; | ||||||||||||||||||||
const path = require('path'); | ||||||||||||||||||||
const uuid = require('uuid'); | ||||||||||||||||||||
const sinon = require('sinon'); | ||||||||||||||||||||
const fetch = require('node-fetch'); | ||||||||||||||||||||
const waitPort = require('wait-port'); | ||||||||||||||||||||
const {Datastore} = require('@google-cloud/datastore'); | ||||||||||||||||||||
import {ok, strictEqual, deepStrictEqual} from 'assert'; | ||||||||||||||||||||
import {exec as execPromise} from 'child-process-promise'; | ||||||||||||||||||||
import {join} from 'path'; | ||||||||||||||||||||
import {v4} from 'uuid'; | ||||||||||||||||||||
import {stub} from 'sinon'; | ||||||||||||||||||||
import fetch from 'node-fetch'; | ||||||||||||||||||||
import { fileURLToPath } from 'url'; | ||||||||||||||||||||
import { dirname } from 'path'; | ||||||||||||||||||||
import waitPort from 'wait-port'; | ||||||||||||||||||||
import {Datastore} from '@google-cloud/datastore'; | ||||||||||||||||||||
|
||||||||||||||||||||
const datastore = new Datastore(); | ||||||||||||||||||||
const program = require('../'); | ||||||||||||||||||||
import {set, get, del} from '../'; | ||||||||||||||||||||
|
||||||||||||||||||||
const FF_TIMEOUT = 3000; | ||||||||||||||||||||
const cwd = path.join(__dirname, '..'); | ||||||||||||||||||||
const __filename = fileURLToPath(import.meta.url); | ||||||||||||||||||||
const __dirname = dirname(__filename); | ||||||||||||||||||||
const cwd = join(__dirname, '..'); | ||||||||||||||||||||
const NAME = 'sampletask1'; | ||||||||||||||||||||
const KIND = `Task-${uuid.v4()}`; | ||||||||||||||||||||
const KIND = `Task-${v4()}`; | ||||||||||||||||||||
const VALUE = { | ||||||||||||||||||||
description: 'Buy milk', | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
@@ -72,14 +76,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
body: {}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.set(req, res); | ||||||||||||||||||||
await set(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Value'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Value'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('set: Fails without a key', async () => { | ||||||||||||||||||||
|
@@ -89,12 +93,12 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
await program.set(req, res); | ||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
await set(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('set: Fails without a kind', async () => { | ||||||||||||||||||||
|
@@ -105,14 +109,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.set(req, res); | ||||||||||||||||||||
await set(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('set: Saves an entity', async () => { | ||||||||||||||||||||
|
@@ -125,9 +129,9 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}), | ||||||||||||||||||||
headers: {'Content-Type': 'application/json'}, | ||||||||||||||||||||
}); | ||||||||||||||||||||
assert.strictEqual(response.status, 200); | ||||||||||||||||||||
strictEqual(response.status, 200); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
const body = await response.text(); | ||||||||||||||||||||
assert.ok(body.includes(`Entity ${KIND}/${NAME} saved`)); | ||||||||||||||||||||
ok(body.includes(`Entity ${KIND}/${NAME} saved`)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -159,9 +163,9 @@ describe('functions/datastore', () => { | |||||||||||||||||||
validateStatus: () => true, | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
assert.strictEqual(response.status, 500); | ||||||||||||||||||||
strictEqual(response.status, 500); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
const body = await response.text(); | ||||||||||||||||||||
assert.ok( | ||||||||||||||||||||
ok( | ||||||||||||||||||||
new RegExp( | ||||||||||||||||||||
/(Missing or insufficient permissions.)|(No entity found for key)/ | ||||||||||||||||||||
).test(body) | ||||||||||||||||||||
Comment on lines
+168
to
171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
|
@@ -177,9 +181,9 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}), | ||||||||||||||||||||
headers: {'Content-Type': 'application/json'}, | ||||||||||||||||||||
}); | ||||||||||||||||||||
assert.strictEqual(response.status, 200); | ||||||||||||||||||||
strictEqual(response.status, 200); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
const body = await response.json(); | ||||||||||||||||||||
assert.deepStrictEqual(body, { | ||||||||||||||||||||
deepStrictEqual(body, { | ||||||||||||||||||||
description: 'Buy milk', | ||||||||||||||||||||
}); | ||||||||||||||||||||
Comment on lines
+186
to
188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
@@ -189,14 +193,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
body: {}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.get(req, res); | ||||||||||||||||||||
await get(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('get: Fails without a kind', async () => { | ||||||||||||||||||||
|
@@ -206,14 +210,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.get(req, res); | ||||||||||||||||||||
await get(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -239,14 +243,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
body: {}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.del(req, res); | ||||||||||||||||||||
await del(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Key'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('del: Fails without a kind', async () => { | ||||||||||||||||||||
|
@@ -256,14 +260,14 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}, | ||||||||||||||||||||
}; | ||||||||||||||||||||
const res = { | ||||||||||||||||||||
status: sinon.stub().returnsThis(), | ||||||||||||||||||||
send: sinon.stub(), | ||||||||||||||||||||
status: stub().returnsThis(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
send: stub(), | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
await program.del(req, res); | ||||||||||||||||||||
await del(req, res); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
|
||||||||||||||||||||
assert.ok(res.status.calledWith(500)); | ||||||||||||||||||||
assert.ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
ok(res.status.calledWith(500)); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
ok(res.send.calledWith(errorMsg('Kind'))); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it("del: Doesn't fail when entity does not exist", async () => { | ||||||||||||||||||||
|
@@ -275,9 +279,9 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}), | ||||||||||||||||||||
headers: {'Content-Type': 'application/json'}, | ||||||||||||||||||||
}); | ||||||||||||||||||||
assert.strictEqual(response.status, 200); | ||||||||||||||||||||
strictEqual(response.status, 200); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
const body = await response.text(); | ||||||||||||||||||||
assert.strictEqual(body, `Entity ${KIND}/nonexistent deleted.`); | ||||||||||||||||||||
strictEqual(body, `Entity ${KIND}/nonexistent deleted.`); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
it('del: Deletes an entity', async () => { | ||||||||||||||||||||
|
@@ -289,13 +293,13 @@ describe('functions/datastore', () => { | |||||||||||||||||||
}), | ||||||||||||||||||||
headers: {'Content-Type': 'application/json'}, | ||||||||||||||||||||
}); | ||||||||||||||||||||
assert.strictEqual(response.status, 200); | ||||||||||||||||||||
strictEqual(response.status, 200); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
const body = await response.text(); | ||||||||||||||||||||
assert.strictEqual(body, `Entity ${KIND}/${NAME} deleted.`); | ||||||||||||||||||||
strictEqual(body, `Entity ${KIND}/${NAME} deleted.`); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change switches from
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
const key = datastore.key([KIND, NAME]); | ||||||||||||||||||||
const [entity] = await datastore.get(key); | ||||||||||||||||||||
assert.ok(!entity); | ||||||||||||||||||||
ok(!entity); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
}); | ||||||||||||||||||||
}); | ||||||||||||||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change switches from
sinon.stub()
tostub()
. Ensure thatstub
is correctly imported fromsinon
.