Skip to content

Commit

Permalink
Update dependencies + fix missing Pub/Sub ACKs (#144)
Browse files Browse the repository at this point in the history
* Update dependencies + fix missing ACKs

* Work around semistandard's unintuitive lack of recursion

* Misc fix: move cloudsql tests to appropriate location

* Update MongoDB snippets to match new library

* Add MONGO_DB_NAME to env-var set

* DEBUG: print out config.json value

* DEBUG: Try to figure out why MONGO_DB_NAME is not being read from config.json

* Debug: further debugging

* Revert debugging code + fix MONGO_DB_NAME errors
  • Loading branch information
Ace Nassri committed Jan 25, 2018
1 parent d9f6d5f commit 9a3ed7e
Show file tree
Hide file tree
Showing 39 changed files with 136 additions and 84 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions 1-hello-world/package.json
Expand Up @@ -56,8 +56,8 @@
"express": "4.16.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.1.1",
"ava": "0.23.0",
"@google-cloud/nodejs-repo-tools": "2.1.4",
"ava": "0.24.0",
"supertest": "3.0.0"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion 2-structured-data/books/model-mongodb.js
Expand Up @@ -42,11 +42,12 @@ function getCollection (cb) {
});
return;
}
MongoClient.connect(config.get('MONGO_URL'), (err, db) => {
MongoClient.connect(config.get('MONGO_URL'), (err, client) => {
if (err) {
cb(err);
return;
}
const db = client.db(config.get('MONGO_DB_NAME'));
collection = db.collection(config.get('MONGO_COLLECTION'));
cb(null, collection);
});
Expand Down
2 changes: 2 additions & 0 deletions 2-structured-data/config.js
Expand Up @@ -28,6 +28,7 @@ nconf
'INSTANCE_CONNECTION_NAME',
'MONGO_URL',
'MONGO_COLLECTION',
'MONGO_DB_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'NODE_ENV',
Expand Down Expand Up @@ -69,6 +70,7 @@ if (nconf.get('DATA_BACKEND') === 'cloudsql') {
} else if (nconf.get('DATA_BACKEND') === 'mongodb') {
checkConfig('MONGO_URL');
checkConfig('MONGO_COLLECTION');
checkConfig('MONGO_DB_NAME');
}

function checkConfig (setting) {
Expand Down
14 changes: 7 additions & 7 deletions 2-structured-data/package.json
Expand Up @@ -54,22 +54,22 @@
]
},
"dependencies": {
"@google-cloud/datastore": "1.1.0",
"@google-cloud/datastore": "1.3.3",
"body-parser": "1.18.2",
"express": "4.16.2",
"lodash": "4.17.4",
"mongodb": "2.2.33",
"mongodb": "3.0.1",
"mysql": "2.15.0",
"nconf": "0.8.5",
"nconf": "0.10.0",
"prompt": "1.0.0",
"pug": "2.0.0-rc.4",
"uglify-js": "3.1.6"
"uglify-js": "3.3.7"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.1.1",
"ava": "0.23.0",
"@google-cloud/nodejs-repo-tools": "2.1.4",
"ava": "0.24.0",
"proxyquire": "1.8.0",
"sinon": "4.0.2"
"sinon": "4.1.6"
},
"engines": {
"node": ">=4.3.2"
Expand Down
3 changes: 3 additions & 0 deletions 2-structured-data/test/app.test.js
Expand Up @@ -67,6 +67,9 @@ test(`should check config`, (t) => {

nconfMock.DATA_BACKEND = `mongodb`;

t.throws(testFunc, Error, getMsg(`MONGO_DB_NAME`));
nconfMock.MONGO_DB_NAME = `test`;

t.throws(testFunc, Error, getMsg(`MONGO_URL`));
nconfMock.MONGO_URL = `url`;

Expand Down
3 changes: 2 additions & 1 deletion 3-binary-data/books/model-mongodb.js
Expand Up @@ -40,11 +40,12 @@ function getCollection (cb) {
});
return;
}
MongoClient.connect(config.get('MONGO_URL'), (err, db) => {
MongoClient.connect(config.get('MONGO_URL'), (err, client) => {
if (err) {
cb(err);
return;
}
const db = client.db(config.get('MONGO_DB_NAME'));
collection = db.collection(config.get('MONGO_COLLECTION'));
cb(null, collection);
});
Expand Down
2 changes: 2 additions & 0 deletions 3-binary-data/config.js
Expand Up @@ -29,6 +29,7 @@ nconf
'INSTANCE_CONNECTION_NAME',
'MONGO_URL',
'MONGO_COLLECTION',
'MONGO_DB_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'NODE_ENV',
Expand Down Expand Up @@ -74,6 +75,7 @@ if (nconf.get('DATA_BACKEND') === 'cloudsql') {
} else if (nconf.get('DATA_BACKEND') === 'mongodb') {
checkConfig('MONGO_URL');
checkConfig('MONGO_COLLECTION');
checkConfig('MONGO_DB_NAME');
}

function checkConfig (setting) {
Expand Down
16 changes: 8 additions & 8 deletions 3-binary-data/package.json
Expand Up @@ -54,24 +54,24 @@
]
},
"dependencies": {
"@google-cloud/datastore": "1.1.0",
"@google-cloud/storage": "1.4.0",
"@google-cloud/datastore": "1.3.3",
"@google-cloud/storage": "1.5.2",
"body-parser": "1.18.2",
"express": "4.16.2",
"lodash": "4.17.4",
"mongodb": "2.2.33",
"mongodb": "3.0.1",
"multer": "1.3.0",
"mysql": "2.15.0",
"nconf": "0.8.5",
"nconf": "0.10.0",
"prompt": "1.0.0",
"pug": "2.0.0-rc.4",
"uglify-js": "3.1.6"
"uglify-js": "3.3.7"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.1.1",
"ava": "0.23.0",
"@google-cloud/nodejs-repo-tools": "2.1.4",
"ava": "0.24.0",
"proxyquire": "1.8.0",
"sinon": "4.0.2"
"sinon": "4.1.6"
},
"engines": {
"node": ">=4.3.2"
Expand Down
3 changes: 3 additions & 0 deletions 3-binary-data/test/app.test.js
Expand Up @@ -70,6 +70,9 @@ test(`should check config`, (t) => {

nconfMock.DATA_BACKEND = `mongodb`;

t.throws(testFunc, Error, getMsg(`MONGO_DB_NAME`));
nconfMock.MONGO_DB_NAME = `test`;

t.throws(testFunc, Error, getMsg(`MONGO_URL`));
nconfMock.MONGO_URL = `url`;

Expand Down
3 changes: 2 additions & 1 deletion 4-auth/books/model-mongodb.js
Expand Up @@ -40,12 +40,13 @@ function getCollection (cb) {
});
return;
}
MongoClient.connect(config.get('MONGO_URL'), (err, db) => {
MongoClient.connect(config.get('MONGO_URL'), (err, client) => {
if (err) {
console.log(err);
cb(err);
return;
}
const db = client.db(config.get('MONGO_DB_NAME'));
collection = db.collection(config.get('MONGO_COLLECTION'));
cb(null, collection);
});
Expand Down
2 changes: 2 additions & 0 deletions 4-auth/config.js
Expand Up @@ -29,6 +29,7 @@ nconf
'MEMCACHE_URL',
'MONGO_URL',
'MONGO_COLLECTION',
'MONGO_DB_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'INSTANCE_CONNECTION_NAME',
Expand Down Expand Up @@ -91,6 +92,7 @@ if (nconf.get('DATA_BACKEND') === 'cloudsql') {
} else if (nconf.get('DATA_BACKEND') === 'mongodb') {
checkConfig('MONGO_URL');
checkConfig('MONGO_COLLECTION');
checkConfig('MONGO_DB_NAME');
}

function checkConfig (setting) {
Expand Down
16 changes: 8 additions & 8 deletions 4-auth/package.json
Expand Up @@ -54,28 +54,28 @@
]
},
"dependencies": {
"@google-cloud/datastore": "1.1.0",
"@google-cloud/storage": "1.4.0",
"@google-cloud/datastore": "1.3.3",
"@google-cloud/storage": "1.5.2",
"body-parser": "1.18.2",
"connect-memcached": "0.2.0",
"express": "4.16.2",
"express-session": "1.15.6",
"lodash": "4.17.4",
"mongodb": "2.2.33",
"mongodb": "3.0.1",
"multer": "1.3.0",
"mysql": "2.15.0",
"nconf": "0.8.5",
"nconf": "0.10.0",
"passport": "0.4.0",
"passport-google-oauth20": "1.0.0",
"prompt": "1.0.0",
"pug": "2.0.0-rc.4",
"uglify-js": "3.1.6"
"uglify-js": "3.3.7"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.1.1",
"ava": "0.23.0",
"@google-cloud/nodejs-repo-tools": "2.1.4",
"ava": "0.24.0",
"proxyquire": "1.8.0",
"sinon": "4.0.2"
"sinon": "4.1.6"
},
"engines": {
"node": ">=4.3.2"
Expand Down
3 changes: 3 additions & 0 deletions 4-auth/test/app.test.js
Expand Up @@ -76,6 +76,9 @@ test(`should check config`, (t) => {

nconfMock.DATA_BACKEND = `mongodb`;

t.throws(testFunc, Error, getMsg(`MONGO_DB_NAME`));
nconfMock.MONGO_DB_NAME = `test`;

t.throws(testFunc, Error, getMsg(`MONGO_URL`));
nconfMock.MONGO_URL = `url`;

Expand Down
3 changes: 2 additions & 1 deletion 5-logging/books/model-mongodb.js
Expand Up @@ -40,11 +40,12 @@ function getCollection (cb) {
});
return;
}
MongoClient.connect(config.get('MONGO_URL'), (err, db) => {
MongoClient.connect(config.get('MONGO_URL'), (err, client) => {
if (err) {
cb(err);
return;
}
const db = client.db(config.get('MONGO_DB_NAME'));
collection = db.collection(config.get('MONGO_COLLECTION'));
cb(null, collection);
});
Expand Down
2 changes: 2 additions & 0 deletions 5-logging/config.js
Expand Up @@ -29,6 +29,7 @@ nconf
'MEMCACHE_URL',
'MONGO_URL',
'MONGO_COLLECTION',
'MONGO_DB_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'INSTANCE_CONNECTION_NAME',
Expand Down Expand Up @@ -91,6 +92,7 @@ if (nconf.get('DATA_BACKEND') === 'cloudsql') {
} else if (nconf.get('DATA_BACKEND') === 'mongodb') {
checkConfig('MONGO_URL');
checkConfig('MONGO_COLLECTION');
checkConfig('MONGO_DB_NAME');
}

function checkConfig (setting) {
Expand Down
22 changes: 11 additions & 11 deletions 5-logging/package.json
Expand Up @@ -54,33 +54,33 @@
]
},
"dependencies": {
"@google-cloud/datastore": "1.1.0",
"@google-cloud/debug-agent": "2.2.2",
"@google-cloud/logging-winston": "^0.6.0",
"@google-cloud/storage": "1.4.0",
"@google-cloud/trace-agent": "2.3.1",
"@google-cloud/datastore": "1.3.3",
"@google-cloud/debug-agent": "2.3.2",
"@google-cloud/logging-winston": "^0.7.0",
"@google-cloud/storage": "1.5.2",
"@google-cloud/trace-agent": "2.4.1",
"body-parser": "1.18.2",
"connect-memcached": "0.2.0",
"express": "4.16.2",
"express-session": "1.15.6",
"express-winston": "2.4.0",
"lodash": "4.17.4",
"mongodb": "2.2.33",
"mongodb": "3.0.1",
"multer": "1.3.0",
"mysql": "2.15.0",
"nconf": "0.8.5",
"nconf": "0.10.0",
"passport": "0.4.0",
"passport-google-oauth20": "1.0.0",
"prompt": "1.0.0",
"pug": "2.0.0-rc.4",
"uglify-js": "3.1.6",
"uglify-js": "3.3.7",
"winston": "2.4.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "2.1.1",
"ava": "0.23.0",
"@google-cloud/nodejs-repo-tools": "2.1.4",
"ava": "0.24.0",
"proxyquire": "1.8.0",
"sinon": "4.0.2",
"sinon": "4.1.6",
"supertest": "3.0.0"
},
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions 5-logging/test/app.test.js
Expand Up @@ -76,6 +76,9 @@ test(`should check config`, (t) => {

nconfMock.DATA_BACKEND = `mongodb`;

t.throws(testFunc, Error, getMsg(`MONGO_DB_NAME`));
nconfMock.MONGO_DB_NAME = `test`;

t.throws(testFunc, Error, getMsg(`MONGO_URL`));
nconfMock.MONGO_URL = `url`;

Expand Down
3 changes: 2 additions & 1 deletion 6-pubsub/books/model-mongodb.js
Expand Up @@ -41,11 +41,12 @@ function getCollection (cb) {
});
return;
}
MongoClient.connect(config.get('MONGO_URL'), (err, db) => {
MongoClient.connect(config.get('MONGO_URL'), (err, client) => {
if (err) {
cb(err);
return;
}
const db = client.db(config.get('MONGO_DB_NAME'));
collection = db.collection(config.get('MONGO_COLLECTION'));
cb(null, collection);
});
Expand Down
2 changes: 2 additions & 0 deletions 6-pubsub/config.js
Expand Up @@ -29,6 +29,7 @@ nconf
'MEMCACHE_URL',
'MONGO_URL',
'MONGO_COLLECTION',
'MONGO_DB_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'INSTANCE_CONNECTION_NAME',
Expand Down Expand Up @@ -96,6 +97,7 @@ if (nconf.get('DATA_BACKEND') === 'cloudsql') {
} else if (nconf.get('DATA_BACKEND') === 'mongodb') {
checkConfig('MONGO_URL');
checkConfig('MONGO_COLLECTION');
checkConfig('MONGO_DB_NAME');
}

function checkConfig (setting) {
Expand Down
1 change: 1 addition & 0 deletions 6-pubsub/lib/background.js
Expand Up @@ -53,6 +53,7 @@ function subscribe (cb) {
// Event handlers
function handleMessage (message) {
const data = JSON.parse(message.data);
message.ack();
cb(null, data);
}
function handleError (err) {
Expand Down
5 changes: 4 additions & 1 deletion 6-pubsub/test/_test-config.worker.js
Expand Up @@ -22,7 +22,6 @@ const VERSION = `${process.env.GAE_VERSION || TESTNAME}`;
module.exports = {
test: TESTNAME,
url: `http://localhost:${PORT}`,
testUrl: `https://${VERSION}-dot-worker-dot-${PROJECT_ID}.appspot.com`,
yaml: `worker.yaml`,
cwd: path.resolve(path.join(__dirname, `../`)),
cmd: `worker`,
Expand All @@ -35,3 +34,7 @@ module.exports = {
version: VERSION,
project: PROJECT_ID
};

if (process.env.E2E_TESTS) {
module.exports.testUrl = `https://${VERSION}-dot-worker-dot-${PROJECT_ID}.appspot.com`;
}
3 changes: 3 additions & 0 deletions 6-pubsub/test/app.test.js
Expand Up @@ -76,6 +76,9 @@ test(`should check config`, (t) => {

nconfMock.DATA_BACKEND = `mongodb`;

t.throws(testFunc, Error, getMsg(`MONGO_DB_NAME`));
nconfMock.MONGO_DB_NAME = `test`;

t.throws(testFunc, Error, getMsg(`MONGO_URL`));
nconfMock.MONGO_URL = `url`;

Expand Down
3 changes: 2 additions & 1 deletion 6-pubsub/test/background.test.js
Expand Up @@ -122,7 +122,8 @@ test.serial.cb(`should subscribe and log message`, (t) => {
// Trigger a message
setTimeout(() => {
mocks.subscription.on.firstCall.args[1]({
data: JSON.stringify(testMessage)
data: JSON.stringify(testMessage),
ack: sinon.stub()
});
}, 10);
});
Expand Down

0 comments on commit 9a3ed7e

Please sign in to comment.