Skip to content

Commit

Permalink
functions/sql to mocha (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman authored and fhinkel committed Apr 4, 2019
1 parent 1c8d086 commit f430af0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions functions/sql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"start-proxy-pg": "cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME-pg=tcp:5432 &",
"start-proxy": "! pgrep cloud_sql_proxy > /dev/null && npm run start-proxy-pg && npm run start-proxy-mysql || exit 0",
"kill-proxy": "killall cloud_sql_proxy",
"ava": "ava -T 20s --verbose test/*.test.js",
"test": "npm run start-proxy && npm run ava && npm run kill-proxy"
"mocha": "mocha test/*.test.js --timeout=20000",
"test": "npm run start-proxy && npm run mocha && npm run kill-proxy"
},
"dependencies": {
"mysql": "^2.16.0",
"pg": "^7.4.3"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"mocha": "^6.0.0",
"proxyquire": "^2.1.0",
"sinon": "^7.3.0"
},
Expand Down
18 changes: 9 additions & 9 deletions functions/sql/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';

const sinon = require(`sinon`);
const test = require(`ava`);
const assert = require(`assert`);
const proxyquire = require(`proxyquire`);

const INSTANCE_PREFIX = `nodejs-docs-samples:us-central1:integration-tests-instance`;
Expand All @@ -29,7 +29,7 @@ const getProgram = env => {
});
};

test(`should query MySQL`, async t => {
it('should query MySQL', async () => {
const program = getProgram({
INSTANCE_CONNECTION_NAME: `${INSTANCE_PREFIX}-mysql`,
SQL_USER: process.env.MYSQL_USER,
Expand All @@ -49,14 +49,14 @@ test(`should query MySQL`, async t => {
setTimeout(resolve, 1500);
});

t.false(resMock.status.called);
t.true(resMock.send.calledOnce);
assert.strictEqual(resMock.status.called, false);
assert.ok(resMock.send.calledOnce);

const response = resMock.send.firstCall.args[0];
t.regex(response, /\d{4}-\d{1,2}-\d{1,2}/);
assert.ok(new RegExp(/\d{4}-\d{1,2}-\d{1,2}/).test(response.message));
});

test(`should query Postgres`, async t => {
it('should query Postgres', async () => {
const program = getProgram({
INSTANCE_CONNECTION_NAME: `${INSTANCE_PREFIX}-pg`,
SQL_USER: process.env.POSTGRES_USER,
Expand All @@ -76,9 +76,9 @@ test(`should query Postgres`, async t => {
setTimeout(resolve, 1500);
});

t.false(resMock.status.called);
t.true(resMock.send.calledOnce);
assert.strictEqual(resMock.status.called, false);
assert.ok(resMock.send.calledOnce);

const response = resMock.send.firstCall.args[0];
t.regex(response, /\d{4}-\d{1,2}-\d{1,2}/);
assert.ok(new RegExp(/\d{4}-\d{1,2}-\d{1,2}/).test(response.message));
});

0 comments on commit f430af0

Please sign in to comment.