From bf778cc0936c16ee0ef7b396c4698c2a1df30ce5 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 4 Oct 2018 08:09:57 -0700 Subject: [PATCH] chore: use arrow functions --- .eslintrc.yml | 1 + package.json | 2 +- src/batch-transaction.js | 9 +- src/codec.js | 12 +- src/database.js | 67 +-- src/index.js | 30 +- src/instance.js | 35 +- src/partial-result-stream.js | 10 +- src/row-builder.js | 23 +- src/session.js | 2 +- src/table.js | 4 +- src/transaction-request.js | 17 +- src/transaction.js | 62 +- system-test/spanner.js | 982 ++++++++++++++++---------------- test/batch-transaction.js | 66 +-- test/codec.js | 220 +++---- test/database.js | 408 ++++++------- test/gapic-v1-database-admin.js | 4 +- test/gapic-v1-instance-admin.js | 4 +- test/gapic-v1.js | 4 +- test/index.js | 218 +++---- test/instance.js | 174 +++--- test/partial-result-stream.js | 68 +-- test/row-builder.js | 108 ++-- test/session-pool.js | 408 +++++++------ test/session.js | 64 +-- test/table.js | 90 +-- test/transaction-request.js | 108 ++-- test/transaction.js | 294 +++++----- 29 files changed, 1734 insertions(+), 1760 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 73eeec276..e7711ec21 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -13,3 +13,4 @@ rules: no-warning-comments: warn no-var: error prefer-const: error + prefer-arrow-callback: error diff --git a/package.json b/package.json index 495ce7e2b..6709a84de 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "test-no-cover": "mocha test/*.js", "test": "npm run cover", "ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb", - "fix": "eslint --fix '**/*.js' && npm run prettier" + "fix": "eslint --fix '**/*.js'" }, "dependencies": { "@google-cloud/common-grpc": "^0.9.0", diff --git a/src/batch-transaction.js b/src/batch-transaction.js index 089eca72f..538b00913 100644 --- a/src/batch-transaction.js +++ b/src/batch-transaction.js @@ -143,24 +143,23 @@ class BatchTransaction extends Transaction { * @param {function} callback Callback function. */ createPartitions_(config, callback) { - const self = this; const query = extend({}, config.reqOpts, { session: this.session.formattedName_, transaction: {id: this.id}, }); config.reqOpts = extend({}, query); delete query.partitionOptions; - this.request(config, function(err, resp) { + this.request(config, (err, resp) => { if (err) { callback(err, null, resp); return; } - const partitions = resp.partitions.map(function(partition) { + const partitions = resp.partitions.map(partition => { return extend({}, query, partition); }); if (resp.transaction) { - self.id = resp.transaction.id; - self.readTimestamp = resp.transaction.readTimestamp; + this.id = resp.transaction.id; + this.readTimestamp = resp.transaction.readTimestamp; } callback(null, partitions, resp); }); diff --git a/src/codec.js b/src/codec.js index 8dfb0606f..d1ff8a2a5 100644 --- a/src/codec.js +++ b/src/codec.js @@ -138,7 +138,7 @@ Struct.fromArray = function(arr) { Struct.fromJSON = function(json) { const struct = new Struct(); - Object.keys(json || {}).forEach(function(name) { + Object.keys(json || {}).forEach(name => { const value = json[name]; struct.push({name, value}); }); @@ -176,7 +176,7 @@ function generateToJSONFromRow(row) { options ); - return row.reduce(function(serializedRow, keyVal) { + return row.reduce((serializedRow, keyVal) => { const name = keyVal.name; let value = keyVal.value; @@ -240,7 +240,7 @@ function decode(value, field) { break; } case 'ARRAY': { - decoded = decoded.map(function(value) { + decoded = decoded.map(value => { return decodeValue_(value, type.arrayElementType); }); break; @@ -365,7 +365,7 @@ function getType(field) { } if (Struct.isStruct(field)) { - const fields = field.map(function(field) { + const fields = field.map(field => { return { name: field.name, type: getType(field.value), @@ -492,7 +492,7 @@ function encodeRead(query) { } if (query.keys) { - encoded.keySet.keys = arrify(query.keys).map(function(key) { + encoded.keySet.keys = arrify(query.keys).map(key => { return { values: arrify(key).map(codec.encode), }; @@ -501,7 +501,7 @@ function encodeRead(query) { } if (query.ranges) { - encoded.keySet.ranges = arrify(query.ranges).map(function(rawRange) { + encoded.keySet.ranges = arrify(query.ranges).map(rawRange => { const range = extend({}, rawRange); for (const bound in range) { diff --git a/src/database.js b/src/database.js index c5fd2c1ae..5772c8d8a 100644 --- a/src/database.js +++ b/src/database.js @@ -263,19 +263,18 @@ class Database extends ServiceObject { * @returns {Promise} */ createBatchTransaction(options, callback) { - const self = this; if (is.fn(options)) { callback = options; options = null; } - this.createSession(function(err, session, resp) { + this.createSession((err, session, resp) => { if (err) { callback(err, null, resp); return; } - const transaction = self.batchTransaction({session}); + const transaction = this.batchTransaction({session}); transaction.options = extend({}, options); - transaction.begin(function(err, resp) { + transaction.begin((err, resp) => { if (err) { callback(err, null, resp); return; @@ -341,7 +340,6 @@ class Database extends ServiceObject { * }); */ createSession(options, callback) { - const self = this; if (is.function(options)) { callback = options; options = {}; @@ -357,12 +355,12 @@ class Database extends ServiceObject { reqOpts: reqOpts, gaxOpts: options, }, - function(err, resp) { + (err, resp) => { if (err) { callback(err, null, resp); return; } - const session = self.session(resp.name); + const session = this.session(resp.name); session.metadata = resp; callback(null, session, resp); } @@ -436,14 +434,13 @@ class Database extends ServiceObject { * }); */ createTable(schema, callback) { - const self = this; - this.updateSchema(schema, function(err, operation, resp) { + this.updateSchema(schema, (err, operation, resp) => { if (err) { callback(err, null, null, resp); return; } const tableName = schema.match(/CREATE TABLE `*([^\s`(]+)/)[1]; - const table = self.table(tableName); + const table = this.table(tableName); callback(null, table, operation, resp); }); } @@ -499,12 +496,11 @@ class Database extends ServiceObject { * }); */ delete(callback) { - const self = this; const reqOpts = { database: this.formattedName_, }; - this.close(function() { - self.request( + this.close(() => { + this.request( { client: 'DatabaseAdminClient', method: 'dropDatabase', @@ -549,7 +545,7 @@ class Database extends ServiceObject { exists(callback) { const NOT_FOUND = 5; - this.getMetadata(function(err) { + this.getMetadata(err => { if (err && err.code !== NOT_FOUND) { callback(err, null); return; @@ -604,22 +600,21 @@ class Database extends ServiceObject { * }); */ get(options, callback) { - const self = this; if (is.fn(options)) { callback = options; options = {}; } - this.getMetadata(function(err, metadata) { + this.getMetadata((err, metadata) => { if (err) { if (options.autoCreate && err.code === 5) { - self.create(options, function(err, database, operation) { + this.create(options, (err, database, operation) => { if (err) { callback(err); return; } - operation.on('error', callback).on('complete', function(metadata) { - self.metadata = metadata; - callback(null, self, metadata); + operation.on('error', callback).on('complete', metadata => { + this.metadata = metadata; + callback(null, this, metadata); }); }); return; @@ -627,7 +622,7 @@ class Database extends ServiceObject { callback(err); return; } - callback(null, self, metadata); + callback(null, this, metadata); }); } /** @@ -846,7 +841,7 @@ class Database extends ServiceObject { }, function(err, sessions) { if (sessions) { - arguments[1] = sessions.map(function(metadata) { + arguments[1] = sessions.map(metadata => { const session = self.session(metadata.name); session.metadata = metadata; return session; @@ -893,32 +888,31 @@ class Database extends ServiceObject { * }); */ getTransaction(options, callback) { - const self = this; if (is.fn(options)) { callback = options; options = null; } if (!options || !options.readOnly) { - this.pool_.getWriteSession(function(err, session, transaction) { + this.pool_.getWriteSession((err, session, transaction) => { if (!err) { - transaction = self.decorateTransaction_(transaction, session); + transaction = this.decorateTransaction_(transaction, session); } callback(err, transaction); }); return; } - this.pool_.getReadSession(function(err, session) { + this.pool_.getReadSession((err, session) => { if (err) { callback(err, null); return; } - session.beginTransaction(options, function(err, transaction) { + session.beginTransaction(options, (err, transaction) => { if (err) { - self.pool_.release(session); + this.pool_.release(session); callback(err, null); return; } - transaction = self.decorateTransaction_(transaction, session); + transaction = this.decorateTransaction_(transaction, session); callback(null, transaction); }); }); @@ -932,15 +926,14 @@ class Database extends ServiceObject { * @param {function} callback Callback function */ makePooledRequest_(config, callback) { - const self = this; const pool = this.pool_; - pool.getReadSession(function(err, session) { + pool.getReadSession((err, session) => { if (err) { callback(err, null); return; } config.reqOpts.session = session.formattedName_; - self.request(config, function() { + this.request(config, function() { pool.release(session); callback.apply(null, arguments); }); @@ -976,8 +969,8 @@ class Database extends ServiceObject { session = null; } } - waitForSessionStream.on('reading', function() { - pool.getReadSession(function(err, session_) { + waitForSessionStream.on('reading', () => { + pool.getReadSession((err, session_) => { if (err) { destroyStream(err); return; @@ -1158,10 +1151,10 @@ class Database extends ServiceObject { } this.runStream(query, options) .on('error', callback) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { callback(null, rows); }); } @@ -1432,7 +1425,7 @@ class Database extends ServiceObject { options = null; } options = extend({}, options); - this.getTransaction(options, function(err, transaction) { + this.getTransaction(options, (err, transaction) => { if (err) { callback(err); return; diff --git a/src/index.js b/src/index.js index 1a0148a00..4752baa40 100644 --- a/src/index.js +++ b/src/index.js @@ -281,7 +281,6 @@ class Spanner extends Service { ['A configuration object is required to create an instance.'].join('') ); } - const self = this; const formattedName = Instance.formatName_(this.projectId, name); const shortName = formattedName.split('/').pop(); const reqOpts = { @@ -310,12 +309,12 @@ class Spanner extends Service { method: 'createInstance', reqOpts: reqOpts, }, - function(err, operation, resp) { + (err, operation, resp) => { if (err) { callback(err, null, null, resp); return; } - const instance = self.instance(formattedName); + const instance = this.instance(formattedName); callback(null, instance, operation, resp); } ); @@ -418,7 +417,7 @@ class Spanner extends Service { }, function(err, instances) { if (instances) { - arguments[1] = instances.map(function(instance) { + arguments[1] = instances.map(instance => { const instanceInstance = self.instance(instance.name); instanceInstance.metadata = instance; return instanceInstance; @@ -620,17 +619,16 @@ class Spanner extends Service { * @param {function} callback Callback function */ prepareGapicRequest_(config, callback) { - const self = this; - this.auth.getProjectId(function(err, projectId) { + this.auth.getProjectId((err, projectId) => { if (err) { callback(err); return; } const clientName = config.client; - if (!self.clients_.has(clientName)) { - self.clients_.set(clientName, new gapic.v1[clientName](self.options)); + if (!this.clients_.has(clientName)) { + this.clients_.set(clientName, new gapic.v1[clientName](this.options)); } - const gaxClient = self.clients_.get(clientName); + const gaxClient = this.clients_.get(clientName); let reqOpts = extend(true, {}, config.reqOpts); reqOpts = replaceProjectIdToken(reqOpts, projectId); const requestFn = gaxClient[config.method].bind( @@ -653,9 +651,8 @@ class Spanner extends Service { * @returns {Promise} */ request(config, callback) { - const self = this; if (is.fn(callback)) { - self.prepareGapicRequest_(config, function(err, requestFn) { + this.prepareGapicRequest_(config, (err, requestFn) => { if (err) { callback(err); } else { @@ -663,8 +660,8 @@ class Spanner extends Service { } }); } else { - return new this.Promise(function(resolve, reject) { - self.prepareGapicRequest_(config, function(err, requestFn) { + return new this.Promise((resolve, reject) => { + this.prepareGapicRequest_(config, (err, requestFn) => { if (err) { reject(err); } else { @@ -687,16 +684,15 @@ class Spanner extends Service { * @returns {Stream} */ requestStream(config) { - const self = this; const stream = streamEvents(through.obj()); - stream.once('reading', function() { - self.prepareGapicRequest_(config, function(err, requestFn) { + stream.once('reading', () => { + this.prepareGapicRequest_(config, (err, requestFn) => { if (err) { stream.destroy(err); return; } requestFn() - .on('error', function(err) { + .on('error', err => { stream.destroy(err); }) .pipe(stream); diff --git a/src/instance.js b/src/instance.js index 934f624d3..dc875c140 100644 --- a/src/instance.js +++ b/src/instance.js @@ -195,7 +195,6 @@ class Instance extends common.ServiceObject { * Full example: */ createDatabase(name, options, callback) { - const self = this; if (!name) { throw new Error('A name is required to create a database.'); } @@ -225,12 +224,12 @@ class Instance extends common.ServiceObject { method: 'createDatabase', reqOpts: reqOpts, }, - function(err, operation, resp) { + (err, operation, resp) => { if (err) { callback(err, null, null, resp); return; } - const database = self.database(name, poolOptions || poolCtor); + const database = this.database(name, poolOptions || poolCtor); callback(null, database, operation, resp); } ); @@ -304,27 +303,26 @@ class Instance extends common.ServiceObject { * }); */ delete(callback) { - const self = this; const reqOpts = { name: this.formattedName_, }; Promise.all( - Array.from(this.databases_.values()).map(function(database) { + Array.from(this.databases_.values()).map(database => { return database.close(); }) ) .catch(common.util.noop) - .then(function() { - self.databases_.clear(); - self.request( + .then(() => { + this.databases_.clear(); + this.request( { client: 'InstanceAdminClient', method: 'deleteInstance', reqOpts: reqOpts, }, - function(err, resp) { + (err, resp) => { if (!err) { - self.parent.instances_.delete(self.id); + this.parent.instances_.delete(this.id); } callback(err, resp); } @@ -365,7 +363,7 @@ class Instance extends common.ServiceObject { exists(callback) { const NOT_FOUND = 5; - this.getMetadata(function(err) { + this.getMetadata(err => { if (err && err.code !== NOT_FOUND) { callback(err, null); return; @@ -419,22 +417,21 @@ class Instance extends common.ServiceObject { * }); */ get(options, callback) { - const self = this; if (is.fn(options)) { callback = options; options = {}; } - this.getMetadata(function(err, metadata) { + this.getMetadata((err, metadata) => { if (err) { if (err.code === 5 && options.autoCreate) { - self.create(options, function(err, database, operation) { + this.create(options, (err, database, operation) => { if (err) { callback(err); return; } - operation.on('error', callback).on('complete', function(metadata) { - self.metadata = metadata; - callback(null, self, metadata); + operation.on('error', callback).on('complete', metadata => { + this.metadata = metadata; + callback(null, this, metadata); }); }); return; @@ -442,7 +439,7 @@ class Instance extends common.ServiceObject { callback(err); return; } - callback(null, self, metadata); + callback(null, this, metadata); }); } /** @@ -530,7 +527,7 @@ class Instance extends common.ServiceObject { }, function(err, databases) { if (databases) { - arguments[1] = databases.map(function(database) { + arguments[1] = databases.map(database => { const databaseInstance = self.database(database.name); databaseInstance.metadata = database; return databaseInstance; diff --git a/src/partial-result-stream.js b/src/partial-result-stream.js index 8d53872b3..a7b8657ab 100644 --- a/src/partial-result-stream.js +++ b/src/partial-result-stream.js @@ -69,7 +69,7 @@ function partialResultStream(requestFn, options) { let builder; const userStream = streamEvents( - through.obj(function(row, _, next) { + through.obj((row, _, next) => { /** * Emits the raw API response. * @@ -112,7 +112,7 @@ function partialResultStream(requestFn, options) { userStream.once('reading', makeRequest); return requestsStream - .intercept('error', function(err) { + .intercept('error', err => { if (lastResumeToken) { // We're going to retry from where we left off. // Empty queued rows on the checkpoint stream (will not emit them to @@ -122,7 +122,7 @@ function partialResultStream(requestFn, options) { return; } - setImmediate(function() { + setImmediate(() => { // We won't retry the request, so this will flush any rows the // checkpoint stream has queued. After that, we will destroy the user's // stream with the same error. @@ -130,13 +130,13 @@ function partialResultStream(requestFn, options) { }); }) .pipe(batchAndSplitOnTokenStream) - .on('error', function(err) { + .on('error', err => { // If we get this error, the checkpoint stream has flushed any rows it had // queued. We can now destroy the user's stream, as our retry attempts are // over. userStream.destroy(err); }) - .on('checkpoint', function(row) { + .on('checkpoint', row => { lastResumeToken = row.resumeToken; }) .pipe(userStream); diff --git a/src/row-builder.js b/src/row-builder.js index 121b402f0..6f48065d6 100644 --- a/src/row-builder.js +++ b/src/row-builder.js @@ -60,25 +60,24 @@ class RowBuilder { * Process chunks. */ build() { - const self = this; - this.chunks.forEach(function(chunk) { + this.chunks.forEach(chunk => { // If we have a chunk to merge, merge the values now. - if (self.pendingChunk) { - const currentColumn = self.currentRow.length % self.fields.length; + if (this.pendingChunk) { + const currentColumn = this.currentRow.length % this.fields.length; const merged = RowBuilder.merge( - self.fields[currentColumn].type, - self.pendingChunk, + this.fields[currentColumn].type, + this.pendingChunk, chunk.values.shift() ); chunk.values = merged.concat(chunk.values); - delete self.pendingChunk; + delete this.pendingChunk; } // If the chunk is chunked, store the last value for merging with the next // chunk to be processed. if (chunk.chunkedValue) { - self.pendingChunk = chunk.values.pop(); + this.pendingChunk = chunk.values.pop(); } - chunk.values.map(RowBuilder.getValue).forEach(self.append.bind(self)); + chunk.values.map(RowBuilder.getValue).forEach(this.append.bind(this)); }); // As chunks are now in rows, remove them. this.chunks.length = 0; @@ -152,14 +151,14 @@ class RowBuilder { return null; } if (field.code === 'ARRAY') { - return value.map(function(value) { + return value.map(value => { return RowBuilder.formatValue(field.arrayElementType, value); }); } if (field.code !== 'STRUCT') { return codec.decode(value, field); } - return field.structType.fields.reduce(function(struct, field, index) { + return field.structType.fields.reduce((struct, field, index) => { struct[field.name] = RowBuilder.formatValue(field, value[index]); return struct; }, {}); @@ -193,7 +192,7 @@ class RowBuilder { merged.push(head, tail); } // Filter out empty strings. - return merged.filter(function(value) { + return merged.filter(value => { return !is.string(value) || value.length; }); } diff --git a/src/session.js b/src/session.js index 857407d5f..c0c0b163d 100644 --- a/src/session.js +++ b/src/session.js @@ -218,7 +218,7 @@ class Session extends ServiceObject { options = {}; } const transaction = this.transaction(options); - transaction.begin(function(err, resp) { + transaction.begin((err, resp) => { if (err) { callback(err, null, resp); return; diff --git a/src/table.js b/src/table.js index 363ca6cab..e769f50ef 100644 --- a/src/table.js +++ b/src/table.js @@ -572,10 +572,10 @@ class Table extends TransactionRequest { } this.createReadStream(query, options) .on('error', callback) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { callback(null, rows); }); } diff --git a/src/transaction-request.js b/src/transaction-request.js index 51ebcb087..1529402ea 100644 --- a/src/transaction-request.js +++ b/src/transaction-request.js @@ -194,7 +194,6 @@ class TransactionRequest { * }); */ createReadStream(table, query) { - const self = this; const reqOpts = codec.encodeRead(query); reqOpts.table = table; delete reqOpts.json; @@ -208,14 +207,14 @@ class TransactionRequest { if (gaxOptions) { delete reqOpts.gaxOptions; } - function makeRequest(resumeToken) { - return self.requestStream({ + const makeRequest = resumeToken => { + return this.requestStream({ client: 'SpannerClient', method: 'streamingRead', reqOpts: extend(reqOpts, {resumeToken: resumeToken}), gaxOpts: gaxOptions, }); - } + }; return new PartialResultStream(makeRequest, { json: query.json, jsonOptions: query.jsonOptions, @@ -278,7 +277,7 @@ class TransactionRequest { mutation['delete'] = { table: table, keySet: { - keys: arrify(keys).map(function(key) { + keys: arrify(keys).map(key => { return { values: arrify(key).map(codec.encode), }; @@ -540,10 +539,10 @@ class TransactionRequest { const rows = []; this.createReadStream(table, query) .on('error', callback) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { callback(null, rows); }); } @@ -711,7 +710,7 @@ class TransactionRequest { mutate_(method, table, keyVals, cb) { keyVals = arrify(keyVals); const columns = [...new Set([].concat(...keyVals.map(Object.keys)))].sort(); - const values = keyVals.map(function(keyVal, index) { + const values = keyVals.map((keyVal, index) => { const keys = Object.keys(keyVal); const missingColumns = columns.filter( column => keys.indexOf(column) === -1 @@ -725,7 +724,7 @@ class TransactionRequest { ); } return { - values: columns.map(function(column) { + values: columns.map(column => { const value = keyVal[column]; return codec.encode(value); }), diff --git a/src/transaction.js b/src/transaction.js index e7bc8d272..68faa3bb5 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -172,7 +172,6 @@ class Transaction extends TransactionRequest { * }); */ begin(callback) { - const self = this; let options; if (!this.readOnly) { options = { @@ -197,17 +196,17 @@ class Transaction extends TransactionRequest { method: 'beginTransaction', reqOpts: reqOpts, }, - function(err, resp) { + (err, resp) => { if (err) { callback(err); return; } - self.attempts_ += 1; - self.ended_ = false; - self.id = resp.id; - self.metadata = resp; + this.attempts_ += 1; + this.ended_ = false; + this.id = resp.id; + this.metadata = resp; if (resp.readTimestamp) { - self.readTimestamp = TransactionRequest.fromProtoTimestamp_( + this.readTimestamp = TransactionRequest.fromProtoTimestamp_( resp.readTimestamp ); } @@ -270,7 +269,6 @@ class Transaction extends TransactionRequest { * }); */ commit(callback) { - const self = this; if (this.ended_) { throw new Error('Transaction has already been ended.'); } @@ -290,9 +288,9 @@ class Transaction extends TransactionRequest { method: 'commit', reqOpts: reqOpts, }, - function(err, resp) { + (err, resp) => { if (!err) { - self.end(); + this.end(); } callback(err, resp); } @@ -365,23 +363,22 @@ class Transaction extends TransactionRequest { * @param {function} callback The callback function. */ request(config, callback) { - const self = this; config.reqOpts = extend( { session: this.session.formattedName_, }, config.reqOpts ); - this.session.request(config, function(err, resp) { - if (!self.runFn_ || !err || !self.isRetryableErrorCode_(err.code)) { + this.session.request(config, (err, resp) => { + if (!this.runFn_ || !err || !this.isRetryableErrorCode_(err.code)) { callback(err, resp); return; } - if (self.shouldRetry_(err)) { - self.retry_(Transaction.getRetryDelay_(err, self.attempts_)); + if (this.shouldRetry_(err)) { + this.retry_(Transaction.getRetryDelay_(err, this.attempts_)); return; } - self.runFn_(Transaction.createDeadlineError_(err)); + this.runFn_(Transaction.createDeadlineError_(err)); }); } /** @@ -393,7 +390,6 @@ class Transaction extends TransactionRequest { * @returns {ReadableStream} */ requestStream(config) { - const self = this; config.reqOpts = extend( { session: this.session.formattedName_, @@ -401,21 +397,21 @@ class Transaction extends TransactionRequest { config.reqOpts ); const requestStream = this.session.requestStream(config); - if (!is.fn(self.runFn_)) { + if (!is.fn(this.runFn_)) { return requestStream; } const userStream = through.obj(); - requestStream.on('error', function(err) { - if (!self.isRetryableErrorCode_(err.code)) { + requestStream.on('error', err => { + if (!this.isRetryableErrorCode_(err.code)) { userStream.destroy(err); return; } userStream.destroy(); - if (self.shouldRetry_(err)) { - self.retry_(Transaction.getRetryDelay_(err, self.attempts_)); + if (this.shouldRetry_(err)) { + this.retry_(Transaction.getRetryDelay_(err, this.attempts_)); return; } - self.runFn_(Transaction.createDeadlineError_(err)); + this.runFn_(Transaction.createDeadlineError_(err)); }); return requestStream.pipe(userStream); } @@ -429,13 +425,13 @@ class Transaction extends TransactionRequest { */ retry_(delay) { const self = this; - this.begin(function(err) { + this.begin(err => { if (err) { self.runFn_(err); return; } self.queuedMutations_ = []; - setTimeout(function() { + setTimeout(() => { self.runFn_(null, self); }, delay); }); @@ -473,7 +469,6 @@ class Transaction extends TransactionRequest { * }); */ rollback(callback) { - const self = this; if (!this.id) { throw new Error('Transaction ID is unknown, nothing to rollback.'); } @@ -486,9 +481,9 @@ class Transaction extends TransactionRequest { method: 'rollback', reqOpts: reqOpts, }, - function(err, resp) { + (err, resp) => { if (!err) { - self.end(); + this.end(); } callback(err, resp); } @@ -594,10 +589,10 @@ class Transaction extends TransactionRequest { const rows = []; this.runStream(query) .on('error', callback) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { callback(null, rows); }); } @@ -686,7 +681,6 @@ class Transaction extends TransactionRequest { * }); */ runStream(query) { - const self = this; if (is.string(query)) { query = { sql: query, @@ -705,13 +699,13 @@ class Transaction extends TransactionRequest { readOnly: this.options || {}, }; } - function makeRequest(resumeToken) { - return self.requestStream({ + const makeRequest = resumeToken => { + return this.requestStream({ client: 'SpannerClient', method: 'executeStreamingSql', reqOpts: extend({}, reqOpts, {resumeToken: resumeToken}), }); - } + }; return new PartialResultStream(makeRequest); } /** diff --git a/system-test/spanner.js b/system-test/spanner.js index f74713a68..987e2f672 100644 --- a/system-test/spanner.js +++ b/system-test/spanner.js @@ -29,7 +29,7 @@ const {Spanner} = require('../'); const PREFIX = 'gcloud-tests-'; const spanner = new Spanner({projectId: process.env.GCLOUD_PROJECT}); -describe('Spanner', function() { +describe('Spanner', () => { const instance = spanner.instance(generateName('instance')); const INSTANCE_CONFIG = { @@ -40,7 +40,7 @@ describe('Spanner', function() { }, }; - before(function(done) { + before(done => { async.series( [ deleteTestResources, @@ -55,7 +55,7 @@ describe('Spanner', function() { after(deleteTestResources); - describe('types', function() { + describe('types', () => { const database = instance.database(generateName('database')); const table = database.table('TypeCheck'); @@ -64,7 +64,7 @@ describe('Spanner', function() { insertData.Key = id; - table.insert(insertData, function(err, insertResp) { + table.insert(insertData, (err, insertResp) => { if (err) { callback(err); return; @@ -77,7 +77,7 @@ describe('Spanner', function() { id: id, }, }, - function(err, rows, readResp) { + (err, rows, readResp) => { if (err) { callback(err); return; @@ -89,7 +89,7 @@ describe('Spanner', function() { }); } - before(function(done) { + before(done => { database.create( { schema: ` @@ -117,8 +117,8 @@ describe('Spanner', function() { ); }); - describe('uneven rows', function() { - it('should allow differently-ordered rows', function(done) { + describe('uneven rows', () => { + it('should allow differently-ordered rows', done => { const data = [ { Key: generateName('id'), @@ -132,7 +132,7 @@ describe('Spanner', function() { }, ]; - table.insert(data, function(err) { + table.insert(data, err => { assert.ifError(err); database.run( @@ -143,7 +143,7 @@ describe('Spanner', function() { b: data[1].Key, }, }, - function(err, rows) { + (err, rows) => { assert.ifError(err); const row1 = rows[0].toJSON(); @@ -161,11 +161,11 @@ describe('Spanner', function() { }); }); - describe('structs', function() { - it('should correctly decode structs', function(done) { + describe('structs', () => { + it('should correctly decode structs', done => { const query = 'SELECT ARRAY(SELECT as struct 1, "hello")'; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const symbols = Object.getOwnPropertySymbols(rows[0][0].value[0]); @@ -205,11 +205,11 @@ describe('Spanner', function() { }); }); - it('should correctly decode structs', function(done) { + it('should correctly decode structs', done => { const query = 'SELECT 1 as id, ARRAY(select as struct 2 as id, "hello" as name)'; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const symbols = Object.getOwnPropertySymbols(rows[0][1].value[0]); @@ -260,41 +260,41 @@ describe('Spanner', function() { }); }); - describe('booleans', function() { - it('should write boolean values', function(done) { - insert({BoolValue: true}, function(err, row) { + describe('booleans', () => { + it('should write boolean values', done => { + insert({BoolValue: true}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().BoolValue, true); done(); }); }); - it('should write null boolean values', function(done) { - insert({BoolValue: null}, function(err, row) { + it('should write null boolean values', done => { + insert({BoolValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().BoolValue, null); done(); }); }); - it('should write empty boolean array values', function(done) { - insert({BoolArray: []}, function(err, row) { + it('should write empty boolean array values', done => { + insert({BoolArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BoolArray, []); done(); }); }); - it('should write null boolean array values', function(done) { - insert({BoolArray: [null]}, function(err, row) { + it('should write null boolean array values', done => { + insert({BoolArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BoolArray, [null]); done(); }); }); - it('should write boolean array values', function(done) { - insert({BoolArray: [true, false]}, function(err, row) { + it('should write boolean array values', done => { + insert({BoolArray: [true, false]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BoolArray, [true, false]); done(); @@ -302,30 +302,30 @@ describe('Spanner', function() { }); }); - describe('int64s', function() { - it('should write int64 values', function(done) { - insert({IntValue: Spanner.int(1234)}, function(err, row) { + describe('int64s', () => { + it('should write int64 values', done => { + insert({IntValue: Spanner.int(1234)}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().IntValue, 1234); done(); }); }); - it('should write null int64 values', function(done) { - insert({IntValue: null}, function(err, row) { + it('should write null int64 values', done => { + insert({IntValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().IntValue, null); done(); }); }); - it('should throw for of bounds integers', function(done) { + it('should throw for of bounds integers', done => { const value = '9223372036854775807'; - insert({IntValue: value}, function(err, row) { + insert({IntValue: value}, (err, row) => { assert.ifError(err); - assert.throws(function() { + assert.throws(() => { row.toJSON(); }, new RegExp('Serializing column "IntValue" encountered an error')); @@ -333,10 +333,10 @@ describe('Spanner', function() { }); }); - it('should optionally wrap out of bounds integers', function(done) { + it('should optionally wrap out of bounds integers', done => { const value = '9223372036854775807'; - insert({IntValue: value}, function(err, row) { + insert({IntValue: value}, (err, row) => { assert.ifError(err); const intValue = row.toJSON({wrapNumbers: true}).IntValue.value; assert.strictEqual(intValue, value); @@ -344,26 +344,26 @@ describe('Spanner', function() { }); }); - it('should write empty in64 array values', function(done) { - insert({IntArray: []}, function(err, row) { + it('should write empty in64 array values', done => { + insert({IntArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().IntArray, []); done(); }); }); - it('should write null int64 array values', function(done) { - insert({IntArray: [null]}, function(err, row) { + it('should write null int64 array values', done => { + insert({IntArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().IntArray, [null]); done(); }); }); - it('should write int64 array values', function(done) { + it('should write int64 array values', done => { const values = [1, 2, 3]; - insert({IntArray: values}, function(err, row) { + insert({IntArray: values}, (err, row) => { assert.ifError(err); const expected = values.map(Spanner.int); @@ -373,75 +373,75 @@ describe('Spanner', function() { }); }); - describe('float64s', function() { - it('should write float64 values', function(done) { - insert({FloatValue: Spanner.float(8.2)}, function(err, row) { + describe('float64s', () => { + it('should write float64 values', done => { + insert({FloatValue: Spanner.float(8.2)}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatValue, 8.2); done(); }); }); - it('should write null float64 values', function(done) { - insert({FloatValue: null}, function(err, row) { + it('should write null float64 values', done => { + insert({FloatValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().FloatValue, null); done(); }); }); - it('should accept a Float object with an Int-like value', function(done) { - insert({FloatValue: Spanner.float(8)}, function(err, row) { + it('should accept a Float object with an Int-like value', done => { + insert({FloatValue: Spanner.float(8)}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatValue, 8); done(); }); }); - it('should handle Infinity', function(done) { - insert({FloatValue: Infinity}, function(err, row) { + it('should handle Infinity', done => { + insert({FloatValue: Infinity}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatValue, Infinity); done(); }); }); - it('should handle -Infinity', function(done) { - insert({FloatValue: -Infinity}, function(err, row) { + it('should handle -Infinity', done => { + insert({FloatValue: -Infinity}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatValue, -Infinity); done(); }); }); - it('should handle NaN', function(done) { - insert({FloatValue: NaN}, function(err, row) { + it('should handle NaN', done => { + insert({FloatValue: NaN}, (err, row) => { assert.ifError(err); assert(isNaN(row.toJSON().FloatValue)); done(); }); }); - it('should write empty float64 array values', function(done) { - insert({FloatArray: []}, function(err, row) { + it('should write empty float64 array values', done => { + insert({FloatArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatArray, []); done(); }); }); - it('should write null float64 array values', function(done) { - insert({FloatArray: [null]}, function(err, row) { + it('should write null float64 array values', done => { + insert({FloatArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().FloatArray, [null]); done(); }); }); - it('should write float64 array values', function(done) { + it('should write float64 array values', done => { const values = [1.2, 2.3, 3.4]; - insert({FloatArray: values}, function(err, row) { + insert({FloatArray: values}, (err, row) => { assert.ifError(err); const expected = values.map(Spanner.float); @@ -451,41 +451,41 @@ describe('Spanner', function() { }); }); - describe('strings', function() { - it('should write string values', function(done) { - insert({StringValue: 'abc'}, function(err, row) { + describe('strings', () => { + it('should write string values', done => { + insert({StringValue: 'abc'}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().StringValue, 'abc'); done(); }); }); - it('should write null string values', function(done) { - insert({StringValue: null}, function(err, row) { + it('should write null string values', done => { + insert({StringValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().StringValue, null); done(); }); }); - it('should write empty string array values', function(done) { - insert({StringArray: []}, function(err, row) { + it('should write empty string array values', done => { + insert({StringArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().StringArray, []); done(); }); }); - it('should write null string array values', function(done) { - insert({StringArray: [null]}, function(err, row) { + it('should write null string array values', done => { + insert({StringArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().StringArray, [null]); done(); }); }); - it('should write string array values', function(done) { - insert({StringArray: ['abc', 'def']}, function(err, row) { + it('should write string array values', done => { + insert({StringArray: ['abc', 'def']}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().StringArray, ['abc', 'def']); done(); @@ -493,43 +493,43 @@ describe('Spanner', function() { }); }); - describe('bytes', function() { - it('should write bytes values', function(done) { - insert({BytesValue: Buffer.from('abc')}, function(err, row) { + describe('bytes', () => { + it('should write bytes values', done => { + insert({BytesValue: Buffer.from('abc')}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BytesValue, Buffer.from('abc')); done(); }); }); - it('should write null bytes values', function(done) { - insert({BytesValue: null}, function(err, row) { + it('should write null bytes values', done => { + insert({BytesValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().BytesValue, null); done(); }); }); - it('should write empty bytes array values', function(done) { - insert({BytesArray: []}, function(err, row) { + it('should write empty bytes array values', done => { + insert({BytesArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BytesArray, []); done(); }); }); - it('should write null bytes array values', function(done) { - insert({BytesArray: [null]}, function(err, row) { + it('should write null bytes array values', done => { + insert({BytesArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BytesArray, [null]); done(); }); }); - it('should write bytes array values', function(done) { + it('should write bytes array values', done => { const values = [Buffer.from('a'), Buffer.from('b')]; - insert({BytesArray: values}, function(err, row) { + insert({BytesArray: values}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().BytesArray, values); done(); @@ -537,11 +537,11 @@ describe('Spanner', function() { }); }); - describe('timestamps', function() { - it('should write timestamp values', function(done) { + describe('timestamps', () => { + it('should write timestamp values', done => { const date = new Date(); - insert({TimestampValue: date}, function(err, row) { + insert({TimestampValue: date}, (err, row) => { assert.ifError(err); const time = row.toJSON().TimestampValue.getTime(); assert.strictEqual(time, date.getTime()); @@ -549,34 +549,34 @@ describe('Spanner', function() { }); }); - it('should write null timestamp values', function(done) { - insert({TimestampValue: null}, function(err, row) { + it('should write null timestamp values', done => { + insert({TimestampValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().TimestampValue, null); done(); }); }); - it('should write empty timestamp array values', function(done) { - insert({TimestampArray: []}, function(err, row) { + it('should write empty timestamp array values', done => { + insert({TimestampArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().TimestampArray, []); done(); }); }); - it('should write null timestamp array values', function(done) { - insert({TimestampArray: [null]}, function(err, row) { + it('should write null timestamp array values', done => { + insert({TimestampArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().TimestampArray, [null]); done(); }); }); - it('should write timestamp array values', function(done) { + it('should write timestamp array values', done => { const values = [new Date(), new Date('3-3-1933')]; - insert({TimestampArray: values}, function(err, row) { + insert({TimestampArray: values}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().TimestampArray, values); done(); @@ -584,45 +584,45 @@ describe('Spanner', function() { }); }); - describe('dates', function() { - it('should write date values', function(done) { + describe('dates', () => { + it('should write date values', done => { const date = Spanner.date(); - insert({DateValue: date}, function(err, row) { + insert({DateValue: date}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(Spanner.date(row.toJSON().DateValue), date); done(); }); }); - it('should write null date values', function(done) { - insert({DateValue: null}, function(err, row) { + it('should write null date values', done => { + insert({DateValue: null}, (err, row) => { assert.ifError(err); assert.strictEqual(row.toJSON().DateValue, null); done(); }); }); - it('should write empty date array values', function(done) { - insert({DateArray: []}, function(err, row) { + it('should write empty date array values', done => { + insert({DateArray: []}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().DateArray, []); done(); }); }); - it('should write null date array values', function(done) { - insert({DateArray: [null]}, function(err, row) { + it('should write null date array values', done => { + insert({DateArray: [null]}, (err, row) => { assert.ifError(err); assert.deepStrictEqual(row.toJSON().DateArray, [null]); done(); }); }); - it('should write date array values', function(done) { + it('should write date array values', done => { const values = [Spanner.date(), Spanner.date('3-3-1933')]; - insert({DateArray: values}, function(err, row) { + insert({DateArray: values}, (err, row) => { assert.ifError(err); const returnedValues = row.toJSON().DateArray.map(Spanner.date); @@ -633,11 +633,11 @@ describe('Spanner', function() { }); }); - describe('commit timestamp', function() { - it('should accept the commit timestamp placeholder', function(done) { + describe('commit timestamp', () => { + it('should accept the commit timestamp placeholder', done => { const data = {CommitTimestamp: Spanner.COMMIT_TIMESTAMP}; - insert(data, function(err, row, commitResponse) { + insert(data, (err, row, commitResponse) => { assert.ifError(err); const timestampFromCommit = fromProtoToDate( @@ -651,24 +651,24 @@ describe('Spanner', function() { }); }); - it('should throw an error for incorrect value types', function(done) { - table.insert({BoolValue: 'abc'}, function(err) { + it('should throw an error for incorrect value types', done => { + table.insert({BoolValue: 'abc'}, err => { assert(err); done(); }); }); }); - describe('Instances', function() { - it('should have created the instance', function(done) { - instance.getMetadata(function(err, metadata) { + describe('Instances', () => { + it('should have created the instance', done => { + instance.getMetadata((err, metadata) => { assert.ifError(err); assert.strictEqual(metadata.name, instance.formattedName_); done(); }); }); - it('should auto create an instance', function(done) { + it('should auto create an instance', done => { const instance = spanner.instance(generateName('instance')); const config = extend( @@ -678,24 +678,24 @@ describe('Spanner', function() { INSTANCE_CONFIG ); - instance.get(config, function(err) { + instance.get(config, err => { assert.ifError(err); instance.getMetadata(done); }); }); - it('should list the instances', function(done) { - spanner.getInstances(function(err, instances) { + it('should list the instances', done => { + spanner.getInstances((err, instances) => { assert.ifError(err); assert(instances.length > 0); done(); }); }); - it('should list the instances in promise mode', function(done) { + it('should list the instances in promise mode', done => { spanner .getInstances() - .then(function(data) { + .then(data => { const instances = data[0]; assert(instances.length > 0); done(); @@ -703,29 +703,29 @@ describe('Spanner', function() { .catch(done); }); - it('should list the instances in stream mode', function(done) { + it('should list the instances in stream mode', done => { spanner .getInstancesStream() .on('error', done) .pipe( - concat(function(instances) { + concat(instances => { assert(instances.length > 0); done(); }) ); }); - it('should update the metadata', function(done) { + it('should update the metadata', done => { const newData = { displayName: 'new-display-name', }; instance.setMetadata( newData, - execAfterOperationComplete(function(err) { + execAfterOperationComplete(err => { assert.ifError(err); - instance.getMetadata(function(err, metadata) { + instance.getMetadata((err, metadata) => { assert.ifError(err); assert.strictEqual(metadata.displayName, newData.displayName); done(); @@ -734,16 +734,16 @@ describe('Spanner', function() { ); }); - it('should return true for instances that exist', function(done) { - instance.exists(function(err, exists) { + it('should return true for instances that exist', done => { + instance.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, true); done(); }); }); - it('should return false for instances that do not exist', function(done) { - spanner.instance('bad-instance').exists(function(err, exists) { + it('should return false for instances that do not exist', done => { + spanner.instance('bad-instance').exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, false); done(); @@ -751,19 +751,19 @@ describe('Spanner', function() { }); }); - describe('instanceConfigs', function() { - it('should list the available instanceConfigs', function(done) { - spanner.getInstanceConfigs(function(err, instanceConfigs) { + describe('instanceConfigs', () => { + it('should list the available instanceConfigs', done => { + spanner.getInstanceConfigs((err, instanceConfigs) => { assert.ifError(err); assert(instanceConfigs.length > 0); done(); }); }); - it('should list the instanceConfigs in promise mode', function(done) { + it('should list the instanceConfigs in promise mode', done => { spanner .getInstanceConfigs() - .then(function(data) { + .then(data => { const instanceConfigs = data[0]; assert(instanceConfigs.length > 0); done(); @@ -771,12 +771,12 @@ describe('Spanner', function() { .catch(done); }); - it('should list the instanceConfigs in stream mode', function(done) { + it('should list the instanceConfigs in stream mode', done => { spanner .getInstanceConfigsStream() .on('error', done) .pipe( - concat(function(instanceConfigs) { + concat(instanceConfigs => { assert(instanceConfigs.length > 0); done(); }) @@ -784,15 +784,15 @@ describe('Spanner', function() { }); }); - describe('Databases', function() { + describe('Databases', () => { const database = instance.database(generateName('database')); - before(function(done) { + before(done => { database.create(execAfterOperationComplete(done)); }); - after(function(done) { - database.close(function(err) { + after(done => { + database.close(err => { if (err) { return done(err); } @@ -801,17 +801,17 @@ describe('Spanner', function() { }); }); - it('should auto create a database', function(done) { + it('should auto create a database', done => { const database = instance.database(generateName('database')); - database.get({autoCreate: true}, function(err) { + database.get({autoCreate: true}, err => { assert.ifError(err); database.getMetadata(done); }); }); - it('should have created the database', function(done) { - database.getMetadata(function(err, metadata) { + it('should have created the database', done => { + database.getMetadata((err, metadata) => { assert.ifError(err); assert.strictEqual(metadata.name, database.formattedName_); assert.strictEqual(metadata.state, 'READY'); @@ -819,18 +819,18 @@ describe('Spanner', function() { }); }); - it('should list the databases from an instance', function(done) { - instance.getDatabases(function(err, databases) { + it('should list the databases from an instance', done => { + instance.getDatabases((err, databases) => { assert.ifError(err); assert(databases.length > 0); done(); }); }); - it('should list the databases in promise mode', function(done) { + it('should list the databases in promise mode', done => { instance .getDatabases() - .then(function(data) { + .then(data => { const databases = data[0]; assert(databases.length > 0); done(); @@ -838,35 +838,35 @@ describe('Spanner', function() { .catch(done); }); - it('should list the databases in stream mode', function(done) { + it('should list the databases in stream mode', done => { instance .getDatabasesStream() .on('error', done) .pipe( - concat(function(databases) { + concat(databases => { assert(databases.length > 0); done(); }) ); }); - it('should return true for databases that exist', function(done) { - database.exists(function(err, exists) { + it('should return true for databases that exist', done => { + database.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, true); done(); }); }); - it('should return false for databases that do not exist', function(done) { - instance.database('bad-database').exists(function(err, exists) { + it('should return false for databases that do not exist', done => { + instance.database('bad-database').exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, false); done(); }); }); - it('should create a table', function(done) { + it('should create a table', done => { const createTableStatement = ` CREATE TABLE Singers ( SingerId INT64 NOT NULL, @@ -877,14 +877,14 @@ describe('Spanner', function() { database.updateSchema( [createTableStatement], - execAfterOperationComplete(function(err) { + execAfterOperationComplete(err => { assert.ifError(err); function replaceNewLinesAndSpacing(str) { return str.replace(/\n\s*/g, '').replace(/\s+/g, ' '); } - database.getSchema(function(err, statements) { + database.getSchema((err, statements) => { assert.ifError(err); assert.strictEqual( replaceNewLinesAndSpacing(statements[0]), @@ -897,11 +897,11 @@ describe('Spanner', function() { }); }); - describe('Sessions', function() { + describe('Sessions', () => { const database = instance.database(generateName('database')); const session = database.session(); - before(function(done) { + before(done => { async.series( [ function(next) { @@ -924,25 +924,25 @@ describe('Spanner', function() { ); }); - after(function(done) { + after(done => { session.delete(done); }); - it('should have created the session', function(done) { - session.getMetadata(function(err, metadata) { + it('should have created the session', done => { + session.getMetadata((err, metadata) => { assert.ifError(err); assert.strictEqual(session.formattedName_, metadata.name); done(); }); }); - it('should get a session by name', function(done) { + it('should get a session by name', done => { const shortName = session.formattedName_.split('/').pop(); const sessionByShortName = database.session(shortName); - sessionByShortName.getMetadata(function(err, metadataByName) { + sessionByShortName.getMetadata((err, metadataByName) => { assert.ifError(err); - session.getMetadata(function(err, metadata) { + session.getMetadata((err, metadata) => { assert.ifError(err); assert.strictEqual(metadataByName.name, metadata.name); done(); @@ -950,20 +950,20 @@ describe('Spanner', function() { }); }); - it('should keep the session alive', function(done) { + it('should keep the session alive', done => { session.keepAlive(done); }); }); - describe('Tables', function() { + describe('Tables', () => { const database = instance.database(generateName('database')); const table = database.table('Singers'); - before(function() { + before(() => { return database .create() .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return table.create(` CREATE TABLE Singers ( SingerId STRING(1024) NOT NULL, @@ -981,43 +981,43 @@ describe('Spanner', function() { .then(onPromiseOperationComplete); }); - after(function() { + after(() => { return table .delete() .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return database.delete(); }); }); - it('should throw an error for non-existant tables', function(done) { + it('should throw an error for non-existant tables', done => { const table = database.table(generateName('nope')); table.insert( { SingerId: generateName('id'), }, - function(err) { + err => { assert.strictEqual(err.code, 5); done(); } ); }); - it('should throw an error for non-existant columns', function(done) { + it('should throw an error for non-existant columns', done => { table.insert( { SingerId: generateName('id'), Nope: 'abc', }, - function(err) { + err => { assert.strictEqual(err.code, 5); done(); } ); }); - it('should read rows as a stream', function(done) { + it('should read rows as a stream', done => { const id = generateName('id'); const name = generateName('name'); @@ -1026,7 +1026,7 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); let rows = []; @@ -1037,10 +1037,10 @@ describe('Spanner', function() { columns: ['SingerId', 'name'], }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { rows = rows.map(x => x.toJSON()); assert.deepStrictEqual(rows, [ @@ -1056,7 +1056,7 @@ describe('Spanner', function() { ); }); - it('should automatically convert to JSON', function(done) { + it('should automatically convert to JSON', done => { const id = generateName('id'); const name = generateName('name'); @@ -1065,7 +1065,7 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); const rows = []; @@ -1077,10 +1077,10 @@ describe('Spanner', function() { json: true, }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { assert.deepStrictEqual(rows, [ { SingerId: id, @@ -1094,7 +1094,7 @@ describe('Spanner', function() { ); }); - it('should automatically convert to JSON with options', function(done) { + it('should automatically convert to JSON with options', done => { const id = generateName('id'); table.insert( @@ -1102,7 +1102,7 @@ describe('Spanner', function() { SingerId: id, Int: 8, }, - function(err) { + err => { assert.ifError(err); const rows = []; @@ -1115,10 +1115,10 @@ describe('Spanner', function() { jsonOptions: {wrapNumbers: true}, }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { assert.strictEqual(rows[0].Int.value, '8'); done(); }); @@ -1126,7 +1126,7 @@ describe('Spanner', function() { ); }); - it('should insert and delete a row', function(done) { + it('should insert and delete a row', done => { const id = generateName('id'); const name = generateName('name'); @@ -1135,10 +1135,10 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); - table.deleteRows([id], function(err) { + table.deleteRows([id], err => { assert.ifError(err); const rows = []; @@ -1149,10 +1149,10 @@ describe('Spanner', function() { columns: ['SingerId'], }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { assert.strictEqual(rows.length, 0); done(); }); @@ -1161,7 +1161,7 @@ describe('Spanner', function() { ); }); - it('should insert and delete multiple rows', function(done) { + it('should insert and delete multiple rows', done => { const id = generateName('id'); const id2 = generateName('id2'); @@ -1178,10 +1178,10 @@ describe('Spanner', function() { Name: name, }, ], - function(err) { + err => { assert.ifError(err); - table.deleteRows([id, id2], function(err) { + table.deleteRows([id, id2], err => { assert.ifError(err); const rows = []; @@ -1192,10 +1192,10 @@ describe('Spanner', function() { columns: ['SingerId'], }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { assert.strictEqual(rows.length, 0); done(); }); @@ -1204,7 +1204,7 @@ describe('Spanner', function() { ); }); - it('should insert and delete multiple composite key rows', function() { + it('should insert and delete multiple composite key rows', () => { const id1 = 1; const name1 = generateName('name1'); @@ -1225,7 +1225,7 @@ describe('Spanner', function() { ` ) .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return table.insert([ { SingerId: id1, @@ -1237,32 +1237,32 @@ describe('Spanner', function() { }, ]); }) - .then(function() { + .then(() => { return table.read({ keys: keys, columns: ['SingerId', 'Name'], }); }) - .then(function(data) { + .then(data => { const rows = data[0]; assert.strictEqual(rows.length, 2); return table.deleteRows(keys); }) - .then(function() { + .then(() => { return table.read({ keys: keys, columns: ['SingerId', 'Name'], }); }) - .then(function(data) { + .then(data => { const rows = data[0]; assert.strictEqual(rows.length, 0); }); }); - it('should insert and query multiple rows', function(done) { + it('should insert and query multiple rows', done => { const id1 = generateName('id'); const name1 = generateName('name'); @@ -1280,10 +1280,10 @@ describe('Spanner', function() { Name: name2, }, ], - function(err) { + err => { assert.ifError(err); - database.run('SELECT * FROM Singers', function(err, rows) { + database.run('SELECT * FROM Singers', (err, rows) => { assert.ifError(err); // We just want the two most recent ones. @@ -1303,7 +1303,7 @@ describe('Spanner', function() { ); }); - it('should insert then replace a row', function(done) { + it('should insert then replace a row', done => { const originalRow = { SingerId: generateName('id'), Name: generateName('name'), @@ -1313,10 +1313,10 @@ describe('Spanner', function() { SingerId: originalRow.SingerId, }; - table.insert(originalRow, function(err) { + table.insert(originalRow, err => { assert.ifError(err); - table.replace(replacedRow, function(err) { + table.replace(replacedRow, err => { assert.ifError(err); table.read( @@ -1324,7 +1324,7 @@ describe('Spanner', function() { keys: [originalRow.SingerId], columns: Object.keys(originalRow), }, - function(err, rows) { + (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -1339,7 +1339,7 @@ describe('Spanner', function() { }); }); - it('should insert then update a row', function(done) { + it('should insert then update a row', done => { const originalRow = { SingerId: generateName('id'), Name: generateName('name'), @@ -1350,10 +1350,10 @@ describe('Spanner', function() { Name: generateName('name'), }; - table.insert(originalRow, function(err) { + table.insert(originalRow, err => { assert.ifError(err); - table.update(updatedRow, function(err) { + table.update(updatedRow, err => { assert.ifError(err); table.read( @@ -1361,7 +1361,7 @@ describe('Spanner', function() { keys: [originalRow.SingerId], columns: Object.keys(originalRow), }, - function(err, rows) { + (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -1376,7 +1376,7 @@ describe('Spanner', function() { }); }); - describe('insert & query', function() { + describe('insert & query', () => { const DATE = new Date('1969-08-20'); const ID = generateName('id'); @@ -1412,11 +1412,11 @@ describe('Spanner', function() { Spanner.int(PHONE_NUMBERS[1]), ]; - before(function() { + before(() => { return table.insert(INSERT_ROW); }); - it('should query in callback mode', function(done) { + it('should query in callback mode', done => { const options = { readOnly: true, strong: true, @@ -1428,7 +1428,7 @@ describe('Spanner', function() { params: {id: ID}, }, options, - function(err, rows) { + (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows.shift().toJSON(), EXPECTED_ROW); done(); @@ -1436,7 +1436,7 @@ describe('Spanner', function() { ); }); - it('should query in promise mode', function(done) { + it('should query in promise mode', done => { const options = { readOnly: true, strong: true, @@ -1450,7 +1450,7 @@ describe('Spanner', function() { }, options ) - .then(function(data) { + .then(data => { const rows = data[0]; assert.deepStrictEqual(rows.shift().toJSON(), EXPECTED_ROW); done(); @@ -1458,7 +1458,7 @@ describe('Spanner', function() { .catch(done); }); - it('should query in stream mode', function(done) { + it('should query in stream mode', done => { const options = { readOnly: true, strong: true, @@ -1478,30 +1478,30 @@ describe('Spanner', function() { row = row_; this.end(); }) - .on('end', function() { + .on('end', () => { assert.deepStrictEqual(row.toJSON(), EXPECTED_ROW); done(); }); }); - it('should allow "SELECT 1" queries', function(done) { + it('should allow "SELECT 1" queries', done => { database.run('SELECT 1', done); }); - it('should fail invalid queries', function(done) { - database.run('SELECT Apples AND Oranges', function(err) { + it('should fail invalid queries', done => { + database.run('SELECT Apples AND Oranges', err => { assert.strictEqual(err.code, 3); done(); }); }); - it('should query an array of structs', function(done) { + it('should query an array of structs', done => { const query = ` SELECT ARRAY(SELECT AS STRUCT C1, C2 FROM (SELECT 'a' AS C1, 1 AS C2 UNION ALL SELECT 'b' AS C1, 2 AS C2) ORDER BY C1 ASC)`; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const values = rows[0][0].value; @@ -1523,20 +1523,20 @@ describe('Spanner', function() { }); }); - it('should query an empty array of structs', function(done) { + it('should query an empty array of structs', done => { const query = ` SELECT ARRAY(SELECT AS STRUCT * FROM (SELECT 'a', 1) WHERE 0 = 1)`; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.length, 0); done(); }); }); - describe('params', function() { - describe('boolean', function() { - it('should bind the value', function(done) { + describe('params', () => { + describe('boolean', () => { + it('should bind the value', done => { const query = { sql: 'SELECT @v', params: { @@ -1544,14 +1544,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, true); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -1562,14 +1562,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [false, true, false]; const query = { @@ -1579,14 +1579,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -1602,14 +1602,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -1623,7 +1623,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -1631,8 +1631,8 @@ describe('Spanner', function() { }); }); - describe('int64', function() { - it('should bind the value', function(done) { + describe('int64', () => { + it('should bind the value', done => { const query = { sql: 'SELECT @v', params: { @@ -1640,14 +1640,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.value, '1234'); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -1658,14 +1658,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [1, 2, 3, null]; const query = { @@ -1675,10 +1675,10 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); - const expected = values.map(function(val) { + const expected = values.map(val => { return is.number(val) ? {value: String(val)} : val; }); @@ -1690,7 +1690,7 @@ describe('Spanner', function() { }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -1706,14 +1706,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -1727,7 +1727,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -1735,8 +1735,8 @@ describe('Spanner', function() { }); }); - describe('float64', function() { - it('should bind the value', function(done) { + describe('float64', () => { + it('should bind the value', done => { const query = { sql: 'SELECT @v', params: { @@ -1744,14 +1744,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.value, 2.2); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -1762,14 +1762,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [null, 1.1, 2.3, 3.5, null]; const query = { @@ -1779,10 +1779,10 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); - const expected = values.map(function(val) { + const expected = values.map(val => { return is.number(val) ? {value: val} : val; }); @@ -1794,7 +1794,7 @@ describe('Spanner', function() { }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -1810,14 +1810,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -1831,14 +1831,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); }); }); - it('should bind Infinity', function(done) { + it('should bind Infinity', done => { const query = { sql: 'SELECT @v', params: { @@ -1846,14 +1846,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.value, 'Infinity'); done(); }); }); - it('should bind -Infinity', function(done) { + it('should bind -Infinity', done => { const query = { sql: 'SELECT @v', params: { @@ -1861,14 +1861,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.value, '-Infinity'); done(); }); }); - it('should bind NaN', function(done) { + it('should bind NaN', done => { const query = { sql: 'SELECT @v', params: { @@ -1876,14 +1876,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value.value, 'NaN'); done(); }); }); - it('should bind an array of Infinity and NaN', function(done) { + it('should bind an array of Infinity and NaN', done => { const values = [Infinity, -Infinity, NaN]; const query = { @@ -1893,10 +1893,10 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); - const expected = values.map(function(val) { + const expected = values.map(val => { return is.number(val) ? {value: val + ''} : val; }); @@ -1909,8 +1909,8 @@ describe('Spanner', function() { }); }); - describe('string', function() { - it('should bind the value', function(done) { + describe('string', () => { + it('should bind the value', done => { const query = { sql: 'SELECT @v', params: { @@ -1918,14 +1918,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, 'abc'); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -1936,14 +1936,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = ['a', 'b', 'c', null]; const query = { @@ -1953,14 +1953,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -1976,14 +1976,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -1997,7 +1997,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -2005,8 +2005,8 @@ describe('Spanner', function() { }); }); - describe('bytes', function() { - it('should bind the value', function(done) { + describe('bytes', () => { + it('should bind the value', done => { const buffer = Buffer.from('abc'); const query = { @@ -2016,14 +2016,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, buffer); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -2034,14 +2034,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [Buffer.from('a'), Buffer.from('b'), null]; const query = { @@ -2051,14 +2051,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -2074,14 +2074,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -2095,7 +2095,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -2103,8 +2103,8 @@ describe('Spanner', function() { }); }); - describe('timestamp', function() { - it('should bind the value', function(done) { + describe('timestamp', () => { + it('should bind the value', done => { const timestamp = new Date(); const query = { @@ -2114,14 +2114,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, timestamp); done(); }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -2132,14 +2132,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [new Date(), new Date('3-3-1999'), null]; const query = { @@ -2149,14 +2149,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -2172,14 +2172,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -2193,7 +2193,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -2201,8 +2201,8 @@ describe('Spanner', function() { }); }); - describe('date', function() { - it('should bind the value', function(done) { + describe('date', () => { + it('should bind the value', done => { const date = Spanner.date(); const query = { @@ -2212,7 +2212,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const returnedDate = Spanner.date(rows[0][0].value); @@ -2222,7 +2222,7 @@ describe('Spanner', function() { }); }); - it('should allow for null values', function(done) { + it('should allow for null values', done => { const query = { sql: 'SELECT @v', params: { @@ -2233,14 +2233,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows[0][0].value, null); done(); }); }); - it('should bind arrays', function(done) { + it('should bind arrays', done => { const values = [ Spanner.date(), Spanner.date(new Date('3-3-1999')), @@ -2254,10 +2254,10 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); - const returnedValues = rows[0][0].value.map(function(val) { + const returnedValues = rows[0][0].value.map(val => { return is.nil(val) ? val : Spanner.date(val); }); @@ -2266,7 +2266,7 @@ describe('Spanner', function() { }); }); - it('should bind empty arrays', function(done) { + it('should bind empty arrays', done => { const values = []; const query = { @@ -2282,14 +2282,14 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, values); done(); }); }); - it('should bind null arrays', function(done) { + it('should bind null arrays', done => { const query = { sql: 'SELECT @v', params: { @@ -2303,7 +2303,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0][0].value, null); done(); @@ -2311,8 +2311,8 @@ describe('Spanner', function() { }); }); - describe('structs', function() { - it('should bind a simple struct', function(done) { + describe('structs', () => { + it('should bind a simple struct', done => { const query = { sql: 'SELECT @structParam.userf, @p4', params: { @@ -2324,7 +2324,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2334,7 +2334,7 @@ describe('Spanner', function() { }); }); - it('should bind null structs', function(done) { + it('should bind null structs', done => { const query = { sql: 'SELECT @structParam.userf is NULL', params: { @@ -2357,7 +2357,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2367,7 +2367,7 @@ describe('Spanner', function() { }); }); - it('should bind nested structs', function(done) { + it('should bind nested structs', done => { const query = { sql: 'SELECT @structParam.structf.nestedf', params: { @@ -2379,7 +2379,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2389,7 +2389,7 @@ describe('Spanner', function() { }); }); - it('should bind null nested structs', function(done) { + it('should bind null nested structs', done => { const query = { sql: 'SELECT @structParam.structf.nestedf', params: { @@ -2414,7 +2414,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2424,7 +2424,7 @@ describe('Spanner', function() { }); }); - it('should bind empty structs', function(done) { + it('should bind empty structs', done => { const query = { sql: 'SELECT @structParam IS NULL', params: { @@ -2432,7 +2432,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2442,7 +2442,7 @@ describe('Spanner', function() { }); }); - it('should bind null structs with no fields', function(done) { + it('should bind null structs with no fields', done => { const query = { sql: 'SELECT @structParam IS NULL', params: { @@ -2453,7 +2453,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2463,7 +2463,7 @@ describe('Spanner', function() { }); }); - it('should bind structs with null fields', function(done) { + it('should bind structs with null fields', done => { const query = { sql: 'SELECT @structParam.f1', params: { @@ -2484,7 +2484,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2494,7 +2494,7 @@ describe('Spanner', function() { }); }); - it('should bind structs with duplicate fields', function(done) { + it('should bind structs with duplicate fields', done => { const query = { sql: 'SELECT @structParam=STRUCT(10, 11)', params: { @@ -2511,7 +2511,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2521,7 +2521,7 @@ describe('Spanner', function() { }); }); - it('should bind structs with missing field names', function(done) { + it('should bind structs with missing field names', done => { const query = { sql: 'SELECT @structParam=STRUCT(5)', params: { @@ -2529,7 +2529,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2539,7 +2539,7 @@ describe('Spanner', function() { }); }); - it('should allow equality checks', function(done) { + it('should allow equality checks', done => { const query = { sql: 'SELECT @structParam=STRUCT(1, "bob")', @@ -2551,7 +2551,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2561,7 +2561,7 @@ describe('Spanner', function() { }); }); - it('should allow nullness checks', function(done) { + it('should allow nullness checks', done => { const query = { sql: 'SELECT @structParam IS NULL', params: { @@ -2572,7 +2572,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0]; @@ -2582,7 +2582,7 @@ describe('Spanner', function() { }); }); - it('should allow an array of non-null structs', function(done) { + it('should allow an array of non-null structs', done => { const query = { sql: 'SELECT a.threadid FROM UNNEST(@arraysf) a', params: { @@ -2597,7 +2597,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); rows = rows.map(row => row.toJSON()); @@ -2610,7 +2610,7 @@ describe('Spanner', function() { }); }); - it('should allow an array of structs with null fields', function(done) { + it('should allow an array of structs with null fields', done => { const query = { sql: 'SELECT a.threadid FROM UNNEST(@structParam.arraysf) a', params: { @@ -2645,7 +2645,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 0); @@ -2653,7 +2653,7 @@ describe('Spanner', function() { }); }); - it('should allow a null array of structs', function(done) { + it('should allow a null array of structs', done => { const query = { sql: 'SELECT a.threadid FROM UNNEST(@structParamArray) a', params: { @@ -2675,7 +2675,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 0); done(); @@ -2684,7 +2684,7 @@ describe('Spanner', function() { }); }); - describe('large reads', function() { + describe('large reads', () => { const table = database.table('LargeReads'); const expectedRow = { @@ -2713,7 +2713,7 @@ describe('Spanner', function() { return Buffer.from(bytes, 'base64'); } - before(function() { + before(() => { return table .create( ` @@ -2726,12 +2726,12 @@ describe('Spanner', function() { ) PRIMARY KEY (Key)` ) .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return table.insert(expectedRow); }); }); - it('should read large datasets', function(done) { + it('should read large datasets', done => { table.read( { keys: [expectedRow.Key], @@ -2743,7 +2743,7 @@ describe('Spanner', function() { 'BytesArray', ], }, - function(err, rows) { + (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2763,7 +2763,7 @@ describe('Spanner', function() { ); }); - it('should query large datasets', function(done) { + it('should query large datasets', done => { const query = { sql: 'SELECT * FROM ' + table.name + ' WHERE Key = @key', params: { @@ -2771,7 +2771,7 @@ describe('Spanner', function() { }, }; - database.run(query, function(err, rows) { + database.run(query, (err, rows) => { assert.ifError(err); const row = rows[0].toJSON(); @@ -2792,22 +2792,22 @@ describe('Spanner', function() { }); }); - describe('upsert', function() { + describe('upsert', () => { const ROW = { SingerId: generateName('id'), Name: generateName('name'), }; - it('should update a row', function(done) { + it('should update a row', done => { const row = { SingerId: ROW.SingerId, Name: generateName('name'), }; - table.insert(row, function(err) { + table.insert(row, err => { assert.ifError(err); - table.upsert(ROW, function(err) { + table.upsert(ROW, err => { assert.ifError(err); table.read( @@ -2815,7 +2815,7 @@ describe('Spanner', function() { keys: [ROW.SingerId], columns: Object.keys(ROW), }, - function(err, rows) { + (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0].toJSON(), ROW); done(); @@ -2825,8 +2825,8 @@ describe('Spanner', function() { }); }); - it('should insert a row', function(done) { - table.upsert(ROW, function(err) { + it('should insert a row', done => { + table.upsert(ROW, err => { assert.ifError(err); table.read( @@ -2834,7 +2834,7 @@ describe('Spanner', function() { keys: [ROW.SingerId], columns: Object.keys(ROW), }, - function(err, rows) { + (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows[0].toJSON(), ROW); done(); @@ -2844,12 +2844,12 @@ describe('Spanner', function() { }); }); - describe('read', function() { + describe('read', () => { const table = database.table('ReadTestTable'); const ALL_COLUMNS = ['Key', 'StringValue']; - before(function() { + before(() => { return table .create( ` @@ -2859,12 +2859,12 @@ describe('Spanner', function() { ) PRIMARY KEY (Key)` ) .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return database.updateSchema(` CREATE INDEX ReadByValue ON ReadTestTable(StringValue)`); }) .then(onPromiseOperationComplete) - .then(function() { + .then(() => { const data = []; for (let i = 0; i < 15; ++i) { @@ -2941,7 +2941,7 @@ describe('Spanner', function() { assert.strictEqual(rows.length, 3); - rows = rows.map(function(row) { + rows = rows.map(row => { return row.toJSON(); }); @@ -2985,7 +2985,7 @@ describe('Spanner', function() { assert.ifError(err); assert.strictEqual(rows.length, 2); - rows = rows.map(function(row) { + rows = rows.map(row => { return row.toJSON(); }); @@ -3008,7 +3008,7 @@ describe('Spanner', function() { assert.ifError(err); assert.strictEqual(rows.length, 3); - rows = rows.map(function(row) { + rows = rows.map(row => { return row.toJSON(); }); @@ -3032,7 +3032,7 @@ describe('Spanner', function() { assert.ifError(err); assert.strictEqual(rows.length, 2); - rows = rows.map(function(row) { + rows = rows.map(row => { return row.toJSON(); }); @@ -3084,7 +3084,7 @@ describe('Spanner', function() { assert.ifError(err); assert.strictEqual(rows.length, 3); - rows = rows.map(function(row) { + rows = rows.map(row => { return row.toJSON(); }); @@ -3093,17 +3093,17 @@ describe('Spanner', function() { assert.strictEqual(rows[2].Key, 'k7'); }, }, - ].forEach(function(test) { + ].forEach(test => { // test normally - it(test.test, function(done) { - table.read(test.query, function(err, rows) { + it(test.test, done => { + table.read(test.query, (err, rows) => { test.assertions(err, rows); done(); }); }); // test using an index - it(test.test + ' with an index', function(done) { + it(test.test + ' with an index', done => { const query = extend( { index: 'ReadByValue', @@ -3112,16 +3112,16 @@ describe('Spanner', function() { ); if (query.keys) { - query.keys = query.keys.map(function(key) { + query.keys = query.keys.map(key => { return key.replace('k', 'v'); }); } if (query.ranges) { - query.ranges = query.ranges.map(function(range_) { + query.ranges = query.ranges.map(range_ => { const range = extend({}, range_); - Object.keys(range).forEach(function(bound) { + Object.keys(range).forEach(bound => { if (range[bound]) { range[bound] = range[bound].replace('k', 'v'); } @@ -3131,14 +3131,14 @@ describe('Spanner', function() { }); } - table.read(query, function(err, rows) { + table.read(query, (err, rows) => { test.assertions(err, rows); done(); }); }); }); - it('should read over invalid database fails', function(done) { + it('should read over invalid database fails', done => { const database = instance.database(generateName('invalid')); const table = database.table('ReadTestTable'); @@ -3147,13 +3147,13 @@ describe('Spanner', function() { columns: ALL_COLUMNS, }; - table.read(query, function(err) { + table.read(query, err => { assert.strictEqual(err.code, 5); done(); }); }); - it('should read over invalid table fails', function(done) { + it('should read over invalid table fails', done => { const table = database.table('ReadTestTablezzz'); const query = { @@ -3161,25 +3161,25 @@ describe('Spanner', function() { columns: ALL_COLUMNS, }; - table.read(query, function(err) { + table.read(query, err => { assert.strictEqual(err.code, 5); done(); }); }); - it('should read over invalid column fails', function(done) { + it('should read over invalid column fails', done => { const query = { keys: ['k1'], columns: ['ohnoes'], }; - table.read(query, function(err) { + table.read(query, err => { assert.strictEqual(err.code, 5); done(); }); }); - it('should fail if deadline exceeds', function(done) { + it('should fail if deadline exceeds', done => { const query = { keys: ['k1'], columns: ALL_COLUMNS, @@ -3188,7 +3188,7 @@ describe('Spanner', function() { }, }; - table.read(query, function(err) { + table.read(query, err => { assert.strictEqual(err.code, 4); done(); }); @@ -3196,11 +3196,11 @@ describe('Spanner', function() { }); }); - describe('SessionPool', function() { + describe('SessionPool', () => { const database = instance.database(generateName('database')); const table = database.table('Singers'); - before(function(done) { + before(done => { async.series( [ function(next) { @@ -3220,7 +3220,7 @@ describe('Spanner', function() { ); }); - it('should insert and query a row', function(done) { + it('should insert and query a row', done => { const id = generateName('id'); const name = generateName('name'); @@ -3229,10 +3229,10 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); - database.run('SELECT * FROM Singers', function(err, rows) { + database.run('SELECT * FROM Singers', (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows.pop().toJSON(), { SingerId: id, @@ -3244,7 +3244,7 @@ describe('Spanner', function() { ); }); - it('should insert and query multiple rows', function(done) { + it('should insert and query multiple rows', done => { const id1 = generateName('id'); const name1 = generateName('name'); @@ -3262,10 +3262,10 @@ describe('Spanner', function() { Name: name2, }, ], - function(err) { + err => { assert.ifError(err); - database.run('SELECT * FROM Singers', function(err, rows) { + database.run('SELECT * FROM Singers', (err, rows) => { assert.ifError(err); // We just want the two most recent ones. @@ -3290,7 +3290,7 @@ describe('Spanner', function() { ); }); - it('should read rows as a stream', function(done) { + it('should read rows as a stream', done => { const id = generateName('id'); const name = generateName('name'); @@ -3299,7 +3299,7 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); let rows = []; @@ -3310,10 +3310,10 @@ describe('Spanner', function() { columns: ['SingerId', 'name'], }) .on('error', done) - .on('data', function(row) { + .on('data', row => { rows.push(row); }) - .on('end', function() { + .on('end', () => { rows = rows.map(x => x.toJSON()); assert.deepStrictEqual(rows, [ @@ -3329,7 +3329,7 @@ describe('Spanner', function() { ); }); - it('should read rows', function(done) { + it('should read rows', done => { const id = generateName('id'); const name = generateName('name'); @@ -3338,7 +3338,7 @@ describe('Spanner', function() { SingerId: id, Name: name, }, - function(err) { + err => { assert.ifError(err); table.read( @@ -3346,7 +3346,7 @@ describe('Spanner', function() { keys: [id], columns: ['SingerId', 'Name'], }, - function(err, rows) { + (err, rows) => { assert.ifError(err); rows = rows.map(x => x.toJSON()); @@ -3366,17 +3366,17 @@ describe('Spanner', function() { }); }); - describe('Transactions', function() { + describe('Transactions', () => { const database = instance.database(generateName('database')); const table = database.table('TxnTable'); const records = []; - before(function() { + before(() => { return database .create() .then(onPromiseOperationComplete) - .then(function() { + .then(() => { return table.create(` CREATE TABLE TxnTable ( Key STRING(MAX) NOT NULL, @@ -3385,7 +3385,7 @@ describe('Spanner', function() { ) PRIMARY KEY (Key)`); }) .then(onPromiseOperationComplete) - .then(function() { + .then(() => { const data = []; for (let i = 0; i < 5; i++) { @@ -3395,8 +3395,8 @@ describe('Spanner', function() { }); } - return data.reduce(function(promise, entry) { - return promise.then(function() { + return data.reduce((promise, entry) => { + return promise.then(() => { const record = extend( { timestamp: new Date(), @@ -3412,17 +3412,17 @@ describe('Spanner', function() { }); }); - describe('read only', function() { - it('should run a read only transaction', function(done) { + describe('read only', () => { + it('should run a read only transaction', done => { const options = { readOnly: true, strong: true, }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); - transaction.run('SELECT * FROM TxnTable', function(err, rows) { + transaction.run('SELECT * FROM TxnTable', (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, records.length); @@ -3431,12 +3431,12 @@ describe('Spanner', function() { }); }); - it('should read keys from a table', function(done) { + it('should read keys from a table', done => { const options = { readOnly: true, }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); const query = { @@ -3449,7 +3449,7 @@ describe('Spanner', function() { columns: ['Key'], }; - transaction.read(table.name, query, function(err, rows) { + transaction.read(table.name, query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, records.length); @@ -3458,16 +3458,16 @@ describe('Spanner', function() { }); }); - it('should accept a read timestamp', function(done) { + it('should accept a read timestamp', done => { const options = { readOnly: true, readTimestamp: records[1].timestamp, }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); - transaction.run('SELECT * FROM TxnTable', function(err, rows) { + transaction.run('SELECT * FROM TxnTable', (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 1); @@ -3482,7 +3482,7 @@ describe('Spanner', function() { }); }); - it('should accept a min timestamp', function(done) { + it('should accept a min timestamp', done => { const query = 'SELECT * FROM TxnTable'; const options = { @@ -3491,23 +3491,23 @@ describe('Spanner', function() { // minTimestamp can only be used in single use transactions // so we can't use database.runTransaction here - database.run(query, options, function(err, rows) { + database.run(query, options, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, records.length); done(); }); }); - it('should accept an exact staleness', function(done) { + it('should accept an exact staleness', done => { const options = { readOnly: true, exactStaleness: Math.ceil((Date.now() - records[2].timestamp) / 1000), }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); - transaction.run('SELECT * FROM TxnTable', function(err, rows) { + transaction.run('SELECT * FROM TxnTable', (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 2); @@ -3523,7 +3523,7 @@ describe('Spanner', function() { }); }); - it('should accept a max staleness', function(done) { + it('should accept a max staleness', done => { const query = 'SELECT * FROM TxnTable'; const options = { @@ -3532,25 +3532,25 @@ describe('Spanner', function() { // minTimestamp can only be used in single use transactions // so we can't use database.runTransaction here - database.run(query, options, function(err, rows) { + database.run(query, options, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, records.length); done(); }); }); - it('should do a strong read with concurrent updates', function(done) { + it('should do a strong read with concurrent updates', done => { const options = { readOnly: true, strong: true, }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); const query = 'SELECT * FROM TxnTable'; - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, records.length); @@ -3559,10 +3559,10 @@ describe('Spanner', function() { Key: 'k4', StringValue: 'v44', }, - function(err) { + err => { assert.ifError(err); - transaction.run(query, function(err, rows_) { + transaction.run(query, (err, rows_) => { assert.ifError(err); const row = rows_.pop().toJSON(); @@ -3576,18 +3576,18 @@ describe('Spanner', function() { }); }); - it('should do an exact read with concurrent updates', function(done) { + it('should do an exact read with concurrent updates', done => { const options = { readOnly: true, readTimestamp: records[records.length - 1].timestamp, }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); const query = 'SELECT * FROM TxnTable'; - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); const originalRows = extend(true, {}, rows); @@ -3598,10 +3598,10 @@ describe('Spanner', function() { Key: rows[0].toJSON().Key, StringValue: 'overridden value', }, - function(err) { + err => { assert.ifError(err); - transaction.run(query, function(err, rows_) { + transaction.run(query, (err, rows_) => { assert.ifError(err); rows_ = extend(true, {}, rows_); @@ -3616,18 +3616,18 @@ describe('Spanner', function() { }); }); - it('should read with staleness & concurrent updates', function(done) { + it('should read with staleness & concurrent updates', done => { const options = { readOnly: true, exactStaleness: Math.ceil((Date.now() - records[1].timestamp) / 1000), }; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { assert.ifError(err); const query = 'SELECT * FROM TxnTable'; - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 1); @@ -3636,10 +3636,10 @@ describe('Spanner', function() { Key: 'k4', StringValue: 'overridden value', }, - function(err) { + err => { assert.ifError(err); - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); assert.strictEqual(rows.length, 1); @@ -3652,9 +3652,9 @@ describe('Spanner', function() { }); }); - describe('read/write', function() { - it('should throw an error for mismatched columns', function(done) { - database.runTransaction(function(err, transaction) { + describe('read/write', () => { + it('should throw an error for mismatched columns', done => { + database.runTransaction((err, transaction) => { assert.ifError(err); const rows = [ @@ -3683,8 +3683,8 @@ describe('Spanner', function() { }); }); - it('should commit a transaction', function(done) { - database.runTransaction(function(err, transaction) { + it('should commit a transaction', done => { + database.runTransaction((err, transaction) => { assert.ifError(err); transaction.insert(table.name, { @@ -3696,35 +3696,35 @@ describe('Spanner', function() { }); }); - it('should rollback a transaction', function(done) { - database.runTransaction(function(err, transaction) { + it('should rollback a transaction', done => { + database.runTransaction((err, transaction) => { assert.ifError(err); - transaction.run('SELECT * FROM TxnTable', function(err) { + transaction.run('SELECT * FROM TxnTable', err => { assert.ifError(err); transaction.rollback(done); }); }); }); - describe('concurrent transactions', function() { + describe('concurrent transactions', () => { const defaultRowValues = { Key: 'k0', NumberValue: 0, }; - beforeEach(function() { + beforeEach(() => { return table.update(defaultRowValues); }); - it('should handle concurrent transactions with read', function(done) { - database.runTransaction(function(err, transaction) { + it('should handle concurrent transactions with read', done => { + database.runTransaction((err, transaction) => { assert.ifError(err); - incrementValue(function(err) { + incrementValue(err => { assert.ifError(err); - getValue(transaction, function(err, value) { + getValue(transaction, (err, value) => { assert.ifError(err); assert.strictEqual(value, defaultRowValues.NumberValue + 1); done(); @@ -3733,10 +3733,10 @@ describe('Spanner', function() { }); function incrementValue(callback) { - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { assert.ifError(err); - getValue(transaction, function(err, value) { + getValue(transaction, (err, value) => { if (err) { callback(err); return; @@ -3759,7 +3759,7 @@ describe('Spanner', function() { keys: [defaultRowValues.Key], columns: ['NumberValue'], }, - function(err, rows) { + (err, rows) => { if (err) { callback(err); return; @@ -3772,14 +3772,14 @@ describe('Spanner', function() { } }); - it('should handle concurrent transactions with query', function(done) { - database.runTransaction(function(err, transaction) { + it('should handle concurrent transactions with query', done => { + database.runTransaction((err, transaction) => { assert.ifError(err); - incrementValue(function(err) { + incrementValue(err => { assert.ifError(err); - getValue(transaction, function(err, value) { + getValue(transaction, (err, value) => { assert.ifError(err); assert.strictEqual(value, defaultRowValues.NumberValue + 1); done(); @@ -3788,10 +3788,10 @@ describe('Spanner', function() { }); function incrementValue(callback) { - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { assert.ifError(err); - getValue(transaction, function(err, value) { + getValue(transaction, (err, value) => { if (err) { callback(err); return; @@ -3815,7 +3815,7 @@ describe('Spanner', function() { key: defaultRowValues.Key, }, }, - function(err, rows) { + (err, rows) => { if (err) { callback(err); return; @@ -3829,7 +3829,7 @@ describe('Spanner', function() { }); }); - it('should retry an aborted txn when reading fails', function(done) { + it('should retry an aborted txn when reading fails', done => { const query = `SELECT * FROM ${table.name}`; let attempts = 0; @@ -3839,18 +3839,18 @@ describe('Spanner', function() { StringValue: 'abc', }; - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { assert.ifError(err); - transaction.run(query, function(err) { + transaction.run(query, err => { assert.ifError(err); const action = attempts++ === 0 ? runOtherTransaction : wrap; - action(function(err) { + action(err => { assert.ifError(err); - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); transaction.insert(table.name, { @@ -3858,7 +3858,7 @@ describe('Spanner', function() { StringValue: generateName('val'), }); - transaction.commit(function(err) { + transaction.commit(err => { assert.ifError(err); const lastRow = rows.pop().toJSON(); @@ -3874,13 +3874,13 @@ describe('Spanner', function() { }); function runOtherTransaction(callback) { - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { if (err) { callback(err); return; } - transaction.run(query, function(err) { + transaction.run(query, err => { if (err) { callback(err); return; @@ -3897,7 +3897,7 @@ describe('Spanner', function() { } }); - it('should retry an aborted txn when commit fails', function(done) { + it('should retry an aborted txn when commit fails', done => { const query = `SELECT * FROM ${table.name}`; let attempts = 0; @@ -3907,10 +3907,10 @@ describe('Spanner', function() { StringValue: 'abc', }; - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { assert.ifError(err); - transaction.run(query, function(err, rows) { + transaction.run(query, (err, rows) => { assert.ifError(err); transaction.insert(table.name, { @@ -3919,14 +3919,14 @@ describe('Spanner', function() { }); if (attempts++ === 0) { - runOtherTransaction(function(err) { + runOtherTransaction(err => { assert.ifError(err); transaction.commit(done); // should not execute callback }); return; } - transaction.commit(function(err) { + transaction.commit(err => { assert.ifError(err); const lastRow = rows.pop().toJSON(); @@ -3940,13 +3940,13 @@ describe('Spanner', function() { }); function runOtherTransaction(callback) { - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { if (err) { callback(err); return; } - transaction.run(query, function(err) { + transaction.run(query, err => { if (err) { callback(err); return; @@ -3959,7 +3959,7 @@ describe('Spanner', function() { } }); - it('should return a deadline error instead of aborted', function(done) { + it('should return a deadline error instead of aborted', done => { const options = { timeout: 10, }; @@ -3967,7 +3967,7 @@ describe('Spanner', function() { const query = `SELECT * FROM ${table.name}`; let attempts = 0; - database.runTransaction(options, function(err, transaction) { + database.runTransaction(options, (err, transaction) => { if (attempts++ === 1) { assert.strictEqual(err.code, 4); assert( @@ -3982,17 +3982,17 @@ describe('Spanner', function() { assert.ifError(err); - transaction.run(query, function(err) { + transaction.run(query, err => { assert.ifError(err); transaction.insert(table.name, { Key: generateName('key'), }); - runOtherTransaction(function(err) { + runOtherTransaction(err => { assert.ifError(err); - transaction.commit(function() { + transaction.commit(() => { done(new Error('Should not have been called.')); }); }); @@ -4000,13 +4000,13 @@ describe('Spanner', function() { }); function runOtherTransaction(callback) { - database.runTransaction(function(err, transaction) { + database.runTransaction((err, transaction) => { if (err) { callback(err); return; } - transaction.run(query, function(err) { + transaction.run(query, err => { if (err) { callback(err); return; @@ -4053,7 +4053,7 @@ function execAfterOperationComplete(callback) { return; } - operation.on('error', callback).on('complete', function(metadata) { + operation.on('error', callback).on('complete', metadata => { callback(null, metadata); }); }; @@ -4064,7 +4064,7 @@ function deleteTestInstances(callback) { { filter: 'labels.gcloud-tests:true', }, - function(err, instances) { + (err, instances) => { if (err) { callback(err); return; @@ -4073,8 +4073,8 @@ function deleteTestInstances(callback) { async.eachLimit( instances, 5, - function(instance, callback) { - setTimeout(function() { + (instance, callback) => { + setTimeout(() => { instance.delete(callback); }, 500); // Delay allows the instance and its databases to fully clear. }, @@ -4089,7 +4089,7 @@ function deleteTestResources(callback) { } function wait(time) { - return new Promise(function(resolve) { + return new Promise(resolve => { setTimeout(resolve, time); }); } diff --git a/test/batch-transaction.js b/test/batch-transaction.js index 33b62a56b..3e499b452 100644 --- a/test/batch-transaction.js +++ b/test/batch-transaction.js @@ -43,13 +43,13 @@ function FakeTransaction(session) { this.session = session; } -describe('BatchTransaction', function() { +describe('BatchTransaction', () => { let BatchTransaction; let batchTransaction; const SESSION = {}; - before(function() { + before(() => { BatchTransaction = proxyquire('../src/batch-transaction.js', { '@google-cloud/promisify': fakePfy, './codec.js': fakeCodec, @@ -57,16 +57,16 @@ describe('BatchTransaction', function() { }); }); - beforeEach(function() { + beforeEach(() => { batchTransaction = new BatchTransaction(SESSION); }); - describe('instantiation', function() { - it('should promisify all the things', function() { + describe('instantiation', () => { + it('should promisify all the things', () => { assert(promisified); }); - it('should extend the Transaction class', function() { + it('should extend the Transaction class', () => { const batchTransaction = new BatchTransaction(SESSION); assert(batchTransaction instanceof FakeTransaction); @@ -75,8 +75,8 @@ describe('BatchTransaction', function() { }); }); - describe('close', function() { - it('should delete the session', function(done) { + describe('close', () => { + it('should delete the session', done => { SESSION.delete = function(callback) { callback(); // the done fn }; @@ -85,14 +85,14 @@ describe('BatchTransaction', function() { }); }); - describe('createQueryPartitions', function() { + describe('createQueryPartitions', () => { const GAX_OPTS = {a: 'b'}; const QUERY = { sql: 'SELECT * FROM Singers', gaxOptions: GAX_OPTS, }; - it('should make the correct request', function(done) { + it('should make the correct request', done => { fakeCodec.encodeQuery = function(query) { assert.deepStrictEqual(query, {sql: QUERY.sql}); return QUERY; @@ -108,7 +108,7 @@ describe('BatchTransaction', function() { batchTransaction.createQueryPartitions(QUERY.sql, done); }); - it('should remove gax options from the query', function(done) { + it('should remove gax options from the query', done => { const fakeQuery = { sql: QUERY.sql, gaxOptions: GAX_OPTS, @@ -129,7 +129,7 @@ describe('BatchTransaction', function() { }); }); - describe('createPartitions_', function() { + describe('createPartitions_', () => { const SESSION = {formattedName_: 'abcdef'}; const ID = 'ghijkl'; const TIMESTAMP = {seconds: 0, nanos: 0}; @@ -140,7 +140,7 @@ describe('BatchTransaction', function() { const QUERY = {a: 'b'}; const CONFIG = {reqOpts: QUERY}; - beforeEach(function() { + beforeEach(() => { batchTransaction.session = SESSION; batchTransaction.id = ID; @@ -149,7 +149,7 @@ describe('BatchTransaction', function() { }; }); - it('should insert the session and transaction ids', function(done) { + it('should insert the session and transaction ids', done => { batchTransaction.request = function(config) { assert.strictEqual(config.reqOpts.a, 'b'); assert.strictEqual(config.reqOpts.session, SESSION.formattedName_); @@ -160,7 +160,7 @@ describe('BatchTransaction', function() { batchTransaction.createPartitions_(CONFIG, assert.ifError); }); - it('should return any request errors', function(done) { + it('should return any request errors', done => { const error = new Error('err'); const response = {}; @@ -168,7 +168,7 @@ describe('BatchTransaction', function() { callback(error, response); }; - batchTransaction.createPartitions_(CONFIG, function(err, parts, resp) { + batchTransaction.createPartitions_(CONFIG, (err, parts, resp) => { assert.strictEqual(err, error); assert.strictEqual(parts, null); assert.strictEqual(resp, response); @@ -176,17 +176,17 @@ describe('BatchTransaction', function() { }); }); - it('should return the prepared partition configs', function(done) { + it('should return the prepared partition configs', done => { const expectedQuery = { a: 'b', session: SESSION.formattedName_, transaction: {id: ID}, }; - batchTransaction.createPartitions_(CONFIG, function(err, parts) { + batchTransaction.createPartitions_(CONFIG, (err, parts) => { assert.ifError(err); - parts.forEach(function(partition, i) { + parts.forEach((partition, i) => { const expectedPartition = extend({}, expectedQuery, PARTITIONS[i]); assert.deepStrictEqual(partition, expectedPartition); }); @@ -195,7 +195,7 @@ describe('BatchTransaction', function() { }); }); - it('should update the transaction with returned metadata', function(done) { + it('should update the transaction with returned metadata', done => { const response = extend({}, RESPONSE, { transaction: { id: ID, @@ -207,7 +207,7 @@ describe('BatchTransaction', function() { callback(null, response); }; - batchTransaction.createPartitions_(CONFIG, function(err, parts, resp) { + batchTransaction.createPartitions_(CONFIG, (err, parts, resp) => { assert.strictEqual(resp, response); assert.strictEqual(batchTransaction.id, ID); assert.strictEqual(batchTransaction.readTimestamp, TIMESTAMP); @@ -216,11 +216,11 @@ describe('BatchTransaction', function() { }); }); - describe('createReadPartitions', function() { + describe('createReadPartitions', () => { const GAX_OPTS = {}; const QUERY = {table: 'abc', gaxOptions: GAX_OPTS}; - it('should make the correct request', function(done) { + it('should make the correct request', done => { const query = {}; fakeCodec.encodeRead = function(options) { @@ -238,7 +238,7 @@ describe('BatchTransaction', function() { batchTransaction.createReadPartitions(query, done); }); - it('should remove gax options from the query', function(done) { + it('should remove gax options from the query', done => { const query = {gaxOptions: GAX_OPTS}; fakeCodec.encodeRead = function() { @@ -255,8 +255,8 @@ describe('BatchTransaction', function() { }); }); - describe('execute', function() { - it('should make read requests for read partitions', function(done) { + describe('execute', () => { + it('should make read requests for read partitions', done => { const partition = {table: 'abc'}; batchTransaction.read = function(table, options, callback) { @@ -268,7 +268,7 @@ describe('BatchTransaction', function() { batchTransaction.execute(partition, done); }); - it('should make query requests for non-read partitions', function(done) { + it('should make query requests for non-read partitions', done => { const partition = {sql: 'SELECT * FROM Singers'}; batchTransaction.run = function(query, callback) { @@ -280,10 +280,10 @@ describe('BatchTransaction', function() { }); }); - describe('executeStream', function() { + describe('executeStream', () => { const STREAM = {}; - it('should make read streams for read partitions', function() { + it('should make read streams for read partitions', () => { const partition = {table: 'abc'}; batchTransaction.createReadStream = function(table, options) { @@ -297,7 +297,7 @@ describe('BatchTransaction', function() { assert.strictEqual(stream, STREAM); }); - it('should make query streams for query partitions', function() { + it('should make query streams for query partitions', () => { const partition = {sql: 'SELECT * FROM Singers'}; batchTransaction.runStream = function(query) { @@ -311,18 +311,18 @@ describe('BatchTransaction', function() { }); }); - describe('identifier', function() { + describe('identifier', () => { const ID = Buffer.from('abc'); const SESSION = {id: 'def'}; const TIMESTAMP = {seconds: 0, nanos: 0}; - beforeEach(function() { + beforeEach(() => { batchTransaction.id = ID; batchTransaction.session = SESSION; batchTransaction.readTimestamp = TIMESTAMP; }); - it('should create a transaction identifier', function() { + it('should create a transaction identifier', () => { const expectedId = ID.toString('base64'); const identifier = batchTransaction.identifier(); diff --git a/test/codec.js b/test/codec.js index 7a438af4e..c9f8f8007 100644 --- a/test/codec.js +++ b/test/codec.js @@ -23,7 +23,7 @@ const {util} = require('@google-cloud/common-grpc'); function FakeGrpcService() {} -describe('codec', function() { +describe('codec', () => { let codecCached; let codec; @@ -40,7 +40,7 @@ describe('codec', function() { 'struct', ]; - before(function() { + before(() => { codec = proxyquire('../src/codec.js', { '@google-cloud/common-grpc': { Service: FakeGrpcService, @@ -49,45 +49,45 @@ describe('codec', function() { codecCached = extend({}, codec); }); - beforeEach(function() { + beforeEach(() => { extend(codec, codecCached); FakeGrpcService.encodeValue_ = util.noop; FakeGrpcService.decodeValue_ = util.noop; }); - describe('SpannerDate', function() { - it('should choke on multiple arguments', function() { + describe('SpannerDate', () => { + it('should choke on multiple arguments', () => { const expectedErrorMessage = [ 'The spanner.date function accepts a Date object or a', "single argument parseable by Date's constructor.", ].join(' '); - assert.throws(function() { + assert.throws(() => { new codec.SpannerDate(2012, 3, 21); }, new RegExp(expectedErrorMessage)); }); - it('should create an instance from a string', function() { + it('should create an instance from a string', () => { const spannerDate = new codec.SpannerDate('08-20-1969'); assert.strictEqual(spannerDate.value, '1969-08-20'); }); - it('should create an instance from a Date object', function() { + it('should create an instance from a Date object', () => { const date = new Date(); const spannerDate = new codec.SpannerDate(date); assert.strictEqual(spannerDate.value, date.toJSON().replace(/T.+/, '')); }); }); - describe('Float', function() { - it('should store the value', function() { + describe('Float', () => { + it('should store the value', () => { const value = 8; const float = new codec.Float(value); assert.strictEqual(float.value, value); }); - it('should return as a float', function() { + it('should return as a float', () => { const value = '8.2'; const float = new codec.Float(value); @@ -96,15 +96,15 @@ describe('codec', function() { }); }); - describe('Int', function() { - it('should stringify the value', function() { + describe('Int', () => { + it('should stringify the value', () => { const value = 8; const int = new codec.Int(value); assert.strictEqual(int.value, '8'); }); - it('should return as a number', function() { + it('should return as a number', () => { const value = 8; const int = new codec.Int(value); @@ -112,35 +112,35 @@ describe('codec', function() { assert.strictEqual(int + 2, 10); }); - it('should throw if number is out of bounds', function() { + it('should throw if number is out of bounds', () => { const value = '9223372036854775807'; const int = new codec.Int(value); - assert.throws(function() { + assert.throws(() => { int.valueOf(); }, new RegExp('Integer ' + value + ' is out of bounds.')); }); }); - describe('Struct', function() { + describe('Struct', () => { let generateToJSONFromRow_; - before(function() { + before(() => { generateToJSONFromRow_ = codec.generateToJSONFromRow; }); - afterEach(function() { + afterEach(() => { codec.generateToJSONFromRow = generateToJSONFromRow_; }); - describe('initialization', function() { - it('should create an array', function() { + describe('initialization', () => { + it('should create an array', () => { const struct = new codec.Struct(); assert(Array.isArray(struct)); }); - it('should set the type', function() { + it('should set the type', () => { const struct = new codec.Struct(); const type = struct[codec.TYPE]; @@ -148,7 +148,7 @@ describe('codec', function() { assert.strictEqual(type, codec.Struct.TYPE); }); - it('should create a toJSON property', function() { + it('should create a toJSON property', () => { const fakeJSON = {}; let cachedStruct; @@ -164,8 +164,8 @@ describe('codec', function() { }); }); - describe('fromJSON', function() { - it('should capture the key value pairs', function() { + describe('fromJSON', () => { + it('should capture the key value pairs', () => { const json = {a: 'b', c: 'd'}; const struct = codec.Struct.fromJSON(json); @@ -178,8 +178,8 @@ describe('codec', function() { }); }); - describe('fromArray', function() { - it('should convert array to struct array', function() { + describe('fromArray', () => { + it('should convert array to struct array', () => { const arr = [{name: 'a', value: 1}, {name: 'b', value: 2}]; const struct = codec.Struct.fromArray(arr); @@ -191,21 +191,21 @@ describe('codec', function() { }); }); - describe('isStruct', function() { - it('should return true for structs', function() { + describe('isStruct', () => { + it('should return true for structs', () => { const struct = new codec.Struct(); const isStruct = codec.Struct.isStruct(struct); assert.strictEqual(isStruct, true); }); - it('should return false for arrays', function() { + it('should return false for arrays', () => { const isStruct = codec.Struct.isStruct([]); assert.strictEqual(isStruct, false); }); - it('should return false for falsey values', function() { + it('should return false for falsey values', () => { const isStruct = codec.Struct.isStruct(null); assert.strictEqual(isStruct, false); @@ -213,7 +213,7 @@ describe('codec', function() { }); }); - describe('generateToJSONFromRow', function() { + describe('generateToJSONFromRow', () => { const ROW = [ { name: 'name', @@ -223,27 +223,27 @@ describe('codec', function() { let toJSON; - beforeEach(function() { + beforeEach(() => { toJSON = codec.generateToJSONFromRow(ROW); }); - it('should return a function', function() { + it('should return a function', () => { assert.strictEqual(typeof toJSON, 'function'); }); - it('should not require options', function() { - assert.doesNotThrow(function() { + it('should not require options', () => { + assert.doesNotThrow(() => { toJSON(); }); }); - it('should return serialized rows', function() { + it('should return serialized rows', () => { assert.deepStrictEqual(toJSON(), { name: 'value', }); }); - it('should not return nameless values', function() { + it('should not return nameless values', () => { const row = [ { value: 'value', @@ -254,7 +254,7 @@ describe('codec', function() { assert.deepStrictEqual(toJSON(), {}); }); - it('should not wrap numbers by default', function() { + it('should not wrap numbers by default', () => { const row = [ { name: 'Number', @@ -267,7 +267,7 @@ describe('codec', function() { assert.strictEqual(toJSON().Number, 3); }); - it('should wrap numbers with option', function() { + it('should wrap numbers with option', () => { const int = new codec.Int(3); const row = [ @@ -284,7 +284,7 @@ describe('codec', function() { assert.deepStrictEqual(value, int); }); - it('should throw an error if number is out of bounds', function() { + it('should throw an error if number is out of bounds', () => { const int = new codec.Int('9223372036854775807'); const row = [ @@ -296,13 +296,13 @@ describe('codec', function() { const toJSON = codec.generateToJSONFromRow(row); - assert.throws(function() { + assert.throws(() => { toJSON(); }, new RegExp('Serializing column "Number" encountered an error')); }); }); - describe('decode', function() { + describe('decode', () => { // Does not require any special decoding. const BYPASS_FIELD = { type: { @@ -310,20 +310,20 @@ describe('codec', function() { }, }; - beforeEach(function() { + beforeEach(() => { FakeGrpcService.decodeValue_ = function(value) { return value; }; }); - it('should return the same value if not a special type', function() { + it('should return the same value if not a special type', () => { const value = {}; const decoded = codec.decode(value, BYPASS_FIELD); assert.strictEqual(decoded, value); }); - it('should return null values as null', function() { + it('should return null values as null', () => { FakeGrpcService.decodeValue_ = function() { return null; }; @@ -332,7 +332,7 @@ describe('codec', function() { assert.strictEqual(decoded, null); }); - it('should decode BYTES', function() { + it('should decode BYTES', () => { const value = Buffer.from('bytes value'); const decoded = codec.decode(value.toString('base64'), { @@ -344,7 +344,7 @@ describe('codec', function() { assert.deepStrictEqual(decoded, Buffer.from(value, 'base64')); }); - it('should decode FLOAT64', function() { + it('should decode FLOAT64', () => { const value = 'Infinity'; const decoded = codec.decode(value, { @@ -357,7 +357,7 @@ describe('codec', function() { assert.strictEqual(decoded.value, value); }); - it('should decode INT64', function() { + it('should decode INT64', () => { const value = '64'; const decoded = codec.decode(value, { @@ -370,7 +370,7 @@ describe('codec', function() { assert.strictEqual(decoded.value, value); }); - it('should decode TIMESTAMP', function() { + it('should decode TIMESTAMP', () => { const value = new Date(); const decoded = codec.decode(value.toJSON(), { @@ -382,7 +382,7 @@ describe('codec', function() { assert.deepStrictEqual(decoded, value); }); - it('should decode DATE', function() { + it('should decode DATE', () => { const value = new Date(); const decoded = codec.decode(value.toJSON(), { @@ -394,7 +394,7 @@ describe('codec', function() { assert.deepStrictEqual(decoded, value); }); - it('should decode ARRAY and inner members', function() { + it('should decode ARRAY and inner members', () => { const value = ['1']; const decoded = codec.decode(value, { @@ -409,7 +409,7 @@ describe('codec', function() { assert(decoded[0] instanceof codec.Int); }); - it('should decode STRUCT and inner members', function() { + it('should decode STRUCT and inner members', () => { const value = { fieldName: '1', }; @@ -449,14 +449,14 @@ describe('codec', function() { }); }); - describe('encode', function() { - beforeEach(function() { + describe('encode', () => { + beforeEach(() => { FakeGrpcService.encodeValue_ = function(value) { return value; }; }); - it('should return the value from the common encoder', function() { + it('should return the value from the common encoder', () => { const value = {}; const defaultEncodedValue = {}; @@ -469,7 +469,7 @@ describe('codec', function() { assert.strictEqual(encoded, defaultEncodedValue); }); - it('should encode BYTES', function() { + it('should encode BYTES', () => { const value = Buffer.from('bytes value'); const encoded = codec.encode(value); @@ -477,14 +477,14 @@ describe('codec', function() { assert.strictEqual(encoded, value.toString('base64')); }); - it('should encode structs', function() { + it('should encode structs', () => { const value = codec.Struct.fromJSON({a: 'b', c: 'd'}); const encoded = codec.encode(value); assert.deepStrictEqual(encoded, ['b', 'd']); }); - it('should stringify Infinity', function() { + it('should stringify Infinity', () => { const value = Infinity; const encoded = codec.encode(value); @@ -492,7 +492,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.toString()); }); - it('should stringify -Infinity', function() { + it('should stringify -Infinity', () => { const value = -Infinity; const encoded = codec.encode(value); @@ -500,7 +500,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.toString()); }); - it('should stringify NaN', function() { + it('should stringify NaN', () => { const value = NaN; const encoded = codec.encode(value); @@ -508,7 +508,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.toString()); }); - it('should stringify INT64', function() { + it('should stringify INT64', () => { const value = 5; const encoded = codec.encode(value); @@ -516,7 +516,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.toString()); }); - it('should encode ARRAY and inner members', function() { + it('should encode ARRAY and inner members', () => { const value = [5]; const encoded = codec.encode(value); @@ -526,7 +526,7 @@ describe('codec', function() { ]); }); - it('should encode TIMESTAMP', function() { + it('should encode TIMESTAMP', () => { const value = new Date(); const encoded = codec.encode(value); @@ -534,7 +534,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.toJSON()); }); - it('should encode DATE', function() { + it('should encode DATE', () => { const value = new codec.SpannerDate(); const encoded = codec.encode(value); @@ -542,7 +542,7 @@ describe('codec', function() { assert.strictEqual(encoded, value.value); }); - it('should encode INT64', function() { + it('should encode INT64', () => { const value = new codec.Int(10); const encoded = codec.encode(value); @@ -550,7 +550,7 @@ describe('codec', function() { assert.strictEqual(encoded, '10'); }); - it('should encode FLOAT64', function() { + it('should encode FLOAT64', () => { const value = new codec.Float(10); const encoded = codec.encode(value); @@ -558,7 +558,7 @@ describe('codec', function() { assert.strictEqual(encoded, 10); }); - it('should encode each key in a dictionary-like object', function() { + it('should encode each key in a dictionary-like object', () => { const obj = { f: new codec.Float(10), i: new codec.Int(10), @@ -567,7 +567,7 @@ describe('codec', function() { assert.deepStrictEqual(encoded, {f: 10, i: '10'}); }); - it('should only encode public properties of objects', function() { + it('should only encode public properties of objects', () => { const obj = { hasOwnProperty: function(key) { // jshint ignore:line @@ -582,12 +582,12 @@ describe('codec', function() { }); }); - describe('getType', function() { - it('should determine if the value is a boolean', function() { + describe('getType', () => { + it('should determine if the value is a boolean', () => { assert.strictEqual(codec.getType(true), 'bool'); }); - it('should determine if the value is a float', function() { + it('should determine if the value is a float', () => { assert.strictEqual(codec.getType(NaN), 'float64'); assert.strictEqual(codec.getType(Infinity), 'float64'); assert.strictEqual(codec.getType(-Infinity), 'float64'); @@ -595,28 +595,28 @@ describe('codec', function() { assert.strictEqual(codec.getType(new codec.Float(1.1)), 'float64'); }); - it('should determine if the value is an int', function() { + it('should determine if the value is an int', () => { assert.strictEqual(codec.getType(1234), 'int64'); assert.strictEqual(codec.getType(new codec.Int(1)), 'int64'); }); - it('should determine if the value is a string', function() { + it('should determine if the value is a string', () => { assert.strictEqual(codec.getType('abc'), 'string'); }); - it('should determine if the value is bytes', function() { + it('should determine if the value is bytes', () => { assert.strictEqual(codec.getType(Buffer.from('abc')), 'bytes'); }); - it('should determine if the value is a timestamp', function() { + it('should determine if the value is a timestamp', () => { assert.strictEqual(codec.getType(new Date()), 'timestamp'); }); - it('should determine if the value is a date', function() { + it('should determine if the value is a date', () => { assert.strictEqual(codec.getType(new codec.SpannerDate()), 'date'); }); - it('should determine if the value is a struct', function() { + it('should determine if the value is a struct', () => { const struct = codec.Struct.fromJSON({a: 'b'}); const type = codec.getType(struct); @@ -631,14 +631,14 @@ describe('codec', function() { }); }); - it('should attempt to determine arrays and their values', function() { + it('should attempt to determine arrays and their values', () => { assert.deepStrictEqual(codec.getType([Infinity]), { type: 'array', child: 'float64', }); }); - it('should return unspecified for unknown values', function() { + it('should return unspecified for unknown values', () => { assert.strictEqual(codec.getType(null), 'unspecified'); assert.deepStrictEqual(codec.getType([null]), { @@ -648,13 +648,13 @@ describe('codec', function() { }); }); - describe('TYPES', function() { - it('should export types', function() { + describe('TYPES', () => { + it('should export types', () => { assert.deepStrictEqual(codec.TYPES, TYPES); }); }); - describe('encodeQuery', function() { + describe('encodeQuery', () => { let createTypeObject_; const QUERY = { @@ -663,15 +663,15 @@ describe('codec', function() { c: 'd', }; - before(function() { + before(() => { createTypeObject_ = codec.createTypeObject; }); - afterEach(function() { + afterEach(() => { codec.createTypeObject = createTypeObject_; }); - it('should return the query', function() { + it('should return the query', () => { const fakeQuery = { a: 'b', c: 'd', @@ -682,7 +682,7 @@ describe('codec', function() { assert.deepStrictEqual(fakeQuery, encodedQuery); }); - it('should clone the query', function() { + it('should clone the query', () => { const fakeQuery = { a: 'b', }; @@ -694,7 +694,7 @@ describe('codec', function() { assert.strictEqual(fakeQuery.a, 'b'); }); - it('should encode query parameters', function() { + it('should encode query parameters', () => { const fakeQuery = { sql: QUERY, params: { @@ -713,7 +713,7 @@ describe('codec', function() { assert.strictEqual(encodedQuery.params.fields.test, encodedValue); }); - it('should attempt to guess the parameter types', function() { + it('should attempt to guess the parameter types', () => { const params = { unspecified: null, bool: true, @@ -771,7 +771,7 @@ describe('codec', function() { }); }); - it('should not overwrite existing type definitions', function() { + it('should not overwrite existing type definitions', () => { const fakeQuery = { params: { test: 123, @@ -788,7 +788,7 @@ describe('codec', function() { codec.encodeQuery(fakeQuery); }); - it('should create type objects', function() { + it('should create type objects', () => { const fakeQuery = { types: { test: 'string', @@ -807,7 +807,7 @@ describe('codec', function() { assert.deepStrictEqual(query.paramTypes, {test: fakeTypeObject}); }); - it('should delete the type map from the request options', function() { + it('should delete the type map from the request options', () => { const fakeQuery = { params: { test: 'abc', @@ -822,9 +822,9 @@ describe('codec', function() { }); }); - describe('encodeRead', function() { - describe('query.keys', function() { - it('should encode and map input to keySet', function() { + describe('encodeRead', () => { + describe('query.keys', () => { + it('should encode and map input to keySet', () => { const query = { keys: ['key', ['composite', 'key']], }; @@ -866,7 +866,7 @@ describe('codec', function() { assert.deepStrictEqual(encoded.keySet.keys, expectedKeys); }); - it('should accept just a key', function() { + it('should accept just a key', () => { const query = 'key'; const encodedValue = {}; @@ -880,7 +880,7 @@ describe('codec', function() { assert.strictEqual(encoded.keySet.keys[0].values[0], encodedValue); }); - it('should accept just an array of keys', function() { + it('should accept just an array of keys', () => { const query = ['key']; const encodedValue = {}; @@ -894,7 +894,7 @@ describe('codec', function() { assert.strictEqual(encoded.keySet.keys[0].values[0], encodedValue); }); - it('should arrify query.keys', function() { + it('should arrify query.keys', () => { const query = { keys: 'key', }; @@ -910,7 +910,7 @@ describe('codec', function() { assert.strictEqual(encoded.keySet.keys[0].values[0], encodedValue); }); - it('should remove keys property from request object', function() { + it('should remove keys property from request object', () => { const query = { keys: ['key'], }; @@ -921,8 +921,8 @@ describe('codec', function() { }); }); - describe('query.ranges', function() { - it('should encode/map the inputs', function() { + describe('query.ranges', () => { + it('should encode/map the inputs', () => { const query = { ranges: [ { @@ -959,7 +959,7 @@ describe('codec', function() { assert.deepStrictEqual(encoded.keySet.ranges, expectedRanges); }); - it('should arrify query.ranges', function() { + it('should arrify query.ranges', () => { const query = { ranges: [ { @@ -994,7 +994,7 @@ describe('codec', function() { assert.deepStrictEqual(encoded.keySet.ranges, expectedRanges); }); - it('should remove the ranges property from the query', function() { + it('should remove the ranges property from the query', () => { const query = { ranges: [ { @@ -1011,22 +1011,22 @@ describe('codec', function() { }); }); - describe('createTypeObject', function() { - it('should convert the type to its int value', function() { - TYPES.forEach(function(typeName, i) { + describe('createTypeObject', () => { + it('should convert the type to its int value', () => { + TYPES.forEach((typeName, i) => { const type = codec.createTypeObject(typeName); assert.deepStrictEqual(type.code, i); }); }); - it('should default to unspecified for unknown types', function() { + it('should default to unspecified for unknown types', () => { const type = codec.createTypeObject('unicorn'); assert.deepStrictEqual(type, {code: TYPES.indexOf('unspecified')}); }); - it('should set the arrayElementType', function() { + it('should set the arrayElementType', () => { const type = codec.createTypeObject({ type: 'array', child: 'bool', @@ -1040,7 +1040,7 @@ describe('codec', function() { }); }); - it('should set the struct fields', function() { + it('should set the struct fields', () => { const type = codec.createTypeObject({ type: 'struct', fields: [ @@ -1070,7 +1070,7 @@ describe('codec', function() { }); }); - it('should handle nested structs', function() { + it('should handle nested structs', () => { const type = codec.createTypeObject({ type: 'struct', fields: [ diff --git a/test/database.js b/test/database.js index 4eca8fcee..8584a570a 100644 --- a/test/database.js +++ b/test/database.js @@ -83,7 +83,7 @@ const fakeCodec = { SpannerDate: function() {}, }; -describe('Database', function() { +describe('Database', () => { let Database; let DatabaseCached; @@ -102,7 +102,7 @@ describe('Database', function() { let database; - before(function() { + before(() => { Database = proxyquire('../src/database.js', { '@google-cloud/common-grpc': { ServiceObject: FakeGrpcServiceObject, @@ -119,27 +119,27 @@ describe('Database', function() { DatabaseCached = extend({}, Database); }); - beforeEach(function() { + beforeEach(() => { fakeCodec.encode = util.noop; extend(Database, DatabaseCached); database = new Database(INSTANCE, NAME, POOL_OPTIONS); database.parent = INSTANCE; }); - describe('instantiation', function() { - it('should promisify all the things', function() { + describe('instantiation', () => { + it('should promisify all the things', () => { assert(promisified); }); - it('should localize the request function', function() { + it('should localize the request function', () => { assert.strictEqual(database.request, INSTANCE.request); }); - it('should localize the requestStream function', function() { + it('should localize the requestStream function', () => { assert.strictEqual(database.requestStream, INSTANCE.requestStream); }); - it('should format the name', function() { + it('should format the name', () => { const formatName_ = Database.formatName_; const formattedName = 'formatted-name'; @@ -156,13 +156,13 @@ describe('Database', function() { assert(database.formattedName_, formattedName); }); - it('should create a SessionPool object', function() { + it('should create a SessionPool object', () => { assert(database.pool_ instanceof FakeSessionPool); assert.strictEqual(database.pool_.calledWith_[0], database); assert.strictEqual(database.pool_.calledWith_[1], POOL_OPTIONS); }); - it('should accept a custom Pool class', function() { + it('should accept a custom Pool class', () => { function FakePool() {} FakePool.prototype.on = util.noop; FakePool.prototype.open = util.noop; @@ -171,10 +171,10 @@ describe('Database', function() { assert(database.pool_ instanceof FakePool); }); - it('should re-emit SessionPool errors', function(done) { + it('should re-emit SessionPool errors', done => { const error = new Error('err'); - database.on('error', function(err) { + database.on('error', err => { assert.strictEqual(err, error); done(); }); @@ -182,7 +182,7 @@ describe('Database', function() { database.pool_.emit('error', error); }); - it('should open the pool', function(done) { + it('should open the pool', done => { FakeSessionPool.prototype.open = function() { FakeSessionPool.prototype.open = util.noop; done(); @@ -191,7 +191,7 @@ describe('Database', function() { new Database(INSTANCE, NAME); }); - it('should inherit from ServiceObject', function(done) { + it('should inherit from ServiceObject', done => { const options = {}; const instanceInstance = extend({}, INSTANCE, { @@ -215,15 +215,15 @@ describe('Database', function() { }); }); - describe('formatName_', function() { - it('should return the name if already formatted', function() { + describe('formatName_', () => { + it('should return the name if already formatted', () => { assert.strictEqual( Database.formatName_(INSTANCE.formattedName_, DATABASE_FORMATTED_NAME), DATABASE_FORMATTED_NAME ); }); - it('should format the name', function() { + it('should format the name', () => { const formattedName_ = Database.formatName_( INSTANCE.formattedName_, NAME @@ -232,12 +232,12 @@ describe('Database', function() { }); }); - describe('batchTransaction', function() { + describe('batchTransaction', () => { const SESSION = {id: 'hijklmnop'}; const ID = 'abcdefg'; const READ_TIMESTAMP = {seconds: 0, nanos: 0}; - it('should create a transaction object', function() { + it('should create a transaction object', () => { const identifier = { session: SESSION, transaction: ID, @@ -252,7 +252,7 @@ describe('Database', function() { assert.strictEqual(transaction.readTimestamp, READ_TIMESTAMP); }); - it('should optionally accept a session id', function() { + it('should optionally accept a session id', () => { const identifier = { session: SESSION.id, transaction: ID, @@ -269,15 +269,15 @@ describe('Database', function() { }); }); - describe('close', function() { + describe('close', () => { const FAKE_ID = 'a/c/b/d'; - beforeEach(function() { + beforeEach(() => { database.id = FAKE_ID; }); - describe('success', function() { - beforeEach(function() { + describe('success', () => { + beforeEach(() => { database.parent = INSTANCE; database.pool_ = { close: function(callback) { @@ -286,18 +286,18 @@ describe('Database', function() { }; }); - it('should close the database', function(done) { + it('should close the database', done => { database.close(done); }); - it('should remove the database cache', function(done) { + it('should remove the database cache', done => { const cache = INSTANCE.databases_; const cacheId = FAKE_ID.split('/').pop(); cache.set(cacheId, database); assert(cache.has(cacheId)); - database.close(function(err) { + database.close(err => { assert.ifError(err); assert.strictEqual(cache.has(cacheId), false); done(); @@ -305,8 +305,8 @@ describe('Database', function() { }); }); - describe('error', function() { - it('should return the closing error', function(done) { + describe('error', () => { + it('should return the closing error', done => { const error = new Error('err.'); database.pool_ = { @@ -315,7 +315,7 @@ describe('Database', function() { }, }; - database.close(function(err) { + database.close(err => { assert.strictEqual(err, error); done(); }); @@ -323,17 +323,17 @@ describe('Database', function() { }); }); - describe('createBatchTransaction', function() { + describe('createBatchTransaction', () => { const SESSION = {}; const RESPONSE = {a: 'b'}; - beforeEach(function() { + beforeEach(() => { database.createSession = function(callback) { callback(null, SESSION, RESPONSE); }; }); - it('should return any session creation errors', function(done) { + it('should return any session creation errors', done => { const error = new Error('err'); const apiResponse = {c: 'd'}; @@ -341,7 +341,7 @@ describe('Database', function() { callback(error, null, apiResponse); }; - database.createBatchTransaction(function(err, transaction, resp) { + database.createBatchTransaction((err, transaction, resp) => { assert.strictEqual(err, error); assert.strictEqual(transaction, null); assert.strictEqual(resp, apiResponse); @@ -349,7 +349,7 @@ describe('Database', function() { }); }); - it('should create a transaction', function(done) { + it('should create a transaction', done => { const opts = {a: 'b'}; const fakeTransaction = { @@ -363,7 +363,7 @@ describe('Database', function() { return fakeTransaction; }; - database.createBatchTransaction(opts, function(err, transaction, resp) { + database.createBatchTransaction(opts, (err, transaction, resp) => { assert.strictEqual(err, null); assert.strictEqual(transaction, fakeTransaction); assert.deepStrictEqual(transaction.options, opts); @@ -372,7 +372,7 @@ describe('Database', function() { }); }); - it('should return any transaction errors', function(done) { + it('should return any transaction errors', done => { const error = new Error('err'); const fakeTransaction = { @@ -385,7 +385,7 @@ describe('Database', function() { return fakeTransaction; }; - database.createBatchTransaction(function(err, transaction, resp) { + database.createBatchTransaction((err, transaction, resp) => { assert.strictEqual(err, error); assert.strictEqual(transaction, null); assert.strictEqual(resp, RESPONSE); @@ -394,11 +394,11 @@ describe('Database', function() { }); }); - describe('createTable', function() { + describe('createTable', () => { const TABLE_NAME = 'table-name'; const SCHEMA = 'CREATE TABLE `' + TABLE_NAME + '`'; - it('should call updateSchema', function(done) { + it('should call updateSchema', done => { database.updateSchema = function(schema) { assert.strictEqual(schema, SCHEMA); done(); @@ -407,18 +407,18 @@ describe('Database', function() { database.createTable(SCHEMA, assert.ifError); }); - describe('error', function() { + describe('error', () => { const ERROR = new Error('Error.'); const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { database.updateSchema = function(name, callback) { callback(ERROR, null, API_RESPONSE); }; }); - it('should execute callback with error & API response', function(done) { - database.createTable(SCHEMA, function(err, table, op, apiResponse) { + it('should execute callback with error & API response', done => { + database.createTable(SCHEMA, (err, table, op, apiResponse) => { assert.strictEqual(err, ERROR); assert.strictEqual(table, null); assert.strictEqual(op, null); @@ -428,18 +428,18 @@ describe('Database', function() { }); }); - describe('success', function() { + describe('success', () => { const OPERATION = {}; const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { database.updateSchema = function(name, callback) { callback(null, OPERATION, API_RESPONSE); }; }); - describe('table name parsing', function() { - it('should recognize an escaped name', function(done) { + describe('table name parsing', () => { + it('should recognize an escaped name', done => { database.table = function(name) { assert.strictEqual(name, TABLE_NAME); done(); @@ -448,7 +448,7 @@ describe('Database', function() { database.createTable(SCHEMA, assert.ifError); }); - it('should recognize a non-escaped name', function(done) { + it('should recognize a non-escaped name', done => { database.table = function(name) { assert.strictEqual(name, TABLE_NAME); done(); @@ -458,7 +458,7 @@ describe('Database', function() { }); }); - it('should exec callback with Table, op & API response', function(done) { + it('should exec callback with Table, op & API response', done => { const tableInstance = {}; database.table = function(name) { @@ -466,7 +466,7 @@ describe('Database', function() { return tableInstance; }; - database.createTable(SCHEMA, function(err, table, op, apiResponse) { + database.createTable(SCHEMA, (err, table, op, apiResponse) => { assert.ifError(err); assert.strictEqual(table, tableInstance); assert.strictEqual(op, OPERATION); @@ -477,14 +477,14 @@ describe('Database', function() { }); }); - describe('decorateTransaction_', function() { - beforeEach(function() { + describe('decorateTransaction_', () => { + beforeEach(() => { database.pool_ = { release: util.noop, }; }); - it('should decorate the end() method', function(done) { + it('should decorate the end() method', done => { const transaction = {}; const end = function(callback) { assert.strictEqual(this, transaction); @@ -501,7 +501,7 @@ describe('Database', function() { decoratedTransaction.end(done); }); - it('should release the session back into the pool', function(done) { + it('should release the session back into the pool', done => { const SESSION = {}; const transaction = {end: util.noop}; @@ -518,14 +518,14 @@ describe('Database', function() { }); }); - describe('delete', function() { - beforeEach(function() { + describe('delete', () => { + beforeEach(() => { database.close = function(callback) { callback(); }; }); - it('should close the database', function(done) { + it('should close the database', done => { database.close = function() { done(); }; @@ -533,7 +533,7 @@ describe('Database', function() { database.delete(); }); - it('should make the correct request', function() { + it('should make the correct request', () => { database.request = function(config, callback) { assert.strictEqual(config.client, 'DatabaseAdminClient'); assert.strictEqual(config.method, 'dropDatabase'); @@ -547,41 +547,41 @@ describe('Database', function() { }); }); - describe('exists', function() { - it('should return any non-404 like errors', function(done) { + describe('exists', () => { + it('should return any non-404 like errors', done => { const error = {code: 3}; database.getMetadata = function(callback) { callback(error); }; - database.exists(function(err, exists) { + database.exists((err, exists) => { assert.strictEqual(err, error); assert.strictEqual(exists, null); done(); }); }); - it('should return true if error is absent', function(done) { + it('should return true if error is absent', done => { database.getMetadata = function(callback) { callback(null); }; - database.exists(function(err, exists) { + database.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, true); done(); }); }); - it('should return false if not found error if present', function(done) { + it('should return false if not found error if present', done => { const error = {code: 5}; database.getMetadata = function(callback) { callback(error); }; - database.exists(function(err, exists) { + database.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, false); done(); @@ -589,8 +589,8 @@ describe('Database', function() { }); }); - describe('get', function() { - it('should call getMetadata', function(done) { + describe('get', () => { + it('should call getMetadata', done => { const options = {}; database.getMetadata = function() { @@ -600,7 +600,7 @@ describe('Database', function() { database.get(options, assert.ifError); }); - it('should not require an options object', function(done) { + it('should not require an options object', done => { database.getMetadata = function() { done(); }; @@ -608,7 +608,7 @@ describe('Database', function() { database.get(assert.ifError); }); - describe('autoCreate', function() { + describe('autoCreate', () => { const error = new Error('Error.'); error.code = 5; @@ -624,7 +624,7 @@ describe('Database', function() { }, }; - beforeEach(function() { + beforeEach(() => { OPERATION.listeners = {}; database.getMetadata = function(callback) { @@ -636,7 +636,7 @@ describe('Database', function() { }; }); - it('should call create', function(done) { + it('should call create', done => { database.create = function(options) { assert.strictEqual(options, OPTIONS); done(); @@ -645,40 +645,40 @@ describe('Database', function() { database.get(OPTIONS, assert.ifError); }); - it('should return error if create failed', function(done) { + it('should return error if create failed', done => { const error = new Error('Error.'); database.create = function(options, callback) { callback(error); }; - database.get(OPTIONS, function(err) { + database.get(OPTIONS, err => { assert.strictEqual(err, error); done(); }); }); - it('should return operation error', function(done) { + it('should return operation error', done => { const error = new Error('Error.'); - setImmediate(function() { + setImmediate(() => { OPERATION.listeners['error'](error); }); - database.get(OPTIONS, function(err) { + database.get(OPTIONS, err => { assert.strictEqual(err, error); done(); }); }); - it('should execute callback if opereation succeeded', function(done) { + it('should execute callback if opereation succeeded', done => { const metadata = {}; - setImmediate(function() { + setImmediate(() => { OPERATION.listeners['complete'](metadata); }); - database.get(OPTIONS, function(err, database_, apiResponse) { + database.get(OPTIONS, (err, database_, apiResponse) => { assert.ifError(err); assert.strictEqual(database_, database); assert.strictEqual(database.metadata, metadata); @@ -688,7 +688,7 @@ describe('Database', function() { }); }); - it('should not auto create without error code 5', function(done) { + it('should not auto create without error code 5', done => { const error = new Error('Error.'); error.code = 'NOT-5'; @@ -704,13 +704,13 @@ describe('Database', function() { throw new Error('Should not create.'); }; - database.get(options, function(err) { + database.get(options, err => { assert.strictEqual(err, error); done(); }); }); - it('should not auto create unless requested', function(done) { + it('should not auto create unless requested', done => { const error = new Error('Error.'); error.code = 5; @@ -722,33 +722,33 @@ describe('Database', function() { throw new Error('Should not create.'); }; - database.get(function(err) { + database.get(err => { assert.strictEqual(err, error); done(); }); }); - it('should return an error from getMetadata', function(done) { + it('should return an error from getMetadata', done => { const error = new Error('Error.'); database.getMetadata = function(callback) { callback(error); }; - database.get(function(err) { + database.get(err => { assert.strictEqual(err, error); done(); }); }); - it('should return self and API response', function(done) { + it('should return self and API response', done => { const apiResponse = {}; database.getMetadata = function(callback) { callback(null, apiResponse); }; - database.get(function(err, database_, apiResponse_) { + database.get((err, database_, apiResponse_) => { assert.ifError(err); assert.strictEqual(database_, database); assert.strictEqual(apiResponse_, apiResponse); @@ -757,8 +757,8 @@ describe('Database', function() { }); }); - describe('getMetadata', function() { - it('should call and return the request', function() { + describe('getMetadata', () => { + it('should call and return the request', () => { const requestReturnValue = {}; database.request = function(config, callback) { @@ -776,8 +776,8 @@ describe('Database', function() { }); }); - describe('getSchema', function() { - it('should make the correct request', function(done) { + describe('getSchema', () => { + it('should make the correct request', done => { database.request = function(config) { assert.strictEqual(config.client, 'DatabaseAdminClient'); assert.strictEqual(config.method, 'getDatabaseDdl'); @@ -790,21 +790,21 @@ describe('Database', function() { database.getSchema(assert.ifError); }); - describe('error', function() { + describe('error', () => { const ARG_1 = {}; const STATEMENTS_ARG = null; const ARG_3 = {}; const ARG_4 = {}; const ARG_5 = {}; - beforeEach(function() { + beforeEach(() => { database.request = function(config, callback) { callback(ARG_1, STATEMENTS_ARG, ARG_3, ARG_4, ARG_5); }; }); - it('should return the arguments from the request', function(done) { - database.getSchema(function(arg1, arg2, arg3, arg4, arg5) { + it('should return the arguments from the request', done => { + database.getSchema((arg1, arg2, arg3, arg4, arg5) => { assert.strictEqual(arg1, ARG_1); assert.strictEqual(arg2, STATEMENTS_ARG); assert.strictEqual(arg3, ARG_3); @@ -815,7 +815,7 @@ describe('Database', function() { }); }); - describe('success', function() { + describe('success', () => { const ARG_1 = {}; const ARG_3 = {}; const ARG_4 = {}; @@ -825,14 +825,14 @@ describe('Database', function() { statements: {}, }; - beforeEach(function() { + beforeEach(() => { database.request = function(config, callback) { callback(ARG_1, STATEMENTS_ARG, ARG_3, ARG_4, ARG_5); }; }); - it('should return just the statements property', function(done) { - database.getSchema(function(arg1, statements, arg3, arg4, arg5) { + it('should return just the statements property', done => { + database.getSchema((arg1, statements, arg3, arg4, arg5) => { assert.strictEqual(arg1, ARG_1); assert.strictEqual(statements, STATEMENTS_ARG.statements); assert.strictEqual(arg3, ARG_3); @@ -844,7 +844,7 @@ describe('Database', function() { }); }); - describe('makePooledRequest_', function() { + describe('makePooledRequest_', () => { let CONFIG; const SESSION = { @@ -853,7 +853,7 @@ describe('Database', function() { const POOL = {}; - beforeEach(function() { + beforeEach(() => { CONFIG = { reqOpts: {}, }; @@ -867,7 +867,7 @@ describe('Database', function() { POOL.release = util.noop; }); - it('should get a session', function(done) { + it('should get a session', done => { POOL.getReadSession = function() { done(); }; @@ -875,20 +875,20 @@ describe('Database', function() { database.makePooledRequest_(CONFIG, assert.ifError); }); - it('should return error if it cannot get a session', function(done) { + it('should return error if it cannot get a session', done => { const error = new Error('Error.'); POOL.getReadSession = function(callback) { callback(error); }; - database.makePooledRequest_(CONFIG, function(err) { + database.makePooledRequest_(CONFIG, err => { assert.strictEqual(err, error); done(); }); }); - it('should call the method with the session', function(done) { + it('should call the method with the session', done => { CONFIG.reqOpts = { a: 'b', }; @@ -906,7 +906,7 @@ describe('Database', function() { database.makePooledRequest_(CONFIG, assert.ifError); }); - it('should release the session after calling the method', function(done) { + it('should release the session after calling the method', done => { POOL.release = function(session) { assert.deepStrictEqual(session, SESSION); done(); @@ -919,7 +919,7 @@ describe('Database', function() { database.makePooledRequest_(CONFIG, assert.ifError); }); - it('should execute the callback with original arguments', function(done) { + it('should execute the callback with original arguments', done => { const originalArgs = ['a', 'b', 'c']; database.request = function(config, callback) { @@ -934,7 +934,7 @@ describe('Database', function() { }); }); - describe('makePooledStreamingRequest_', function() { + describe('makePooledStreamingRequest_', () => { let CONFIG; let REQUEST_STREAM; @@ -944,7 +944,7 @@ describe('Database', function() { const POOL = {}; - beforeEach(function() { + beforeEach(() => { REQUEST_STREAM = through(); CONFIG = { @@ -964,7 +964,7 @@ describe('Database', function() { POOL.release = util.noop; }); - it('should get a session when stream opens', function(done) { + it('should get a session when stream opens', done => { POOL.getReadSession = function() { done(); }; @@ -972,19 +972,19 @@ describe('Database', function() { database.makePooledStreamingRequest_(CONFIG).emit('reading'); }); - describe('could not get session', function() { + describe('could not get session', () => { const ERROR = new Error('Error.'); - beforeEach(function() { + beforeEach(() => { POOL.getReadSession = function(callback) { callback(ERROR); }; }); - it('should destroy the stream', function(done) { + it('should destroy the stream', done => { database .makePooledStreamingRequest_(CONFIG) - .on('error', function(err) { + .on('error', err => { assert.strictEqual(err, ERROR); done(); }) @@ -992,14 +992,14 @@ describe('Database', function() { }); }); - describe('session retrieved successfully', function() { - beforeEach(function() { + describe('session retrieved successfully', () => { + beforeEach(() => { POOL.getReadSession = function(callback) { callback(null, SESSION); }; }); - it('should assign session to request options', function(done) { + it('should assign session to request options', done => { database.requestStream = function(config) { assert.strictEqual(config.reqOpts.session, SESSION.formattedName_); setImmediate(done); @@ -1009,10 +1009,10 @@ describe('Database', function() { database.makePooledStreamingRequest_(CONFIG).emit('reading'); }); - it('should make request and pipe to the stream', function(done) { + it('should make request and pipe to the stream', done => { const responseData = Buffer.from('response-data'); - database.makePooledStreamingRequest_(CONFIG).on('data', function(data) { + database.makePooledStreamingRequest_(CONFIG).on('data', data => { assert.deepStrictEqual(data, responseData); done(); }); @@ -1020,7 +1020,7 @@ describe('Database', function() { REQUEST_STREAM.end(responseData); }); - it('should release session when request stream ends', function(done) { + it('should release session when request stream ends', done => { POOL.release = function(session) { assert.strictEqual(session, SESSION); done(); @@ -1031,7 +1031,7 @@ describe('Database', function() { REQUEST_STREAM.end(); }); - it('should release session when request stream errors', function(done) { + it('should release session when request stream errors', done => { POOL.release = function(session) { assert.strictEqual(session, SESSION); done(); @@ -1039,32 +1039,32 @@ describe('Database', function() { database.makePooledStreamingRequest_(CONFIG).emit('reading'); - setImmediate(function() { + setImmediate(() => { REQUEST_STREAM.emit('error'); }); }); - it('should error user stream when request stream errors', function(done) { + it('should error user stream when request stream errors', done => { const error = new Error('Error.'); database .makePooledStreamingRequest_(CONFIG) - .on('error', function(err) { + .on('error', err => { assert.strictEqual(err, error); done(); }) .emit('reading'); - setImmediate(function() { + setImmediate(() => { REQUEST_STREAM.destroy(error); }); }); }); - describe('abort', function() { + describe('abort', () => { let SESSION; - beforeEach(function() { + beforeEach(() => { REQUEST_STREAM.cancel = util.noop; SESSION = { @@ -1076,7 +1076,7 @@ describe('Database', function() { }; }); - it('should release the session', function(done) { + it('should release the session', done => { POOL.release = function(session) { assert.strictEqual(session, SESSION); done(); @@ -1086,12 +1086,12 @@ describe('Database', function() { requestStream.emit('reading'); - setImmediate(function() { + setImmediate(() => { requestStream.abort(); }); }); - it('should not release the session more than once', function(done) { + it('should not release the session more than once', done => { let numTimesReleased = 0; POOL.release = function(session) { @@ -1103,7 +1103,7 @@ describe('Database', function() { requestStream.emit('reading'); - setImmediate(function() { + setImmediate(() => { requestStream.abort(); assert.strictEqual(numTimesReleased, 1); @@ -1114,21 +1114,21 @@ describe('Database', function() { }); }); - it('should cancel the request stream', function(done) { + it('should cancel the request stream', done => { REQUEST_STREAM.cancel = done; const requestStream = database.makePooledStreamingRequest_(CONFIG); requestStream.emit('reading'); - setImmediate(function() { + setImmediate(() => { requestStream.abort(); }); }); }); }); - describe('run', function() { + describe('run', () => { const QUERY = 'SELECT query FROM query'; let QUERY_STREAM; @@ -1137,7 +1137,7 @@ describe('Database', function() { const ROW_2 = {}; const ROW_3 = {}; - beforeEach(function() { + beforeEach(() => { QUERY_STREAM = through.obj(); QUERY_STREAM.push(ROW_1); QUERY_STREAM.push(ROW_2); @@ -1148,7 +1148,7 @@ describe('Database', function() { }; }); - it('should correctly call runStream', function(done) { + it('should correctly call runStream', done => { database.runStream = function(query, options) { assert.strictEqual(query, QUERY); assert.strictEqual(options, null); @@ -1159,7 +1159,7 @@ describe('Database', function() { database.run(QUERY, assert.ifError); }); - it('should optionally accept options', function(done) { + it('should optionally accept options', done => { const OPTIONS = {}; database.runStream = function(query, options) { @@ -1171,29 +1171,29 @@ describe('Database', function() { database.run(QUERY, OPTIONS, assert.ifError); }); - it('should return rows from the stream to the callback', function(done) { + it('should return rows from the stream to the callback', done => { QUERY_STREAM.end(); - database.run(QUERY, function(err, rows) { + database.run(QUERY, (err, rows) => { assert.ifError(err); assert.deepStrictEqual(rows, [ROW_1, ROW_2, ROW_3]); done(); }); }); - it('should execute callback with error from stream', function(done) { + it('should execute callback with error from stream', done => { const error = new Error('Error.'); QUERY_STREAM.destroy(error); - database.run(QUERY, function(err) { + database.run(QUERY, err => { assert.strictEqual(err, error); done(); }); }); }); - describe('runStream', function() { + describe('runStream', () => { const QUERY = { sql: 'SELECT * FROM table', a: 'b', @@ -1202,13 +1202,13 @@ describe('Database', function() { const ENCODED_QUERY = extend({}, QUERY); - beforeEach(function() { + beforeEach(() => { fakeCodec.encodeQuery = function() { return ENCODED_QUERY; }; }); - it('should accept a query object', function(done) { + it('should accept a query object', done => { fakeCodec.encodeQuery = function(query) { assert.strictEqual(query, QUERY); return ENCODED_QUERY; @@ -1226,7 +1226,7 @@ describe('Database', function() { makeRequestFn(); }); - it('should accept a query string', function(done) { + it('should accept a query string', done => { fakeCodec.encodeQuery = function(query) { assert.strictEqual(query.sql, QUERY.sql); return ENCODED_QUERY; @@ -1242,12 +1242,12 @@ describe('Database', function() { makeRequestFn(); }); - it('should return PartialResultStream', function() { + it('should return PartialResultStream', () => { const stream = database.runStream(QUERY); assert(stream instanceof FakePartialResultStream); }); - it('should pass json, jsonOptions to PartialResultStream', function() { + it('should pass json, jsonOptions to PartialResultStream', () => { const query = extend({}, QUERY); query.json = {}; query.jsonOptions = {}; @@ -1259,7 +1259,7 @@ describe('Database', function() { }); }); - it('should not pass json, jsonOptions to request', function(done) { + it('should not pass json, jsonOptions to request', done => { database.makePooledStreamingRequest_ = function(config) { assert.strictEqual(config.reqOpts.json, undefined); assert.strictEqual(config.reqOpts.jsonOptions, undefined); @@ -1275,7 +1275,7 @@ describe('Database', function() { makeRequestFn(); }); - it('should assign a resumeToken to the request', function(done) { + it('should assign a resumeToken to the request', done => { const resumeToken = 'resume-token'; database.makePooledStreamingRequest_ = function(config) { @@ -1288,7 +1288,7 @@ describe('Database', function() { makeRequestFn(resumeToken); }); - it('should add timestamp options', function(done) { + it('should add timestamp options', done => { const OPTIONS = {a: 'a'}; const FORMATTED_OPTIONS = {b: 'b'}; @@ -1312,8 +1312,8 @@ describe('Database', function() { }); }); - describe('runTransaction', function() { - it('should get a Transaction object', function(done) { + describe('runTransaction', () => { + it('should get a Transaction object', done => { database.getTransaction = function() { done(); }; @@ -1321,20 +1321,20 @@ describe('Database', function() { database.runTransaction(assert.ifError); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); database.getTransaction = function(options, callback) { callback(error); }; - database.runTransaction(function(err) { + database.runTransaction(err => { assert.strictEqual(err, error); done(); }); }); - it('should run the transaction', function(done) { + it('should run the transaction', done => { const TRANSACTION = {}; const OPTIONS = { a: 'a', @@ -1365,7 +1365,7 @@ describe('Database', function() { database.runTransaction(OPTIONS, runFn); }); - it('should capture the timeout', function(done) { + it('should capture the timeout', done => { const TRANSACTION = {}; const OPTIONS = { timeout: 1000, @@ -1375,7 +1375,7 @@ describe('Database', function() { callback(null, TRANSACTION); }; - database.runTransaction(OPTIONS, function(err, txn) { + database.runTransaction(OPTIONS, (err, txn) => { assert.ifError(err); assert.strictEqual(txn.timeout_, OPTIONS.timeout); done(); @@ -1383,16 +1383,16 @@ describe('Database', function() { }); }); - describe('table', function() { + describe('table', () => { const NAME = 'table-name'; - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { database.table(); }, /A name is required to access a Table object\./); }); - it('should return an instance of Tession', function() { + it('should return an instance of Tession', () => { const table = database.table(NAME); assert(table instanceof FakeTable); @@ -1401,10 +1401,10 @@ describe('Database', function() { }); }); - describe('updateSchema', function() { + describe('updateSchema', () => { const STATEMENTS = ['statement-1', 'statement-2']; - it('should call and return the request', function() { + it('should call and return the request', () => { const requestReturnValue = {}; database.request = function(config, callback) { @@ -1422,7 +1422,7 @@ describe('Database', function() { assert.strictEqual(returnValue, requestReturnValue); }); - it('should arrify a string statement', function(done) { + it('should arrify a string statement', done => { database.request = function(config) { assert.deepStrictEqual(config.reqOpts.statements, [STATEMENTS[0]]); done(); @@ -1431,7 +1431,7 @@ describe('Database', function() { database.updateSchema(STATEMENTS[0], assert.ifError); }); - it('should accept an object', function(done) { + it('should accept an object', done => { const config = { statements: STATEMENTS, otherConfiguration: {}, @@ -1450,10 +1450,10 @@ describe('Database', function() { }); }); - describe('createSession', function() { + describe('createSession', () => { const OPTIONS = {}; - it('should make the correct request', function(done) { + it('should make the correct request', done => { database.request = function(config) { assert.strictEqual(config.client, 'SpannerClient'); assert.strictEqual(config.method, 'createSession'); @@ -1469,7 +1469,7 @@ describe('Database', function() { database.createSession(OPTIONS, assert.ifError); }); - it('should not require options', function(done) { + it('should not require options', done => { database.request = function(config) { assert.deepStrictEqual(config.reqOpts, { database: database.formattedName_, @@ -1483,18 +1483,18 @@ describe('Database', function() { database.createSession(assert.ifError); }); - describe('error', function() { + describe('error', () => { const ERROR = new Error('Error.'); const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { database.request = function(config, callback) { callback(ERROR, API_RESPONSE); }; }); - it('should execute callback with error & API response', function(done) { - database.createSession(function(err, session, apiResponse) { + it('should execute callback with error & API response', done => { + database.createSession((err, session, apiResponse) => { assert.strictEqual(err, ERROR); assert.strictEqual(session, null); assert.strictEqual(apiResponse, API_RESPONSE); @@ -1503,18 +1503,18 @@ describe('Database', function() { }); }); - describe('success', function() { + describe('success', () => { const API_RESPONSE = { name: 'session-name', }; - beforeEach(function() { + beforeEach(() => { database.request = function(config, callback) { callback(null, API_RESPONSE); }; }); - it('should execute callback with session & API response', function(done) { + it('should execute callback with session & API response', done => { const sessionInstance = {}; database.session = function(name) { @@ -1522,7 +1522,7 @@ describe('Database', function() { return sessionInstance; }; - database.createSession(function(err, session, apiResponse) { + database.createSession((err, session, apiResponse) => { assert.ifError(err); assert.strictEqual(session, sessionInstance); @@ -1536,11 +1536,11 @@ describe('Database', function() { }); }); - describe('getTransaction', function() { + describe('getTransaction', () => { let SESSION; let TRANSACTION; - beforeEach(function() { + beforeEach(() => { TRANSACTION = {}; SESSION = { @@ -1560,16 +1560,16 @@ describe('Database', function() { }; }); - describe('write mode', function() { - it('should get a session from the pool', function(done) { - database.getTransaction(function(err, transaction) { + describe('write mode', () => { + it('should get a session from the pool', done => { + database.getTransaction((err, transaction) => { assert.ifError(err); assert.strictEqual(transaction, TRANSACTION); done(); }); }); - it('should decorate the transaction', function(done) { + it('should decorate the transaction', done => { const DECORATED_TRANSACTION = {}; database.decorateTransaction_ = function(transaction, session) { @@ -1578,14 +1578,14 @@ describe('Database', function() { return DECORATED_TRANSACTION; }; - database.getTransaction(function(err, transaction) { + database.getTransaction((err, transaction) => { assert.ifError(err); assert.strictEqual(transaction, DECORATED_TRANSACTION); done(); }); }); - it('should return errors to the callback', function(done) { + it('should return errors to the callback', done => { const error = new Error('Error.'); database.pool_ = { @@ -1594,20 +1594,20 @@ describe('Database', function() { }, }; - database.getTransaction(function(err) { + database.getTransaction(err => { assert.strictEqual(err, error); done(); }); }); }); - describe('readOnly mode', function() { + describe('readOnly mode', () => { const OPTIONS = { readOnly: true, a: 'a', }; - beforeEach(function() { + beforeEach(() => { database.pool_ = { getReadSession: function(callback) { callback(null, SESSION); @@ -1616,7 +1616,7 @@ describe('Database', function() { }; }); - it('should get a session from the pool', function(done) { + it('should get a session from the pool', done => { database.pool_.getReadSession = function() { done(); }; @@ -1624,20 +1624,20 @@ describe('Database', function() { database.getTransaction(OPTIONS, assert.ifError); }); - it('should return an error if could not get session', function(done) { + it('should return an error if could not get session', done => { const error = new Error('err.'); database.pool_.getReadSession = function(callback) { callback(error); }; - database.getTransaction(OPTIONS, function(err) { + database.getTransaction(OPTIONS, err => { assert.strictEqual(err, error); done(); }); }); - it('should should create a transaction', function(done) { + it('should should create a transaction', done => { SESSION.beginTransaction = function(options) { assert.strictEqual(options, OPTIONS); done(); @@ -1646,7 +1646,7 @@ describe('Database', function() { database.getTransaction(OPTIONS, assert.ifError); }); - it('should decorate the transaction', function(done) { + it('should decorate the transaction', done => { const DECORATED_TRANSACTION = {}; database.decorateTransaction_ = function(transaction, session) { @@ -1655,21 +1655,21 @@ describe('Database', function() { return DECORATED_TRANSACTION; }; - database.getTransaction(OPTIONS, function(err, transaction) { + database.getTransaction(OPTIONS, (err, transaction) => { assert.ifError(err); assert.strictEqual(transaction, DECORATED_TRANSACTION); done(); }); }); - it('should return an error if transaction cannot begin', function(done) { + it('should return an error if transaction cannot begin', done => { const error = new Error('err'); SESSION.beginTransaction = function(options, callback) { callback(error); }; - database.getTransaction(OPTIONS, function(err) { + database.getTransaction(OPTIONS, err => { assert.strictEqual(err, error); done(); }); @@ -1677,8 +1677,8 @@ describe('Database', function() { }); }); - describe('getSessions', function() { - it('should make the correct request', function(done) { + describe('getSessions', () => { + it('should make the correct request', done => { const gaxOpts = {}; const options = {a: 'a', gaxOptions: gaxOpts}; @@ -1699,7 +1699,7 @@ describe('Database', function() { database.getSessions(options, assert.ifError); }); - it('should not require a query', function(done) { + it('should not require a query', done => { database.request = function(config) { assert.deepStrictEqual(config.reqOpts, { database: database.formattedName_, @@ -1711,7 +1711,7 @@ describe('Database', function() { database.getSessions(assert.ifError); }); - it('should return all arguments on error', function(done) { + it('should return all arguments on error', done => { const ARGS = [new Error('err'), null, {}]; database.request = function(config, callback) { @@ -1725,7 +1725,7 @@ describe('Database', function() { }); }); - it('should create and return Session objects', function(done) { + it('should create and return Session objects', done => { const SESSIONS = [{name: 'abc'}]; const SESSION_INSTANCE = {}; const RESPONSE = {}; @@ -1739,7 +1739,7 @@ describe('Database', function() { return SESSION_INSTANCE; }; - database.getSessions(function(err, sessions, resp) { + database.getSessions((err, sessions, resp) => { assert.ifError(err); assert.strictEqual(sessions[0], SESSION_INSTANCE); assert.strictEqual(resp, RESPONSE); @@ -1748,10 +1748,10 @@ describe('Database', function() { }); }); - describe('session', function() { + describe('session', () => { const NAME = 'session-name'; - it('should return an instance of Session', function() { + it('should return an instance of Session', () => { const session = database.session(NAME); assert(session instanceof FakeSession); diff --git a/test/gapic-v1-database-admin.js b/test/gapic-v1-database-admin.js index 6d7a063e6..1e139f281 100644 --- a/test/gapic-v1-database-admin.js +++ b/test/gapic-v1-database-admin.js @@ -90,7 +90,7 @@ describe('DatabaseAdminClient', () => { }); }); - describe('createDatabase', function() { + describe('createDatabase', () => { it('invokes createDatabase without error', done => { const client = new spannerModule.v1.DatabaseAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, @@ -253,7 +253,7 @@ describe('DatabaseAdminClient', () => { }); }); - describe('updateDatabaseDdl', function() { + describe('updateDatabaseDdl', () => { it('invokes updateDatabaseDdl without error', done => { const client = new spannerModule.v1.DatabaseAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, diff --git a/test/gapic-v1-instance-admin.js b/test/gapic-v1-instance-admin.js index 81b28bc21..6cf096d0f 100644 --- a/test/gapic-v1-instance-admin.js +++ b/test/gapic-v1-instance-admin.js @@ -291,7 +291,7 @@ describe('InstanceAdminClient', () => { }); }); - describe('createInstance', function() { + describe('createInstance', () => { it('invokes createInstance without error', done => { const client = new spannerModule.v1.InstanceAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, @@ -396,7 +396,7 @@ describe('InstanceAdminClient', () => { }); }); - describe('updateInstance', function() { + describe('updateInstance', () => { it('invokes updateInstance without error', done => { const client = new spannerModule.v1.InstanceAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, diff --git a/test/gapic-v1.js b/test/gapic-v1.js index 81b28bc21..6cf096d0f 100644 --- a/test/gapic-v1.js +++ b/test/gapic-v1.js @@ -291,7 +291,7 @@ describe('InstanceAdminClient', () => { }); }); - describe('createInstance', function() { + describe('createInstance', () => { it('invokes createInstance without error', done => { const client = new spannerModule.v1.InstanceAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, @@ -396,7 +396,7 @@ describe('InstanceAdminClient', () => { }); }); - describe('updateInstance', function() { + describe('updateInstance', () => { it('invokes updateInstance without error', done => { const client = new spannerModule.v1.InstanceAdminClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, diff --git a/test/index.js b/test/index.js index 5c5599e78..f8d691342 100644 --- a/test/index.js +++ b/test/index.js @@ -90,7 +90,7 @@ function FakeInstance() { this.calledWith_ = arguments; } -describe('Spanner', function() { +describe('Spanner', () => { let Spanner; let spanner; @@ -98,7 +98,7 @@ describe('Spanner', function() { projectId: 'project-id', }; - before(function() { + before(() => { Spanner = proxyquire('../src/index.js', { '@google-cloud/common-grpc': { Operation: FakeGrpcOperation, @@ -118,7 +118,7 @@ describe('Spanner', function() { }).Spanner; }); - beforeEach(function() { + beforeEach(() => { fakeGapicClient = util.noop; fakeGapicClient.scopes = []; fakeV1.DatabaseAdminClient = fakeGapicClient; @@ -131,26 +131,26 @@ describe('Spanner', function() { replaceProjectIdTokenOverride = null; }); - describe('instantiation', function() { - it('should localize a cached gapic client map', function() { + describe('instantiation', () => { + it('should localize a cached gapic client map', () => { assert(spanner.clients_ instanceof Map); assert.strictEqual(spanner.clients_.size, 0); }); - it('should localize an instance map', function() { + it('should localize an instance map', () => { assert(spanner.instances_ instanceof Map); assert.strictEqual(spanner.instances_.size, 0); }); - it('should promisify all the things', function() { + it('should promisify all the things', () => { assert(promisified); }); - it('should streamify the correct methods', function() { + it('should streamify the correct methods', () => { assert.strictEqual(spanner.getInstancesStream, 'getInstances'); }); - it('should create an auth instance from google-auth-library', function() { + it('should create an auth instance from google-auth-library', () => { const expectedOptions = extend({}, OPTIONS, { libName: 'gccl', libVersion: require('../package.json').version, @@ -160,7 +160,7 @@ describe('Spanner', function() { assert.deepStrictEqual(spanner.auth.calledWith_[0], expectedOptions); }); - it('should combine and uniquify all gapic client scopes', function() { + it('should combine and uniquify all gapic client scopes', () => { const expectedScopes = ['a', 'b', 'c']; fakeV1.DatabaseAdminClient.scopes = ['a', 'c']; fakeV1.InstanceAdminClient.scopes = ['a', 'b']; @@ -177,7 +177,7 @@ describe('Spanner', function() { assert.deepStrictEqual(spanner.auth.calledWith_[0], expectedOptions); }); - it('should inherit from GrpcService', function() { + it('should inherit from GrpcService', () => { assert(spanner instanceof FakeGrpcService); const config = spanner.calledWith_[0]; @@ -206,7 +206,7 @@ describe('Spanner', function() { ); }); - it('should optionally accept a servicePath', function() { + it('should optionally accept a servicePath', () => { const SERVICE_PATH = 'abc.def.ghi'; const spanner = new Spanner({servicePath: SERVICE_PATH}); @@ -216,8 +216,8 @@ describe('Spanner', function() { }); }); - describe('date', function() { - it('should create a SpannerDate instance', function() { + describe('date', () => { + it('should create a SpannerDate instance', () => { const value = {}; const customValue = {}; @@ -231,8 +231,8 @@ describe('Spanner', function() { }); }); - describe('float', function() { - it('should create a SpannerDate instance', function() { + describe('float', () => { + it('should create a SpannerDate instance', () => { const value = {}; const customValue = {}; @@ -246,8 +246,8 @@ describe('Spanner', function() { }); }); - describe('int', function() { - it('should create an Int instance', function() { + describe('int', () => { + it('should create an Int instance', () => { const value = {}; const customValue = {}; @@ -261,8 +261,8 @@ describe('Spanner', function() { }); }); - describe('struct', function() { - it('should create a struct from JSON', function() { + describe('struct', () => { + it('should create a struct from JSON', () => { const json = {}; const fakeStruct = []; @@ -278,7 +278,7 @@ describe('Spanner', function() { assert.strictEqual(struct, fakeStruct); }); - it('should create a struct from an Array', function() { + it('should create a struct from an Array', () => { const arr = []; const fakeStruct = []; @@ -295,7 +295,7 @@ describe('Spanner', function() { }); }); - describe('createInstance', function() { + describe('createInstance', () => { const NAME = 'instance-name'; let PATH; @@ -306,34 +306,34 @@ describe('Spanner', function() { let formatName_; - before(function() { + before(() => { formatName_ = FakeInstance.formatName_; }); - after(function() { + after(() => { FakeInstance.formatName_ = formatName_; }); - beforeEach(function() { + beforeEach(() => { FakeInstance.formatName_ = formatName_; PATH = 'projects/' + spanner.projectId + '/instances/' + NAME; spanner.request = util.noop; }); - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { spanner.createInstance(); }, /A name is required to create an instance\./); }); - it('should throw if a config object is not provided', function() { - assert.throws(function() { + it('should throw if a config object is not provided', () => { + assert.throws(() => { spanner.createInstance(NAME); }, /A configuration object is required to create an instance\./); }); - it('should set the correct defaults on the request', function(done) { + it('should set the correct defaults on the request', done => { FakeInstance.formatName_ = function(projectId, name) { assert.strictEqual(projectId, spanner.projectId); assert.strictEqual(name, NAME); @@ -365,7 +365,7 @@ describe('Spanner', function() { spanner.createInstance(NAME, CONFIG, assert.ifError); }); - it('should accept a path', function(done) { + it('should accept a path', done => { FakeInstance.formatName_ = function(projectId, name) { assert.strictEqual(name, PATH); setImmediate(done); @@ -375,8 +375,8 @@ describe('Spanner', function() { spanner.createInstance(PATH, CONFIG, assert.ifError); }); - describe('config.nodes', function() { - it('should rename to nodeCount', function(done) { + describe('config.nodes', () => { + it('should rename to nodeCount', done => { const config = extend({}, CONFIG, {nodes: 10}); spanner.request = function(config_) { @@ -390,8 +390,8 @@ describe('Spanner', function() { }); }); - describe('config.config', function() { - it('should format a name', function(done) { + describe('config.config', () => { + it('should format a name', done => { const name = 'config-name'; const config = extend({}, CONFIG, {config: name}); const originalConfig = extend({}, config); @@ -412,18 +412,18 @@ describe('Spanner', function() { }); }); - describe('error', function() { + describe('error', () => { const ERROR = new Error('Error.'); const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { spanner.request = function(config, callback) { callback(ERROR, null, API_RESPONSE); }; }); - it('should execute callback with error & API response', function(done) { - spanner.createInstance(NAME, CONFIG, function(err, instance, op, resp) { + it('should execute callback with error & API response', done => { + spanner.createInstance(NAME, CONFIG, (err, instance, op, resp) => { assert.strictEqual(err, ERROR); assert.strictEqual(instance, null); assert.strictEqual(op, null); @@ -433,17 +433,17 @@ describe('Spanner', function() { }); }); - describe('success', function() { + describe('success', () => { const OPERATION = {}; const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { spanner.request = function(config, callback) { callback(null, OPERATION, API_RESPONSE); }; }); - it('should create an Instance and return an Operation', function(done) { + it('should create an Instance and return an Operation', done => { const formattedName = 'formatted-name'; FakeInstance.formatName_ = function() { return formattedName; @@ -455,7 +455,7 @@ describe('Spanner', function() { return fakeInstanceInstance; }; - spanner.createInstance(NAME, CONFIG, function(err, instance, op, resp) { + spanner.createInstance(NAME, CONFIG, (err, instance, op, resp) => { assert.ifError(err); assert.strictEqual(instance, fakeInstanceInstance); assert.strictEqual(op, OPERATION); @@ -466,17 +466,17 @@ describe('Spanner', function() { }); }); - describe('getInstances', function() { + describe('getInstances', () => { const QUERY = { a: 'b', }; const ORIGINAL_QUERY = extend({}, QUERY); - beforeEach(function() { + beforeEach(() => { spanner.request = util.noop; }); - it('should make the correct request', function(done) { + it('should make the correct request', done => { const expectedReqOpts = extend({}, QUERY, { parent: 'projects/' + spanner.projectId, }); @@ -497,7 +497,7 @@ describe('Spanner', function() { spanner.getInstances(QUERY, assert.ifError); }); - it('should not require a query', function(done) { + it('should not require a query', done => { spanner.request = function(config) { assert.deepStrictEqual(config.reqOpts, { parent: 'projects/' + spanner.projectId, @@ -511,16 +511,16 @@ describe('Spanner', function() { spanner.getInstances(assert.ifError); }); - describe('error', function() { + describe('error', () => { const GAX_RESPONSE_ARGS = [new Error('Error.'), null, {}]; - beforeEach(function() { + beforeEach(() => { spanner.request = function(config, callback) { callback.apply(null, GAX_RESPONSE_ARGS); }; }); - it('should execute callback with original arguments', function(done) { + it('should execute callback with original arguments', done => { spanner.getInstances(QUERY, function() { assert.deepStrictEqual([].slice.call(arguments), GAX_RESPONSE_ARGS); done(); @@ -528,7 +528,7 @@ describe('Spanner', function() { }); }); - describe('success', function() { + describe('success', () => { const INSTANCES = [ { name: 'instance-name', @@ -537,13 +537,13 @@ describe('Spanner', function() { const GAX_RESPONSE_ARGS = [null, INSTANCES, {}]; - beforeEach(function() { + beforeEach(() => { spanner.request = function(config, callback) { callback.apply(null, GAX_RESPONSE_ARGS); }; }); - it('should create and return Instance objects', function(done) { + it('should create and return Instance objects', done => { const fakeInstanceInstance = {}; spanner.instance = function(name) { @@ -568,12 +568,12 @@ describe('Spanner', function() { }); }); - describe('getInstanceConfigs', function() { - beforeEach(function() { + describe('getInstanceConfigs', () => { + beforeEach(() => { spanner.request = util.noop; }); - it('should make and return the correct request', function() { + it('should make and return the correct request', () => { const query = {a: 'b'}; const expectedQuery = extend({}, query, { parent: 'projects/' + spanner.projectId, @@ -603,7 +603,7 @@ describe('Spanner', function() { assert.strictEqual(returnedValue, returnValue); }); - it('should not require a query', function(done) { + it('should not require a query', done => { spanner.request = function(config) { const reqOpts = config.reqOpts; assert.deepStrictEqual(reqOpts, { @@ -616,12 +616,12 @@ describe('Spanner', function() { }); }); - describe('getInstanceConfigsStream', function() { - beforeEach(function() { + describe('getInstanceConfigsStream', () => { + beforeEach(() => { spanner.requestStream = util.noop; }); - it('should make and return the correct gax API call', function() { + it('should make and return the correct gax API call', () => { const query = {a: 'b'}; const expectedQuery = extend({}, query, { parent: 'projects/' + spanner.projectId, @@ -647,16 +647,16 @@ describe('Spanner', function() { }); }); - describe('instance', function() { + describe('instance', () => { const NAME = 'instance-name'; - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { spanner.instance(); }, /A name is required to access an Instance object\./); }); - it('should create and cache an Instance', function() { + it('should create and cache an Instance', () => { const cache = spanner.instances_; assert.strictEqual(cache.has(NAME), false); @@ -669,7 +669,7 @@ describe('Spanner', function() { assert.strictEqual(instance, cache.get(NAME)); }); - it('should re-use cached objects', function() { + it('should re-use cached objects', () => { const cache = spanner.instances_; const fakeInstance = {}; @@ -681,16 +681,16 @@ describe('Spanner', function() { }); }); - describe('operation', function() { + describe('operation', () => { const NAME = 'op-name'; - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { spanner.operation(); }, /A name is required to access an Operation object\./); }); - it('should return an Operation object', function() { + it('should return an Operation object', () => { const operation = spanner.operation(NAME); assert(operation instanceof FakeGrpcOperation); assert.strictEqual(operation.calledWith_[0], spanner); @@ -698,7 +698,7 @@ describe('Spanner', function() { }); }); - describe('prepareGapicRequest_', function() { + describe('prepareGapicRequest_', () => { const PROJECT_ID = 'project-id'; const CONFIG = { client: 'SpannerClient', @@ -714,7 +714,7 @@ describe('Spanner', function() { [CONFIG.method]: util.noop, }; - beforeEach(function() { + beforeEach(() => { FAKE_GAPIC_CLIENT[CONFIG.method] = util.noop; spanner.auth.getProjectId = function(callback) { @@ -726,7 +726,7 @@ describe('Spanner', function() { }; }); - it('should get the project ID from google-auth-library', function(done) { + it('should get the project ID from google-auth-library', done => { spanner.auth.getProjectId = function() { done(); }; @@ -734,24 +734,24 @@ describe('Spanner', function() { spanner.prepareGapicRequest_(CONFIG, assert.ifError); }); - it('should return an error from google-auth-library', function(done) { + it('should return an error from google-auth-library', done => { const error = new Error('Error.'); spanner.auth.getProjectId = function(callback) { callback(error); }; - spanner.prepareGapicRequest_(CONFIG, function(err) { + spanner.prepareGapicRequest_(CONFIG, err => { assert.strictEqual(err, error); done(); }); }); - it('should create and cache a gapic client', function(done) { + it('should create and cache a gapic client', done => { fakeV1[CONFIG.client] = function(options) { assert.strictEqual(options, spanner.options); - setImmediate(function() { + setImmediate(() => { const cachedClient = spanner.clients_.get(CONFIG.client); assert.strictEqual(cachedClient, FAKE_GAPIC_CLIENT); done(); @@ -763,7 +763,7 @@ describe('Spanner', function() { spanner.prepareGapicRequest_(CONFIG, assert.ifError); }); - it('should re-use a cached gapic client', function() { + it('should re-use a cached gapic client', () => { fakeV1[CONFIG.client] = function() { throw new Error('Should not have re-created client!'); }; @@ -773,7 +773,7 @@ describe('Spanner', function() { spanner.prepareGapicRequest_(CONFIG, assert.ifError); }); - it('should replace project ID tokens within the reqOpts', function(done) { + it('should replace project ID tokens within the reqOpts', done => { const replacedReqOpts = {}; replaceProjectIdTokenOverride = function(reqOpts, projectId) { @@ -790,12 +790,12 @@ describe('Spanner', function() { done(); }; - spanner.prepareGapicRequest_(CONFIG, function(err, requestFn) { + spanner.prepareGapicRequest_(CONFIG, (err, requestFn) => { requestFn(); // (FAKE_GAPIC_CLIENT[CONFIG.method]) }); }); - it('should return the gax client method with correct args', function(done) { + it('should return the gax client method with correct args', done => { replaceProjectIdTokenOverride = function(reqOpts) { return reqOpts; }; @@ -811,27 +811,27 @@ describe('Spanner', function() { arg(); // done() }; - spanner.prepareGapicRequest_(CONFIG, function(err, requestFn) { + spanner.prepareGapicRequest_(CONFIG, (err, requestFn) => { requestFn(done); // (FAKE_GAPIC_CLIENT[CONFIG.method]) }); }); }); - describe('request', function() { + describe('request', () => { const CONFIG = {}; - beforeEach(function() { + beforeEach(() => { spanner.prepareGapicRequest_ = util.noop; spanner.Promise = Promise; }); - describe('callback mode', function() { - it('should not return a promise', function() { + describe('callback mode', () => { + it('should not return a promise', () => { const returnedValue = spanner.request(CONFIG, assert.ifError); assert.strictEqual(returnedValue, undefined); }); - it('should prepare the gapic request', function(done) { + it('should prepare the gapic request', done => { spanner.prepareGapicRequest_ = function(config) { assert.strictEqual(config, CONFIG); done(); @@ -840,20 +840,20 @@ describe('Spanner', function() { spanner.request(CONFIG, assert.ifError); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); spanner.prepareGapicRequest_ = function(config, callback) { callback(error); }; - spanner.request(CONFIG, function(err) { + spanner.request(CONFIG, err => { assert.strictEqual(err, error); done(); }); }); - it('should pass callback to request function', function(done) { + it('should pass callback to request function', done => { function gapicRequestFn(callback) { callback(); // done() } @@ -866,13 +866,13 @@ describe('Spanner', function() { }); }); - describe('promise mode', function() { - it('should return a promise', function() { + describe('promise mode', () => { + it('should return a promise', () => { const returnedValue = spanner.request(CONFIG); assert(returnedValue instanceof Promise); }); - it('should prepare the gapic request', function(done) { + it('should prepare the gapic request', done => { spanner.prepareGapicRequest_ = function(config) { assert.strictEqual(config, CONFIG); done(); @@ -881,20 +881,20 @@ describe('Spanner', function() { spanner.request(CONFIG); }); - it('should reject the promise', function(done) { + it('should reject the promise', done => { const error = new Error('Error.'); spanner.prepareGapicRequest_ = function(config, callback) { callback(error); }; - spanner.request(CONFIG).catch(function(err) { + spanner.request(CONFIG).catch(err => { assert.strictEqual(err, error); done(); }); }); - it('should resolve the promise with the request fn', function() { + it('should resolve the promise with the request fn', () => { const gapicRequestFnResult = {}; function gapicRequestFn() { @@ -905,21 +905,21 @@ describe('Spanner', function() { callback(null, gapicRequestFn); }; - return spanner.request(CONFIG).then(function(result) { + return spanner.request(CONFIG).then(result => { assert.strictEqual(result, gapicRequestFnResult); }); }); }); }); - describe('requestStream', function() { + describe('requestStream', () => { const CONFIG = {}; - beforeEach(function() { + beforeEach(() => { spanner.prepareGapicRequest_ = util.noop; }); - it('should prepare the gapic request', function(done) { + it('should prepare the gapic request', done => { spanner.prepareGapicRequest_ = function(config) { assert.strictEqual(config, CONFIG); done(); @@ -928,7 +928,7 @@ describe('Spanner', function() { spanner.requestStream(CONFIG).emit('reading'); }); - it('should destroy the stream with an error', function(done) { + it('should destroy the stream with an error', done => { const error = new Error('Error.'); spanner.prepareGapicRequest_ = function(config, callback) { @@ -937,20 +937,20 @@ describe('Spanner', function() { spanner .requestStream(CONFIG) - .on('error', function(err) { + .on('error', err => { assert.strictEqual(err, error); done(); }) .emit('reading'); }); - it('should pipe the request stream to the user stream', function(done) { + it('should pipe the request stream to the user stream', done => { const requestStream = through.obj(); const data = {}; spanner.prepareGapicRequest_ = function(config, callback) { - callback(null, function() { - setImmediate(function() { + callback(null, () => { + setImmediate(() => { requestStream.end(data); }); @@ -960,20 +960,20 @@ describe('Spanner', function() { spanner .requestStream(CONFIG) - .on('data', function(data_) { + .on('data', data_ => { assert.strictEqual(data_, data); done(); }) .emit('reading'); }); - it('should pass errors from the request stream', function(done) { + it('should pass errors from the request stream', done => { const requestStream = through.obj(); const error = new Error('Error.'); spanner.prepareGapicRequest_ = function(config, callback) { - callback(null, function() { - setImmediate(function() { + callback(null, () => { + setImmediate(() => { requestStream.destroy(error); }); @@ -983,7 +983,7 @@ describe('Spanner', function() { spanner .requestStream(CONFIG) - .on('error', function(err) { + .on('error', err => { assert.strictEqual(err, error); done(); }) diff --git a/test/instance.js b/test/instance.js index 4d50f05a7..b251baf3c 100644 --- a/test/instance.js +++ b/test/instance.js @@ -49,7 +49,7 @@ function FakeGrpcServiceObject() { this.calledWith_ = arguments; } -describe('Instance', function() { +describe('Instance', () => { let Instance; let instance; @@ -62,7 +62,7 @@ describe('Instance', function() { const NAME = 'instance-name'; - before(function() { + before(() => { Instance = proxyquire('../src/instance.js', { '@google-cloud/common-grpc': { ServiceObject: FakeGrpcServiceObject, @@ -73,20 +73,20 @@ describe('Instance', function() { }); }); - beforeEach(function() { + beforeEach(() => { instance = new Instance(SPANNER, NAME); }); - describe('instantiation', function() { - it('should localize an database map', function() { + describe('instantiation', () => { + it('should localize an database map', () => { assert(instance.databases_ instanceof Map); }); - it('should promisify all the things', function() { + it('should promisify all the things', () => { assert(promisified); }); - it('should format the name', function() { + it('should format the name', () => { const formatName_ = Instance.formatName_; const formattedName = 'formatted-name'; @@ -103,7 +103,7 @@ describe('Instance', function() { assert(instance.formattedName_, formattedName); }); - it('should localize the request function', function(done) { + it('should localize the request function', done => { const spannerInstance = extend({}, SPANNER); spannerInstance.request = function() { @@ -115,7 +115,7 @@ describe('Instance', function() { instance.request(); }); - it('should localize the requestStream function', function(done) { + it('should localize the requestStream function', done => { const spannerInstance = extend({}, SPANNER); spannerInstance.requestStream = function() { @@ -127,7 +127,7 @@ describe('Instance', function() { instance.requestStream(); }); - it('should inherit from ServiceObject', function(done) { + it('should inherit from ServiceObject', done => { const options = {}; const spannerInstance = extend({}, SPANNER, { createInstance: function(name, options_, callback) { @@ -150,20 +150,20 @@ describe('Instance', function() { }); }); - describe('formatName_', function() { + describe('formatName_', () => { const PATH = 'projects/' + SPANNER.projectId + '/instances/' + NAME; - it('should return the name if already formatted', function() { + it('should return the name if already formatted', () => { assert.strictEqual(Instance.formatName_(SPANNER.projectId, PATH), PATH); }); - it('should format the name', function() { + it('should format the name', () => { const formattedName = Instance.formatName_(SPANNER.projectId, NAME); assert.strictEqual(formattedName, PATH); }); }); - describe('createDatabase', function() { + describe('createDatabase', () => { const NAME = 'database-name'; const PATH = 'projects/project-id/databases/' + NAME; @@ -172,13 +172,13 @@ describe('Instance', function() { }; const ORIGINAL_OPTIONS = extend({}, OPTIONS); - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { instance.createDatabase(); }, /A name is required to create a database\./); }); - it('should make the correct default request', function(done) { + it('should make the correct default request', done => { instance.request = function(config) { assert.strictEqual(config.client, 'DatabaseAdminClient'); assert.strictEqual(config.method, 'createDatabase'); @@ -193,7 +193,7 @@ describe('Instance', function() { instance.createDatabase(NAME, assert.ifError); }); - it('should accept options', function(done) { + it('should accept options', done => { instance.request = function(config) { assert.deepStrictEqual(OPTIONS, ORIGINAL_OPTIONS); @@ -213,7 +213,7 @@ describe('Instance', function() { instance.createDatabase(NAME, OPTIONS, assert.ifError); }); - it('should only use the name in the createStatement', function(done) { + it('should only use the name in the createStatement', done => { instance.request = function(config) { const expectedReqOpts = extend( { @@ -231,8 +231,8 @@ describe('Instance', function() { instance.createDatabase(PATH, OPTIONS, assert.ifError); }); - describe('options.poolOptions', function() { - it('should allow specifying session pool options', function(done) { + describe('options.poolOptions', () => { + it('should allow specifying session pool options', done => { const poolOptions = {}; const options = extend({}, OPTIONS, { @@ -253,8 +253,8 @@ describe('Instance', function() { }); }); - describe('options.schema', function() { - it('should arrify and rename to extraStatements', function(done) { + describe('options.schema', () => { + it('should arrify and rename to extraStatements', done => { const SCHEMA = 'schema'; const options = extend({}, OPTIONS, { @@ -271,18 +271,18 @@ describe('Instance', function() { }); }); - describe('error', function() { + describe('error', () => { const ERROR = new Error('Error.'); const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { instance.request = function(config, callback) { callback(ERROR, null, API_RESPONSE); }; }); - it('should execute callback with error & API response', function(done) { - instance.createDatabase(NAME, OPTIONS, function(err, db, op, resp) { + it('should execute callback with error & API response', done => { + instance.createDatabase(NAME, OPTIONS, (err, db, op, resp) => { assert.strictEqual(err, ERROR); assert.strictEqual(op, null); assert.strictEqual(resp, API_RESPONSE); @@ -291,17 +291,17 @@ describe('Instance', function() { }); }); - describe('success', function() { + describe('success', () => { const OPERATION = {}; const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { instance.request = function(config, callback) { callback(null, OPERATION, API_RESPONSE); }; }); - it('should exec callback with a Database and Operation', function(done) { + it('should exec callback with a Database and Operation', done => { const fakeDatabaseInstance = {}; instance.database = function(name) { @@ -309,7 +309,7 @@ describe('Instance', function() { return fakeDatabaseInstance; }; - instance.createDatabase(NAME, OPTIONS, function(err, db, op, resp) { + instance.createDatabase(NAME, OPTIONS, (err, db, op, resp) => { assert.ifError(err); assert.strictEqual(db, fakeDatabaseInstance); assert.strictEqual(op, OPERATION); @@ -320,16 +320,16 @@ describe('Instance', function() { }); }); - describe('database', function() { + describe('database', () => { const NAME = 'database-name'; - it('should throw if a name is not provided', function() { - assert.throws(function() { + it('should throw if a name is not provided', () => { + assert.throws(() => { instance.database(); }, /A name is required to access a Database object\./); }); - it('should create and cache a Database', function() { + it('should create and cache a Database', () => { const cache = instance.databases_; const poolOptions = {}; @@ -344,7 +344,7 @@ describe('Instance', function() { assert.strictEqual(database, cache.get(NAME)); }); - it('should re-use cached objects', function() { + it('should re-use cached objects', () => { const cache = instance.databases_; const fakeDatabase = {}; @@ -356,12 +356,12 @@ describe('Instance', function() { }); }); - describe('delete', function() { - beforeEach(function() { + describe('delete', () => { + beforeEach(() => { instance.parent = SPANNER; }); - it('should close all cached databases', function(done) { + it('should close all cached databases', done => { let closed = false; instance.databases_.set('key', { @@ -380,7 +380,7 @@ describe('Instance', function() { instance.delete(assert.ifError); }); - it('should ignore closing errors', function(done) { + it('should ignore closing errors', done => { instance.databases_.set('key', { close: function() { return Promise.reject(new Error('err')); @@ -394,7 +394,7 @@ describe('Instance', function() { instance.delete(assert.ifError); }); - it('should make the correct request', function(done) { + it('should make the correct request', done => { instance.request = function(config, callback) { assert.strictEqual(config.client, 'InstanceAdminClient'); assert.strictEqual(config.method, 'deleteInstance'); @@ -407,7 +407,7 @@ describe('Instance', function() { instance.delete(done); }); - it('should remove the Instance from the cache', function(done) { + it('should remove the Instance from the cache', done => { const cache = instance.parent.instances_; instance.request = function(config, callback) { @@ -417,7 +417,7 @@ describe('Instance', function() { cache.set(instance.id, instance); assert.strictEqual(cache.get(instance.id), instance); - instance.delete(function(err) { + instance.delete(err => { assert.ifError(err); assert.strictEqual(cache.has(instance.id), false); done(); @@ -425,41 +425,41 @@ describe('Instance', function() { }); }); - describe('exists', function() { - it('should return any non-404 like errors', function(done) { + describe('exists', () => { + it('should return any non-404 like errors', done => { const error = {code: 3}; instance.getMetadata = function(callback) { callback(error); }; - instance.exists(function(err, exists) { + instance.exists((err, exists) => { assert.strictEqual(err, error); assert.strictEqual(exists, null); done(); }); }); - it('should return true if error is absent', function(done) { + it('should return true if error is absent', done => { instance.getMetadata = function(callback) { callback(null); }; - instance.exists(function(err, exists) { + instance.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, true); done(); }); }); - it('should return false if not found error if present', function(done) { + it('should return false if not found error if present', done => { const error = {code: 5}; instance.getMetadata = function(callback) { callback(error); }; - instance.exists(function(err, exists) { + instance.exists((err, exists) => { assert.ifError(err); assert.strictEqual(exists, false); done(); @@ -467,8 +467,8 @@ describe('Instance', function() { }); }); - describe('get', function() { - it('should call getMetadata', function(done) { + describe('get', () => { + it('should call getMetadata', done => { const options = {}; instance.getMetadata = function() { @@ -478,7 +478,7 @@ describe('Instance', function() { instance.get(options, assert.ifError); }); - it('should not require an options object', function(done) { + it('should not require an options object', done => { instance.getMetadata = function() { done(); }; @@ -486,7 +486,7 @@ describe('Instance', function() { instance.get(assert.ifError); }); - describe('autoCreate', function() { + describe('autoCreate', () => { const error = new Error('Error.'); error.code = 5; @@ -502,7 +502,7 @@ describe('Instance', function() { }, }; - beforeEach(function() { + beforeEach(() => { OPERATION.listeners = {}; instance.getMetadata = function(callback) { @@ -514,7 +514,7 @@ describe('Instance', function() { }; }); - it('should call create', function(done) { + it('should call create', done => { instance.create = function(options) { assert.strictEqual(options, OPTIONS); done(); @@ -523,40 +523,40 @@ describe('Instance', function() { instance.get(OPTIONS, assert.ifError); }); - it('should return error if create failed', function(done) { + it('should return error if create failed', done => { const error = new Error('Error.'); instance.create = function(options, callback) { callback(error); }; - instance.get(OPTIONS, function(err) { + instance.get(OPTIONS, err => { assert.strictEqual(err, error); done(); }); }); - it('should return operation error', function(done) { + it('should return operation error', done => { const error = new Error('Error.'); - setImmediate(function() { + setImmediate(() => { OPERATION.listeners['error'](error); }); - instance.get(OPTIONS, function(err) { + instance.get(OPTIONS, err => { assert.strictEqual(err, error); done(); }); }); - it('should execute callback if opereation succeeded', function(done) { + it('should execute callback if opereation succeeded', done => { const metadata = {}; - setImmediate(function() { + setImmediate(() => { OPERATION.listeners['complete'](metadata); }); - instance.get(OPTIONS, function(err, instance_, apiResponse) { + instance.get(OPTIONS, (err, instance_, apiResponse) => { assert.ifError(err); assert.strictEqual(instance_, instance); assert.strictEqual(instance.metadata, metadata); @@ -566,7 +566,7 @@ describe('Instance', function() { }); }); - it('should not auto create without error code 5', function(done) { + it('should not auto create without error code 5', done => { const error = new Error('Error.'); error.code = 'NOT-5'; @@ -582,13 +582,13 @@ describe('Instance', function() { throw new Error('Should not create.'); }; - instance.get(options, function(err) { + instance.get(options, err => { assert.strictEqual(err, error); done(); }); }); - it('should not auto create unless requested', function(done) { + it('should not auto create unless requested', done => { const error = new Error('Error.'); error.code = 5; @@ -600,33 +600,33 @@ describe('Instance', function() { throw new Error('Should not create.'); }; - instance.get(function(err) { + instance.get(err => { assert.strictEqual(err, error); done(); }); }); - it('should return an error from getMetadata', function(done) { + it('should return an error from getMetadata', done => { const error = new Error('Error.'); instance.getMetadata = function(callback) { callback(error); }; - instance.get(function(err) { + instance.get(err => { assert.strictEqual(err, error); done(); }); }); - it('should return self and API response', function(done) { + it('should return self and API response', done => { const apiResponse = {}; instance.getMetadata = function(callback) { callback(null, apiResponse); }; - instance.get(function(err, instance_, apiResponse_) { + instance.get((err, instance_, apiResponse_) => { assert.ifError(err); assert.strictEqual(instance_, instance); assert.strictEqual(apiResponse_, apiResponse); @@ -635,13 +635,13 @@ describe('Instance', function() { }); }); - describe('getDatabases', function() { + describe('getDatabases', () => { const QUERY = { a: 'b', }; const ORIGINAL_QUERY = extend({}, QUERY); - it('should make the correct request', function(done) { + it('should make the correct request', done => { const expectedReqOpts = extend({}, QUERY, { parent: instance.formattedName_, }); @@ -662,7 +662,7 @@ describe('Instance', function() { instance.getDatabases(QUERY, assert.ifError); }); - it('should not require a query', function(done) { + it('should not require a query', done => { instance.request = function(config) { assert.deepStrictEqual(config.reqOpts, { parent: instance.formattedName_, @@ -676,16 +676,16 @@ describe('Instance', function() { instance.getDatabases(assert.ifError); }); - describe('error', function() { + describe('error', () => { const REQUEST_RESPONSE_ARGS = [new Error('Error.'), null, {}]; - beforeEach(function() { + beforeEach(() => { instance.request = function(config, callback) { callback.apply(null, REQUEST_RESPONSE_ARGS); }; }); - it('should execute callback with original arguments', function(done) { + it('should execute callback with original arguments', done => { instance.getDatabases(QUERY, function() { assert.deepStrictEqual( [].slice.call(arguments), @@ -696,7 +696,7 @@ describe('Instance', function() { }); }); - describe('success', function() { + describe('success', () => { const DATABASES = [ { name: 'database-name', @@ -705,13 +705,13 @@ describe('Instance', function() { const REQUEST_RESPONSE_ARGS = [null, DATABASES, {}]; - beforeEach(function() { + beforeEach(() => { instance.request = function(config, callback) { callback.apply(null, REQUEST_RESPONSE_ARGS); }; }); - it('should create and return Database objects', function(done) { + it('should create and return Database objects', done => { const fakeDatabaseInstance = {}; instance.database = function(name) { @@ -736,8 +736,8 @@ describe('Instance', function() { }); }); - describe('getMetadata', function() { - it('should correctly call and return request', function() { + describe('getMetadata', () => { + it('should correctly call and return request', () => { const requestReturnValue = {}; function callback() {} @@ -757,13 +757,13 @@ describe('Instance', function() { }); }); - describe('setMetadata', function() { + describe('setMetadata', () => { const METADATA = { needsToBeSnakeCased: true, }; const ORIGINAL_METADATA = extend({}, METADATA); - it('should make and return the request', function() { + it('should make and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -792,8 +792,8 @@ describe('Instance', function() { assert.strictEqual(returnValue, requestReturnValue); }); - it('should not require a callback', function() { - assert.doesNotThrow(function() { + it('should not require a callback', () => { + assert.doesNotThrow(() => { instance.setMetadata(METADATA); }); }); diff --git a/test/partial-result-stream.js b/test/partial-result-stream.js index b45e36c3a..fbe59240e 100644 --- a/test/partial-result-stream.js +++ b/test/partial-result-stream.js @@ -66,7 +66,7 @@ FakeRowBuilder.prototype.toJSON = function() { return FakeRowBuilderOverrides.toJSON.apply(this, arguments); }; -describe('PartialResultStream', function() { +describe('PartialResultStream', () => { let partialResultStreamModule; let partialResultStreamCached; @@ -100,7 +100,7 @@ describe('PartialResultStream', function() { values: [], }; - before(function() { + before(() => { partialResultStreamModule = proxyquire('../src/partial-result-stream.js', { 'checkpoint-stream': fakeCheckpointStream, './row-builder.js': FakeRowBuilder, @@ -108,20 +108,20 @@ describe('PartialResultStream', function() { partialResultStreamCached = extend({}, partialResultStreamModule); }); - beforeEach(function() { + beforeEach(() => { FakeRowBuilderOverrides = {}; checkpointStreamOverride = null; fakeRequestStream = through.obj(); extend(partialResultStreamModule, partialResultStreamCached); - partialResultStream = partialResultStreamModule(function() { + partialResultStream = partialResultStreamModule(() => { return fakeRequestStream; }); }); - describe('stream', function() { - beforeEach(function() { + describe('stream', () => { + beforeEach(() => { FakeRowBuilderOverrides.addRow = function(row) { this.row = row; }; @@ -137,7 +137,7 @@ describe('PartialResultStream', function() { }; }); - it('should only push rows when there is a token', function(done) { + it('should only push rows when there is a token', done => { let eventsEmitted = 0; function assertDoesNotEmit() { @@ -165,47 +165,47 @@ describe('PartialResultStream', function() { fakeRequestStream.push(null); }); - it('should emit the raw response', function(done) { + it('should emit the raw response', done => { fakeRequestStream.push(RESULT_WITH_TOKEN); fakeRequestStream.push(null); partialResultStream .on('error', done) - .on('response', function(response) { + .on('response', response => { assert.strictEqual(response, RESULT_WITH_TOKEN); done(); }) .resume(); }); - it('should effectively skip rows without values', function(done) { + it('should effectively skip rows without values', done => { fakeRequestStream.push(RESULT_WITHOUT_VALUE); fakeRequestStream.push(null); partialResultStream.on('error', done).pipe( - concat(function(rows) { + concat(rows => { assert.strictEqual(rows.length, 0); done(); }) ); }); - it('should not queue more than 10 results', function(done) { + it('should not queue more than 10 results', done => { for (let i = 0; i < 11; i += 1) { fakeRequestStream.push(RESULT_WITHOUT_TOKEN); } fakeRequestStream.push(null); partialResultStream.on('error', done).pipe( - concat(function(rows) { + concat(rows => { assert.strictEqual(rows.length, 11); done(); }) ); }); - describe('RowBuilder', function() { - it('should create a RowBuiler instance', function(done) { + describe('RowBuilder', () => { + it('should create a RowBuiler instance', done => { const fields = []; const row = extend(true, {}, RESULT_WITH_TOKEN); row.metadata.rowType.fields = fields; @@ -221,7 +221,7 @@ describe('PartialResultStream', function() { partialResultStream.on('error', done).resume(); }); - it('should run chunks through RowBuilder', function(done) { + it('should run chunks through RowBuilder', done => { const builtRow = {}; let wasBuildCalled = false; @@ -241,7 +241,7 @@ describe('PartialResultStream', function() { fakeRequestStream.push(null); partialResultStream.on('error', done).pipe( - concat(function(rows) { + concat(rows => { assert.strictEqual(wasBuildCalled, true); assert.strictEqual(rows[0], builtRow); done(); @@ -249,13 +249,13 @@ describe('PartialResultStream', function() { ); }); - it('should return the formatted row as JSON', function(done) { + it('should return the formatted row as JSON', done => { const options = { json: true, jsonOptions: {}, }; - const partialResultStream = partialResultStreamModule(function() { + const partialResultStream = partialResultStreamModule(() => { return fakeRequestStream; }, options); @@ -277,7 +277,7 @@ describe('PartialResultStream', function() { }); }); - it('should resume if there was an error', function(done) { + it('should resume if there was an error', done => { // This test will emit four rows total: // - Two rows // - Error event (should retry) @@ -299,13 +299,13 @@ describe('PartialResultStream', function() { numTimesRequestFnCalled++; if (numTimesRequestFnCalled === 1) { - setTimeout(function() { + setTimeout(() => { firstFakeRequestStream.push(RESULT_WITH_TOKEN); fakeCheckpointStream.emit('checkpoint', RESULT_WITH_TOKEN); firstFakeRequestStream.push(RESULT_WITH_TOKEN); fakeCheckpointStream.emit('checkpoint', RESULT_WITH_TOKEN); - setTimeout(function() { + setTimeout(() => { // This causes a new request stream to be created. firstFakeRequestStream.emit('error', new Error('Error.')); firstFakeRequestStream.end(); @@ -318,7 +318,7 @@ describe('PartialResultStream', function() { if (numTimesRequestFnCalled === 2) { assert.strictEqual(resumeToken, RESULT_WITH_TOKEN.resumeToken); - setTimeout(function() { + setTimeout(() => { secondFakeRequestStream.push(RESULT_WITH_TOKEN); fakeCheckpointStream.emit('checkpoint', RESULT_WITH_TOKEN); secondFakeRequestStream.push(RESULT_WITH_TOKEN); @@ -334,24 +334,24 @@ describe('PartialResultStream', function() { partialResultStreamModule(requestFn) .on('error', done) .pipe( - concat(function(rows) { + concat(rows => { assert.strictEqual(rows.length, 4); done(); }) ); }); - it('should emit rows and error when there is no token', function(done) { + it('should emit rows and error when there is no token', done => { const error = new Error('Error.'); let eventsEmitted = 0; partialResultStream - .on('data', function(row) { + .on('data', row => { eventsEmitted++; assert.strictEqual(row, RESULT_WITHOUT_TOKEN); }) - .on('error', function(err) { + .on('error', err => { assert.strictEqual(eventsEmitted, 3); assert.strictEqual(err, error); done(); @@ -364,12 +364,12 @@ describe('PartialResultStream', function() { fakeRequestStream.destroy(error); }); - it('should let user abort request', function(done) { + it('should let user abort request', done => { fakeRequestStream.abort = function() { done(); }; - const partialResultStream = partialResultStreamModule(function() { + const partialResultStream = partialResultStreamModule(() => { return fakeRequestStream; }); @@ -377,7 +377,7 @@ describe('PartialResultStream', function() { partialResultStream.abort(); }); - it('should silently no-op abort if no active request', function(done) { + it('should silently no-op abort if no active request', done => { // If no request is ever made, then there should be no active // stream to be aborted. fakeRequestStream.abort = function() { @@ -386,14 +386,14 @@ describe('PartialResultStream', function() { // Create a partial result stream and then abort it, without // ever sending a request. - const partialResultStream = partialResultStreamModule(function() { + const partialResultStream = partialResultStreamModule(() => { return fakeRequestStream; }); partialResultStream.abort(); done(); }); - it('should let user abort the most recent request', function(done) { + it('should let user abort the most recent request', done => { fakeRequestStream.abort = function() { done(new Error('Wrong stream was aborted.')); }; @@ -405,7 +405,7 @@ describe('PartialResultStream', function() { let numTimesRequestFnCalled = 0; - const partialResultStream = partialResultStreamModule(function() { + const partialResultStream = partialResultStreamModule(() => { numTimesRequestFnCalled++; if (numTimesRequestFnCalled === 1) { @@ -413,7 +413,7 @@ describe('PartialResultStream', function() { } if (numTimesRequestFnCalled === 2) { - setImmediate(function() { + setImmediate(() => { partialResultStream.abort(); }); return secondFakeRequestStream; diff --git a/test/row-builder.js b/test/row-builder.js index 46488d8ac..e57d896fd 100644 --- a/test/row-builder.js +++ b/test/row-builder.js @@ -39,14 +39,14 @@ const fakeCodec = { function FakeGrpcService() {} -describe('RowBuilder', function() { +describe('RowBuilder', () => { let RowBuilder; let RowBuilderCached; let rowBuilder; const FIELDS = [{}, {}]; - before(function() { + before(() => { RowBuilder = proxyquire('../src/row-builder.js', { '@google-cloud/common-grpc': { Service: FakeGrpcService, @@ -57,7 +57,7 @@ describe('RowBuilder', function() { RowBuilderCached = extend({}, RowBuilder); }); - beforeEach(function() { + beforeEach(() => { FakeGrpcService.decodeValue_ = util.noop; decodeOverride = null; generateToJSONFromRowOverride = null; @@ -65,11 +65,11 @@ describe('RowBuilder', function() { rowBuilder = new RowBuilder(FIELDS); }); - describe('acceptance tests', function() { + describe('acceptance tests', () => { const TESTS = require('./data/streaming-read-acceptance-test.json').tests; - TESTS.forEach(function(test) { - it('should pass acceptance test: ' + test.name, function() { + TESTS.forEach(test => { + it('should pass acceptance test: ' + test.name, () => { const fields = JSON.parse(test.chunks[0]).metadata.rowType.fields; const chunkJson = JSON.parse('[' + test.chunks.join() + ']'); const builder = new RowBuilder(fields); @@ -81,20 +81,20 @@ describe('RowBuilder', function() { }); }); - describe('instantiation', function() { - it('should localize fields', function() { + describe('instantiation', () => { + it('should localize fields', () => { assert.strictEqual(rowBuilder.fields, FIELDS); }); - it('should correctly initialize a chunks array', function() { + it('should correctly initialize a chunks array', () => { assert.deepStrictEqual(rowBuilder.chunks, []); }); - it('should correctly initialize a rows array', function() { + it('should correctly initialize a rows array', () => { assert.deepStrictEqual(rowBuilder.rows, [[]]); }); - it('should return the last row when accessing currentRow', function() { + it('should return the last row when accessing currentRow', () => { const rows = [{}, {}]; rowBuilder.rows.push(rows[0]); @@ -105,14 +105,14 @@ describe('RowBuilder', function() { }); }); - describe('getValue', function() { - it('should do nothing to plain values', function() { + describe('getValue', () => { + it('should do nothing to plain values', () => { const value = 'hi'; assert.strictEqual(RowBuilder.getValue(value), value); }); - it('should decode using GrpcService module', function() { + it('should decode using GrpcService module', () => { const value = { kind: 'stringValue', }; @@ -126,7 +126,7 @@ describe('RowBuilder', function() { assert.strictEqual(RowBuilder.getValue(value), expectedValue); }); - it('should return value from arrays', function() { + it('should return value from arrays', () => { const value = { kind: 'listValue', listValue: { @@ -145,7 +145,7 @@ describe('RowBuilder', function() { assert.strictEqual(RowBuilder.getValue(value), expectedValue); }); - it('should only return the values property from objects', function() { + it('should only return the values property from objects', () => { const value = []; Object.defineProperty(value, 'values', { @@ -161,15 +161,15 @@ describe('RowBuilder', function() { assert.strictEqual(RowBuilder.getValue(value), value); }); - it('should accept null values', function() { + it('should accept null values', () => { const value = null; assert.strictEqual(RowBuilder.getValue(value), value); }); }); - describe('formatValue', function() { - it('should iterate an array', function() { + describe('formatValue', () => { + it('should iterate an array', () => { const field = { code: 'ARRAY', arrayElementType: 'type', @@ -188,7 +188,7 @@ describe('RowBuilder', function() { assert.deepStrictEqual(formattedValue, [decodedValue]); }); - it('should return null if value is NULL_VALUE', function() { + it('should return null if value is NULL_VALUE', () => { const field = { code: 'ARRAY', arrayElementType: 'type', @@ -200,7 +200,7 @@ describe('RowBuilder', function() { assert.strictEqual(formattedValue, null); }); - it('should return decoded value if not an array or struct', function() { + it('should return decoded value if not an array or struct', () => { const field = { code: 'NOT_STRUCT_OR_ARRAY', }; @@ -218,7 +218,7 @@ describe('RowBuilder', function() { assert.strictEqual(formattedValue, decodedValue); }); - it('should iterate a struct', function() { + it('should iterate a struct', () => { const field = { code: 'STRUCT', structType: { @@ -247,8 +247,8 @@ describe('RowBuilder', function() { }); }); - describe('merge', function() { - it('should merge arrays', function() { + describe('merge', () => { + it('should merge arrays', () => { const type = { code: 'ARRAY', arrayElementType: { @@ -264,7 +264,7 @@ describe('RowBuilder', function() { assert.deepStrictEqual(merged, [[1, 2, 3, 4]]); }); - it('should merge structs', function() { + it('should merge structs', () => { const type = { code: 'STRUCT', structType: { @@ -287,7 +287,7 @@ describe('RowBuilder', function() { assert.deepStrictEqual(merged, [[1, 2, 3, 4]]); }); - it('should merge numbers', function() { + it('should merge numbers', () => { const type = { code: 'mergable-type', // any value but float64/array/struct }; @@ -299,7 +299,7 @@ describe('RowBuilder', function() { assert.strictEqual(merged[0], 3); }); - it('should merge strings', function() { + it('should merge strings', () => { const type = { code: 'mergable-type', // any value but float64/array/struct }; @@ -311,7 +311,7 @@ describe('RowBuilder', function() { assert.strictEqual(merged[0], 'ab'); }); - it('should not merge null head values', function() { + it('should not merge null head values', () => { const type = { code: 'mergable-type', // any value but float64/array/struct }; @@ -324,7 +324,7 @@ describe('RowBuilder', function() { assert.strictEqual(merged[1], tail); }); - it('should not merge null tail values', function() { + it('should not merge null tail values', () => { const type = { code: 'mergable-type', // any value but float64/array/struct }; @@ -337,7 +337,7 @@ describe('RowBuilder', function() { assert.strictEqual(merged[1], tail); }); - it('should not merge floats', function() { + it('should not merge floats', () => { const type = { code: 'FLOAT64', // any value but float64/array/struct }; @@ -350,7 +350,7 @@ describe('RowBuilder', function() { assert.strictEqual(merged[1], tail); }); - it('should filter out empty strings', function() { + it('should filter out empty strings', () => { const type = { code: 'mergable-type', // any value but float64/array/struct }; @@ -363,8 +363,8 @@ describe('RowBuilder', function() { }); }); - describe('addRow', function() { - it('should combine row with chunks', function() { + describe('addRow', () => { + it('should combine row with chunks', () => { rowBuilder.chunks = []; const row = {}; @@ -374,13 +374,13 @@ describe('RowBuilder', function() { }); }); - describe('append', function() { + describe('append', () => { const ROWS = [[{}, {}], [{}, {}]]; const ROW_1 = ROWS[0]; const ROW_2 = ROWS[1]; - beforeEach(function() { + beforeEach(() => { rowBuilder.fields = [{}, {}]; // matches the # of objects in a row rowBuilder.rows = [ @@ -388,7 +388,7 @@ describe('RowBuilder', function() { ]; }); - it('should create a new row if the last row is complete', function() { + it('should create a new row if the last row is complete', () => { rowBuilder.append(ROW_2[0]); rowBuilder.append(ROW_2[1]); @@ -399,7 +399,7 @@ describe('RowBuilder', function() { assert.strictEqual(rowBuilder.rows[1][1], ROW_2[1]); }); - it('should push a value into the current row if incomplete', function() { + it('should push a value into the current row if incomplete', () => { assert.strictEqual(rowBuilder.rows[0][0], ROW_1[0]); assert.strictEqual(rowBuilder.rows[0][1], ROW_1[1]); @@ -411,8 +411,8 @@ describe('RowBuilder', function() { }); }); - describe('build', function() { - beforeEach(function() { + describe('build', () => { + beforeEach(() => { rowBuilder.chunks = [ { values: [{}], @@ -420,7 +420,7 @@ describe('RowBuilder', function() { ]; }); - it('should append values from a chunk', function(done) { + it('should append values from a chunk', done => { rowBuilder.append = function(value) { assert.strictEqual(this, rowBuilder); assert.strictEqual(value, rowBuilder.chunks[0].values[0]); @@ -430,7 +430,7 @@ describe('RowBuilder', function() { rowBuilder.build(); }); - it('should merge chunked values', function() { + it('should merge chunked values', () => { rowBuilder.rows = [[{}, {}], [{}]]; rowBuilder.fields = [ @@ -472,34 +472,34 @@ describe('RowBuilder', function() { assert.strictEqual(mergedValues[0], rowBuilder.rows[1][1]); }); - it('should remove chunks', function() { + it('should remove chunks', () => { rowBuilder.build(); assert.deepStrictEqual(rowBuilder.chunks, []); }); }); - describe('flush', function() { + describe('flush', () => { const ROWS = [[]]; for (let i = 0; i < FIELDS.length; i++) { ROWS[0].push({}); } - beforeEach(function() { + beforeEach(() => { rowBuilder.rows = ROWS; }); - it('should return rows', function() { + it('should return rows', () => { const expectedRows = rowBuilder.rows; assert.deepStrictEqual(rowBuilder.flush(), expectedRows); }); - it('should reset rows', function() { + it('should reset rows', () => { rowBuilder.flush(); assert.deepStrictEqual(rowBuilder.rows, [[]]); }); - it('should retain a partial row', function() { + it('should retain a partial row', () => { const partialRow = [{partial: true}]; rowBuilder.rows = rowBuilder.rows.concat(partialRow); @@ -508,10 +508,10 @@ describe('RowBuilder', function() { }); }); - describe('toJSON', function() { + describe('toJSON', () => { const ROWS = [[{}]]; - beforeEach(function() { + beforeEach(() => { rowBuilder.fields = [ { name: 'fieldName', @@ -520,7 +520,7 @@ describe('RowBuilder', function() { ]; }); - it('should format the values', function() { + it('should format the values', () => { const formattedValue = { formatted: true, }; @@ -546,11 +546,11 @@ describe('RowBuilder', function() { }); }); - describe('toJSON', function() { + describe('toJSON', () => { const toJSONOverride = function() {}; let FORMATTED_ROW; - beforeEach(function() { + beforeEach(() => { generateToJSONFromRowOverride = function() { return toJSONOverride; }; @@ -566,11 +566,11 @@ describe('RowBuilder', function() { FORMATTED_ROW = rowBuilder.toJSON(ROWS)[0]; }); - it('should assign a toJSON method', function() { + it('should assign a toJSON method', () => { assert.strictEqual(FORMATTED_ROW.toJSON, toJSONOverride); }); - it('should not include toJSON when iterated', function() { + it('should not include toJSON when iterated', () => { for (const keyVal in FORMATTED_ROW) { if (keyVal === 'toJSON') { throw new Error('toJSON should not be iterated.'); diff --git a/test/session-pool.js b/test/session-pool.js index c3f21aabc..60a38c3f7 100644 --- a/test/session-pool.js +++ b/test/session-pool.js @@ -67,29 +67,29 @@ const fakeStackTrace = extend({}, stackTrace); function noop() {} -describe('SessionPool', function() { +describe('SessionPool', () => { let sessionPool; let SessionPool; const DATABASE = {}; - before(function() { + before(() => { SessionPool = proxyquire('../src/session-pool.js', { 'p-queue': FakePQueue, 'stack-trace': fakeStackTrace, }); }); - beforeEach(function() { + beforeEach(() => { DATABASE.session = () => new FakeSession(); sessionPool = new SessionPool(DATABASE); }); - afterEach(function() { + afterEach(() => { pQueueOverride = null; }); - describe('formatTrace', function() { + describe('formatTrace', () => { const fakeFileName = 'path/to/file.js'; const fakeLineNumber = '99'; const fakeColumnNumber = '13'; @@ -118,7 +118,7 @@ describe('SessionPool', function() { }, ]; - it('should return a trace with the method name', function() { + it('should return a trace with the method name', () => { fakeMethod = 'MyClass.myMethod'; const expected = `Session leak detected!\n at ${fakeMethod} (${file})`; @@ -127,7 +127,7 @@ describe('SessionPool', function() { assert.strictEqual(expected, actual); }); - it('should return a trace with the function name', function() { + it('should return a trace with the function name', () => { fakeFunction = 'myFunction'; const expected = `Session leak detected!\n at ${fakeFunction} (${file})`; @@ -137,8 +137,8 @@ describe('SessionPool', function() { }); }); - describe('available', function() { - it('should return the number of available sessions', function() { + describe('available', () => { + it('should return the number of available sessions', () => { sessionPool._inventory = { readonly: [{}], readwrite: [{}, {}], @@ -148,16 +148,16 @@ describe('SessionPool', function() { }); }); - describe('borrowed', function() { - it('should return the number of borrowed sessions', function() { + describe('borrowed', () => { + it('should return the number of borrowed sessions', () => { sessionPool._inventory.borrowed = new Set([{}, {}]); assert.strictEqual(sessionPool.borrowed, 2); }); }); - describe('isFull', function() { - it('should indicate if the pool is full', function() { + describe('isFull', () => { + it('should indicate if the pool is full', () => { sessionPool.options.max = 1; assert.strictEqual(sessionPool.isFull, false); @@ -166,13 +166,13 @@ describe('SessionPool', function() { }); }); - describe('reads', function() { - it('should get the total number of read sessions', function() { + describe('reads', () => { + it('should get the total number of read sessions', () => { sessionPool._inventory.readonly = [{}, {}, {}]; assert.strictEqual(sessionPool.reads, 3); }); - it('should factor in borrowed sessions', function() { + it('should factor in borrowed sessions', () => { sessionPool.options.min = 4; return sessionPool @@ -188,8 +188,8 @@ describe('SessionPool', function() { }); }); - describe('size', function() { - it('should return the size of the pool', function() { + describe('size', () => { + it('should return the size of the pool', () => { sessionPool._inventory = { readonly: [{}], readwrite: [{}, {}], @@ -200,13 +200,13 @@ describe('SessionPool', function() { }); }); - describe('writes', function() { - it('should get the total number of read/write sessions', function() { + describe('writes', () => { + it('should get the total number of read/write sessions', () => { sessionPool._inventory.readwrite = [{}, {}, {}]; assert.strictEqual(sessionPool.writes, 3); }); - it('should factor in borrowed sessions', function() { + it('should factor in borrowed sessions', () => { sessionPool.options.min = 4; sessionPool.options.writes = 1; @@ -223,13 +223,13 @@ describe('SessionPool', function() { }); }); - describe('instantiation', function() { - it('should localize the database instance', function() { + describe('instantiation', () => { + it('should localize the database instance', () => { assert.strictEqual(sessionPool.database, DATABASE); }); - describe('options', function() { - it('should apply defaults', function() { + describe('options', () => { + it('should apply defaults', () => { assert.strictEqual(sessionPool.options.acquireTimeout, Infinity); assert.strictEqual(sessionPool.options.concurrency, Infinity); assert.strictEqual(sessionPool.options.fail, false); @@ -241,33 +241,33 @@ describe('SessionPool', function() { assert.strictEqual(sessionPool.options.writes, 0); }); - it('should not override user options', function() { + it('should not override user options', () => { sessionPool = new SessionPool(DATABASE, {acquireTimeout: 0}); assert.strictEqual(sessionPool.options.acquireTimeout, 0); }); - describe('writes', function() { + describe('writes', () => { const writeErrReg = /Write percentage should be represented as a float between 0\.0 and 1\.0\./; - it('should throw when writes is less than 0', function() { - assert.throws(function() { + it('should throw when writes is less than 0', () => { + assert.throws(() => { return new SessionPool(DATABASE, {writes: -1}); }, writeErrReg); }); - it('should throw when writes is greater than 1', function() { - assert.throws(function() { + it('should throw when writes is greater than 1', () => { + assert.throws(() => { return new SessionPool(DATABASE, {writes: 50}); }, writeErrReg); }); }); }); - it('should set isOpen to false', function() { + it('should set isOpen to false', () => { assert.strictEqual(sessionPool.isOpen, false); }); - it('should create an inventory object', function() { + it('should create an inventory object', () => { assert.deepStrictEqual(sessionPool._inventory, { readonly: [], readwrite: [], @@ -275,7 +275,7 @@ describe('SessionPool', function() { }); }); - it('should create a request queue', function() { + it('should create a request queue', () => { const poolOptions = { concurrency: 11, }; @@ -290,7 +290,7 @@ describe('SessionPool', function() { }); }); - it('should create an acquire queue', function() { + it('should create an acquire queue', () => { pQueueOverride = function(options) { return options; }; @@ -301,17 +301,17 @@ describe('SessionPool', function() { }); }); - it('should create a map of traces', function() { + it('should create a map of traces', () => { assert.deepStrictEqual(sessionPool._traces, new Map()); }); - it('should inherit from EventEmitter', function() { + it('should inherit from EventEmitter', () => { assert(sessionPool instanceof events.EventEmitter); }); }); - describe('close', function() { - beforeEach(function() { + describe('close', () => { + beforeEach(() => { sessionPool._inventory = { readonly: [{}, {}], readwrite: [{}], @@ -321,29 +321,29 @@ describe('SessionPool', function() { sessionPool._destroy = noop; }); - it('should clear the inventory', function() { + it('should clear the inventory', () => { sessionPool.close(noop); assert.strictEqual(sessionPool.size, 0); }); - it('should stop housekeeping', function(done) { + it('should stop housekeeping', done => { sessionPool._stopHouseKeeping = done; sessionPool.close(noop); }); - it('should set isOpen to false', function() { + it('should set isOpen to false', () => { sessionPool.isOpen = true; sessionPool.close(noop); assert.strictEqual(sessionPool.isOpen, false); }); - it('should emit the close event', function(done) { + it('should emit the close event', done => { sessionPool.on('close', done); sessionPool.close(noop); }); - it('should destroy all the sessions', function() { + it('should destroy all the sessions', () => { const sessions = [].concat( sessionPool._inventory.readonly, sessionPool._inventory.readwrite, @@ -360,7 +360,7 @@ describe('SessionPool', function() { assert.strictEqual(destroyed, sessions.length); }); - it('should execute the callback on idle', function(done) { + it('should execute the callback on idle', done => { let idleCalled = false; sessionPool._requests.onIdle = function() { @@ -368,21 +368,21 @@ describe('SessionPool', function() { return Promise.resolve(); }; - sessionPool.close(function(err) { + sessionPool.close(err => { assert.ifError(err); assert.strictEqual(idleCalled, true); done(); }); }); - it('should return a leak error', function(done) { + it('should return a leak error', done => { const fakeLeaks = [{}, {}]; sessionPool._getLeaks = function() { return fakeLeaks; }; - sessionPool.close(function(err) { + sessionPool.close(err => { assert.strictEqual( err.message, `${fakeLeaks.length} session leak(s) detected.` @@ -393,8 +393,8 @@ describe('SessionPool', function() { }); }); - describe('getReadSession', function() { - it('should acquire a read session', function(done) { + describe('getReadSession', () => { + it('should acquire a read session', done => { const fakeSession = new FakeSession(); sessionPool._acquire = function(type) { @@ -402,29 +402,29 @@ describe('SessionPool', function() { return Promise.resolve(fakeSession); }; - sessionPool.getReadSession(function(err, session) { + sessionPool.getReadSession((err, session) => { assert.ifError(err); assert.strictEqual(session, fakeSession); done(); }); }); - it('should pass any errors to the callback', function(done) { + it('should pass any errors to the callback', done => { const error = new Error('err'); sessionPool._acquire = function() { return Promise.reject(error); }; - sessionPool.getReadSession(function(err) { + sessionPool.getReadSession(err => { assert.strictEqual(err, error); done(); }); }); }); - describe('getWriteSession', function() { - it('should pass back the session and txn', function(done) { + describe('getWriteSession', () => { + it('should pass back the session and txn', done => { const fakeSession = new FakeSession(); const fakeTxn = new FakeTransaction(); @@ -435,7 +435,7 @@ describe('SessionPool', function() { return Promise.resolve(fakeSession); }; - sessionPool.getWriteSession(function(err, session, txn) { + sessionPool.getWriteSession((err, session, txn) => { assert.ifError(err); assert.strictEqual(session, fakeSession); assert.strictEqual(txn, fakeTxn); @@ -443,27 +443,27 @@ describe('SessionPool', function() { }); }); - it('should pass any errors to the callback', function(done) { + it('should pass any errors to the callback', done => { const error = new Error('err'); sessionPool._acquire = function() { return Promise.reject(error); }; - sessionPool.getWriteSession(function(err) { + sessionPool.getWriteSession(err => { assert.strictEqual(err, error); done(); }); }); }); - describe('open', function() { - beforeEach(function() { + describe('open', () => { + beforeEach(() => { sessionPool._stopHouseKeeping = noop; sessionPool._fill = noop; }); - it('should create an onclose promise', function() { + it('should create an onclose promise', () => { sessionPool.open(); assert(sessionPool._onClose instanceof Promise); @@ -471,42 +471,42 @@ describe('SessionPool', function() { return sessionPool._onClose; }); - it('should start housekeeping', function(done) { + it('should start housekeeping', done => { sessionPool._startHouseKeeping = done; sessionPool.open(); }); - it('should set isOpen to true', function() { + it('should set isOpen to true', () => { sessionPool.open(); assert.strictEqual(sessionPool.isOpen, true); }); - it('should emit the open event', function(done) { + it('should emit the open event', done => { sessionPool.on('open', done); sessionPool.open(); }); - it('should fill the pool', function() { + it('should fill the pool', () => { const fakeFillReturn = {}; sessionPool._fill = function() { return Promise.resolve(fakeFillReturn); }; - return sessionPool.open().then(function(obj) { + return sessionPool.open().then(obj => { assert.strictEqual(obj, fakeFillReturn); }); }); }); - describe('release', function() { - beforeEach(function() { + describe('release', () => { + beforeEach(() => { sessionPool._prepareTransaction = function() { return Promise.resolve(); }; }); - it('should throw an error when returning unknown resources', function() { + it('should throw an error when returning unknown resources', () => { const badResource = {}; try { @@ -518,7 +518,7 @@ describe('SessionPool', function() { } }); - it('should delete any old transactions', function() { + it('should delete any old transactions', () => { const session = new FakeSession(); sessionPool._release = noop; @@ -529,7 +529,7 @@ describe('SessionPool', function() { assert.strictEqual(session.txn, undefined); }); - it('should update the lastUsed timestamp', function() { + it('should update the lastUsed timestamp', () => { const session = new FakeSession(); sessionPool._release = noop; @@ -540,8 +540,8 @@ describe('SessionPool', function() { assert(isAround(session.lastUsed, Date.now())); }); - describe('readonly', function() { - it('should release readonly sessions', function(done) { + describe('readonly', () => { + it('should release readonly sessions', done => { const fakeSession = new FakeSession(); sessionPool._prepareTransaction = shouldNotBeCalled; @@ -557,16 +557,16 @@ describe('SessionPool', function() { }); }); - describe('readwrite', function() { + describe('readwrite', () => { let fakeSession; - beforeEach(function() { + beforeEach(() => { fakeSession = new FakeSession(); fakeSession.type = 'readwrite'; sessionPool._inventory.borrowed.add(fakeSession); }); - it('should prep a new transaction', function(done) { + it('should prep a new transaction', done => { sessionPool._prepareTransaction = function(session) { assert.strictEqual(session, fakeSession); setImmediate(done); @@ -577,7 +577,7 @@ describe('SessionPool', function() { sessionPool.release(fakeSession); }); - it('should release the read/write session', function(done) { + it('should release the read/write session', done => { sessionPool._prepareTransaction = function() { return Promise.resolve(); }; @@ -590,7 +590,7 @@ describe('SessionPool', function() { sessionPool.release(fakeSession); }); - it('should convert to a read session if txn fails', function(done) { + it('should convert to a read session if txn fails', done => { sessionPool._prepareTransaction = function() { return Promise.reject(); }; @@ -606,28 +606,28 @@ describe('SessionPool', function() { }); }); - describe('_acquire', function() { - beforeEach(function() { + describe('_acquire', () => { + beforeEach(() => { sessionPool.isOpen = true; sessionPool._isValidSession = () => true; }); - it('should return a closed error if not open', function() { + it('should return a closed error if not open', () => { sessionPool.isOpen = false; - return sessionPool._acquire().then(shouldNotBeCalled, function(err) { + return sessionPool._acquire().then(shouldNotBeCalled, err => { assert.strictEqual(err.message, 'Database is closed.'); }); }); - it('should return a timeout error if a timeout happens', function() { + it('should return a timeout error if a timeout happens', () => { sessionPool.options.acquireTimeout = 1; sessionPool._acquires.add = function(fn) { return delay(2).then(fn); }; - return sessionPool._acquire().then(shouldNotBeCalled, function(err) { + return sessionPool._acquire().then(shouldNotBeCalled, err => { assert.strictEqual( err.message, 'Timeout occurred while acquiring session.' @@ -635,7 +635,7 @@ describe('SessionPool', function() { }); }); - it('should return a session', function() { + it('should return a session', () => { const fakeSession = new FakeSession(); const fakeType = 'readonly'; const now = Date.now(); @@ -646,12 +646,12 @@ describe('SessionPool', function() { return Promise.resolve(fakeSession); }; - return sessionPool._acquire(fakeType).then(function(session) { + return sessionPool._acquire(fakeType).then(session => { assert.strictEqual(session, fakeSession); }); }); - it('should drop expired sessions', function() { + it('should drop expired sessions', () => { const badSession = new FakeSession(); const goodSession = new FakeSession(); const fakeSessions = [badSession, goodSession]; @@ -666,13 +666,13 @@ describe('SessionPool', function() { sessionPool._inventory.borrowed = new Set(fakeSessions); - return sessionPool._acquire('readonly').then(function(session) { + return sessionPool._acquire('readonly').then(session => { assert.strictEqual(session, goodSession); assert.strictEqual(sessionPool.size, 1); }); }); - it('should capture the stack trace', function() { + it('should capture the stack trace', () => { const id = 'abc'; const fakeSession = new FakeSession(); @@ -688,13 +688,13 @@ describe('SessionPool', function() { return fakeTrace; }; - return sessionPool._acquire('readonly').then(function() { + return sessionPool._acquire('readonly').then(() => { const trace = sessionPool._traces.get(id); assert.strictEqual(trace, fakeTrace); }); }); - it('should convert read sessions to write sessions', function() { + it('should convert read sessions to write sessions', () => { const fakeSession = new FakeSession(); const convertedSession = new FakeSession(); @@ -707,14 +707,14 @@ describe('SessionPool', function() { return convertedSession; }; - return sessionPool._acquire('readwrite').then(function(session) { + return sessionPool._acquire('readwrite').then(session => { assert.strictEqual(session, convertedSession); }); }); }); - describe('_borrow', function() { - it('should mark the session as borrowed', function() { + describe('_borrow', () => { + it('should mark the session as borrowed', () => { const fakeSession = new FakeSession(); const inv = sessionPool._inventory; @@ -728,8 +728,8 @@ describe('SessionPool', function() { }); }); - describe('_borrowFrom', function() { - it('should borrow the first available type', function() { + describe('_borrowFrom', () => { + it('should borrow the first available type', () => { const fakeSession = new FakeSession(); let borrowed = false; @@ -747,8 +747,8 @@ describe('SessionPool', function() { }); }); - describe('_borrowNextAvailableSession', function() { - it('should borrow from readonly when available', function() { + describe('_borrowNextAvailableSession', () => { + it('should borrow from readonly when available', () => { const fakeSession = new FakeSession(); sessionPool._inventory.readonly.push(fakeSession); @@ -763,7 +763,7 @@ describe('SessionPool', function() { assert.strictEqual(session, fakeSession); }); - it('should borrow from readwrites when available', function() { + it('should borrow from readwrites when available', () => { const fakeSession = new FakeSession(); sessionPool._inventory.readwrite.push(fakeSession); @@ -778,7 +778,7 @@ describe('SessionPool', function() { assert.strictEqual(session, fakeSession); }); - it('should borrow from rw when readonly isnt available', function() { + it('should borrow from rw when readonly isnt available', () => { const fakeSession = new FakeSession(); sessionPool._inventory.readwrite.push(fakeSession); @@ -793,7 +793,7 @@ describe('SessionPool', function() { assert.strictEqual(session, fakeSession); }); - it('should borrow from readonly when rw isnt available', function() { + it('should borrow from readonly when rw isnt available', () => { const fakeSession = new FakeSession(); sessionPool._inventory.readonly.push(fakeSession); @@ -809,8 +809,8 @@ describe('SessionPool', function() { }); }); - describe('_convertSession', function() { - it('should prepare a transaction', function() { + describe('_convertSession', () => { + it('should prepare a transaction', () => { const fakeSession = new FakeSession(); let prepared = false; @@ -821,13 +821,13 @@ describe('SessionPool', function() { return Promise.resolve(); }; - return sessionPool._convertSession(fakeSession).then(function(session) { + return sessionPool._convertSession(fakeSession).then(session => { assert.strictEqual(session, fakeSession); assert.strictEqual(prepared, true); }); }); - it('should release the session if it fails', function() { + it('should release the session if it fails', () => { const fakeSession = new FakeSession(); const error = new Error('err'); @@ -844,29 +844,29 @@ describe('SessionPool', function() { return sessionPool ._convertSession(fakeSession) - .then(shouldNotBeCalled, function(err) { + .then(shouldNotBeCalled, err => { assert.strictEqual(err, error); assert.strictEqual(released, true); }); }); }); - describe('_createSession', function() { - it('should put the session into a borrowed state', function() { + describe('_createSession', () => { + it('should put the session into a borrowed state', () => { sessionPool._requests.add = () => Promise.resolve(); sessionPool._createSession('readonly'); assert.strictEqual(sessionPool.borrowed, 1); }); - it('should create the session', function() { - return sessionPool._createSession('readonly').then(function() { + it('should create the session', () => { + return sessionPool._createSession('readonly').then(() => { const session = sessionPool._inventory.readonly[0]; assert.strictEqual(session.created, true); }); }); - it('should discard the session if unable to create', function() { + it('should discard the session if unable to create', () => { const error = new Error('err'); class BadFakeSession extends FakeSession { @@ -879,16 +879,14 @@ describe('SessionPool', function() { return new BadFakeSession(); }; - return sessionPool - ._createSession() - .then(shouldNotBeCalled, function(err) { - assert.strictEqual(err, error); - assert.strictEqual(sessionPool.borrowed, 0); - assert.strictEqual(sessionPool.available, 0); - }); + return sessionPool._createSession().then(shouldNotBeCalled, err => { + assert.strictEqual(err, error); + assert.strictEqual(sessionPool.borrowed, 0); + assert.strictEqual(sessionPool.available, 0); + }); }); - it('should prepare a transaction for readwrite sessions', function() { + it('should prepare a transaction for readwrite sessions', () => { let prepared = false; sessionPool._prepareTransaction = function(session) { @@ -897,25 +895,25 @@ describe('SessionPool', function() { return Promise.resolve(); }; - return sessionPool._createSession('readwrite').then(function() { + return sessionPool._createSession('readwrite').then(() => { assert.strictEqual(sessionPool.writes, 1); assert.strictEqual(prepared, true); }); }); - it('should convert rw to readonly if unable to prepare txn', function() { + it('should convert rw to readonly if unable to prepare txn', () => { sessionPool._prepareTransaction = function() { return Promise.reject(new Error('err')); }; - return sessionPool._createSession('readwrite').then(function() { + return sessionPool._createSession('readwrite').then(() => { assert.strictEqual(sessionPool.reads, 1); assert.strictEqual(sessionPool.writes, 0); }); }); - it('should update the session state', function() { - return sessionPool._createSession('readonly').then(function() { + it('should update the session state', () => { + return sessionPool._createSession('readonly').then(() => { const session = sessionPool._inventory.readonly[0]; assert.strictEqual(session.type, 'readonly'); @@ -927,8 +925,8 @@ describe('SessionPool', function() { }); }); - describe('_createSessionInBackground', function() { - it('should emit available on success', function(done) { + describe('_createSessionInBackground', () => { + it('should emit available on success', done => { sessionPool._createSession = function(type) { assert.strictEqual(type, 'readonly'); return Promise.resolve(); @@ -938,14 +936,14 @@ describe('SessionPool', function() { sessionPool._createSessionInBackground('readonly'); }); - it('should emit error on error', function(done) { + it('should emit error on error', done => { const error = new Error('err'); sessionPool._createSession = function() { return Promise.reject(error); }; - sessionPool.on('error', function(err) { + sessionPool.on('error', err => { assert.strictEqual(err, error); done(); }); @@ -954,22 +952,22 @@ describe('SessionPool', function() { }); }); - describe('_destroy', function() { - it('should delete the session', function() { + describe('_destroy', () => { + it('should delete the session', () => { const fakeSession = new FakeSession(); - return sessionPool._destroy(fakeSession).then(function() { + return sessionPool._destroy(fakeSession).then(() => { assert.strictEqual(fakeSession.deleted, true); }); }); - it('should emit any errors', function(done) { + it('should emit any errors', done => { const error = new Error('err'); const fakeSession = { delete: () => Promise.reject(error), }; - sessionPool.on('error', function(err) { + sessionPool.on('error', err => { assert.strictEqual(err, error); done(); }); @@ -978,10 +976,10 @@ describe('SessionPool', function() { }); }); - describe('_evictIdleSessions', function() { + describe('_evictIdleSessions', () => { let fakeSessions; - beforeEach(function() { + beforeEach(() => { fakeSessions = [ {type: 'readonly'}, {type: 'readwrite'}, @@ -997,7 +995,7 @@ describe('SessionPool', function() { }; }); - it('should evict the sessions', function() { + it('should evict the sessions', () => { let destroyCallCount = 0; sessionPool._destroy = function(session) { @@ -1011,7 +1009,7 @@ describe('SessionPool', function() { assert.strictEqual(destroyCallCount, fakeSessions.length); }); - it('should respect the maxIdle option', function() { + it('should respect the maxIdle option', () => { let destroyCallCount = 0; sessionPool._destroy = function(session) { @@ -1027,7 +1025,7 @@ describe('SessionPool', function() { assert.strictEqual(destroyCallCount, 1); }); - it('should respect the min value', function() { + it('should respect the min value', () => { let destroyCallCount = 0; sessionPool._destroy = function(session) { @@ -1044,10 +1042,10 @@ describe('SessionPool', function() { }); }); - describe('_fill', function() { + describe('_fill', () => { let created; - beforeEach(function() { + beforeEach(() => { sessionPool.options.min = 8; created = { @@ -1060,14 +1058,14 @@ describe('SessionPool', function() { }; }); - it('should create the min number of required sessions', function() { + it('should create the min number of required sessions', () => { sessionPool._fill(); assert.strictEqual(created.readonly, 8); assert.strictEqual(created.readwrite, 0); }); - it('should create the min number of write sessions', function() { + it('should create the min number of write sessions', () => { sessionPool.options.writes = 0.5; sessionPool._fill(); @@ -1075,7 +1073,7 @@ describe('SessionPool', function() { assert.strictEqual(created.readwrite, 4); }); - it('should respect the current size of the pool', function() { + it('should respect the current size of the pool', () => { sessionPool.options.writes = 0.5; sessionPool._inventory = { readonly: [{}], @@ -1089,23 +1087,23 @@ describe('SessionPool', function() { assert.strictEqual(created.readwrite, 2); }); - it('should settle once all the sessions are created', function() { + it('should settle once all the sessions are created', () => { const end = timeSpan(); sessionPool._createSessionInBackground = function() { - return new Promise(function(resolve) { + return new Promise(resolve => { setTimeout(resolve, 500); }); }; - return sessionPool._fill().then(function() { + return sessionPool._fill().then(() => { assert(isAround(500, end())); }); }); }); - describe('_getIdleSessions', function() { - it('should return a list of idle sessions', function() { + describe('_getIdleSessions', () => { + it('should return a list of idle sessions', () => { const idlesAfter = (sessionPool.options.idlesAfter = 1); // 1 minute const idleTimestamp = Date.now() - idlesAfter * 60000; @@ -1125,8 +1123,8 @@ describe('SessionPool', function() { }); }); - describe('_getLeaks', function() { - it('should return an array of leaks', function() { + describe('_getLeaks', () => { + it('should return an array of leaks', () => { sessionPool._traces.set('a', 'aaa'); sessionPool._traces.set('b', 'bbb'); @@ -1146,15 +1144,15 @@ describe('SessionPool', function() { }); }); - describe('_getSession', function() { - beforeEach(function() { + describe('_getSession', () => { + beforeEach(() => { sessionPool._onClose = new Promise(resolve => { sessionPool.on('close', resolve); }); sessionPool.options.max = 0; }); - it('should return a session if one is available', function() { + it('should return a session if one is available', () => { const fakeSession = new FakeSession(); sessionPool._inventory.readonly = [fakeSession]; @@ -1164,28 +1162,28 @@ describe('SessionPool', function() { return fakeSession; }; - return sessionPool._getSession('readonly').then(function(session) { + return sessionPool._getSession('readonly').then(session => { assert.strictEqual(session, fakeSession); }); }); - it('should return an error if empty and fail = true', function() { + it('should return an error if empty and fail = true', () => { sessionPool.options.fail = true; - return sessionPool._getSession().then(shouldNotBeCalled, function(err) { + return sessionPool._getSession().then(shouldNotBeCalled, err => { assert.strictEqual(err.message, 'No resources available.'); }); }); - it('should throw a closed error if the pool closes', function() { + it('should throw a closed error if the pool closes', () => { setTimeout(() => sessionPool.emit('close'), 100); - return sessionPool._getSession().then(shouldNotBeCalled, function(err) { + return sessionPool._getSession().then(shouldNotBeCalled, err => { assert.strictEqual(err.message, 'Database is closed.'); }); }); - it('should return a session when it becomes available', function() { + it('should return a session when it becomes available', () => { const fakeSession = new FakeSession(); sessionPool._borrowNextAvailableSession = function(type) { @@ -1195,18 +1193,18 @@ describe('SessionPool', function() { setTimeout(() => sessionPool.emit('available'), 100); - return sessionPool._getSession('readonly').then(function(session) { + return sessionPool._getSession('readonly').then(session => { assert.strictEqual(session, fakeSession); }); }); - it('should use the acquireTimeout if set', function() { + it('should use the acquireTimeout if set', () => { const end = timeSpan(); const timeout = (sessionPool.options.acquireTimeout = 100); return sessionPool ._getSession('readonly', Date.now()) - .then(shouldNotBeCalled, function(err) { + .then(shouldNotBeCalled, err => { assert(isAround(timeout, end())); assert.strictEqual( err.message, @@ -1215,7 +1213,7 @@ describe('SessionPool', function() { }); }); - it('should create a session if the pool is not full', function() { + it('should create a session if the pool is not full', () => { const fakeSession = new FakeSession(); sessionPool.options.max = 1; @@ -1232,13 +1230,13 @@ describe('SessionPool', function() { return fakeSession; }; - return sessionPool._getSession('readonly').then(function(session) { + return sessionPool._getSession('readonly').then(session => { assert.strictEqual(created, true); assert.strictEqual(session, fakeSession); }); }); - it('should return any create errors', function() { + it('should return any create errors', () => { const error = new Error('err'); sessionPool.options.max = 1; @@ -1247,33 +1245,33 @@ describe('SessionPool', function() { return Promise.reject(error); }; - return sessionPool._getSession().then(shouldNotBeCalled, function(err) { + return sessionPool._getSession().then(shouldNotBeCalled, err => { assert.strictEqual(err, error); }); }); - it('should remove the available listener on error', function() { + it('should remove the available listener on error', () => { sessionPool.options.acquireTimeout = 100; const promise = sessionPool._getSession('readonly'); assert.strictEqual(sessionPool.listenerCount('available'), 1); - return promise.then(shouldNotBeCalled, function() { + return promise.then(shouldNotBeCalled, () => { assert.strictEqual(sessionPool.listenerCount('available'), 0); }); }); }); - describe('_isValidSession', function() { - it('should return true if the session is good', function() { + describe('_isValidSession', () => { + it('should return true if the session is good', () => { const fakeSession = {lastUsed: Date.now()}; const isValid = sessionPool._isValidSession(fakeSession); assert.strictEqual(isValid, true); }); - it('should return true if the session has gone bad', function() { + it('should return true if the session has gone bad', () => { const fakeSession = {lastUsed: Date.now - 61 * 60000}; const isValid = sessionPool._isValidSession(fakeSession); @@ -1281,14 +1279,14 @@ describe('SessionPool', function() { }); }); - describe('_ping', function() { - beforeEach(function() { + describe('_ping', () => { + beforeEach(() => { sessionPool._borrow = function(session) { sessionPool._inventory.borrowed.add(session); }; }); - it('should borrow the session', function() { + it('should borrow the session', () => { const fakeSession = new FakeSession(); sessionPool._borrow = function(session) { @@ -1298,12 +1296,12 @@ describe('SessionPool', function() { sessionPool._ping(fakeSession); }); - it('should discard it if expired', function() { + it('should discard it if expired', () => { const fakeSession = new FakeSession(); fakeSession.lastUsed = Date.now() - 61 * 60000; - return sessionPool._ping(fakeSession).then(function() { + return sessionPool._ping(fakeSession).then(() => { const inPool = sessionPool._inventory.borrowed.has(fakeSession); assert.strictEqual(inPool, false); @@ -1311,7 +1309,7 @@ describe('SessionPool', function() { }); }); - it('should keep alive the session then release it', function() { + it('should keep alive the session then release it', () => { const fakeSession = new FakeSession(); fakeSession.lastUsed = Date.now(); @@ -1323,13 +1321,13 @@ describe('SessionPool', function() { released = true; }; - return sessionPool._ping(fakeSession).then(function() { + return sessionPool._ping(fakeSession).then(() => { assert.strictEqual(fakeSession.keptAlive, true); assert.strictEqual(released, true); }); }); - it('should destroy the session if the ping fails', function() { + it('should destroy the session if the ping fails', () => { const fakeSession = new FakeSession(); fakeSession.lastUsed = Date.now(); @@ -1343,7 +1341,7 @@ describe('SessionPool', function() { destroyed = true; }; - return sessionPool._ping(fakeSession).then(function() { + return sessionPool._ping(fakeSession).then(() => { const inPool = sessionPool._inventory.borrowed.has(fakeSession); assert.strictEqual(inPool, false); @@ -1352,8 +1350,8 @@ describe('SessionPool', function() { }); }); - describe('_pingIdleSessions', function() { - it('should ping each idle session', function() { + describe('_pingIdleSessions', () => { + it('should ping each idle session', () => { const fakeSessions = [{}, {}, {}]; sessionPool._getIdleSessions = function() { @@ -1369,12 +1367,12 @@ describe('SessionPool', function() { sessionPool._fill = noop; - return sessionPool._pingIdleSessions().then(function() { + return sessionPool._pingIdleSessions().then(() => { assert.strictEqual(pingCalls, 3); }); }); - it('should fill the pool after pinging', function() { + it('should fill the pool after pinging', () => { let filled = false; sessionPool._fill = function() { @@ -1385,28 +1383,26 @@ describe('SessionPool', function() { return []; }; - return sessionPool._pingIdleSessions().then(function() { + return sessionPool._pingIdleSessions().then(() => { assert.strictEqual(filled, true); }); }); }); - describe('_prepareTransaction', function() { - it('should prepare a transaction', function() { + describe('_prepareTransaction', () => { + it('should prepare a transaction', () => { const fakeSession = new FakeSession(); const options = {}; - return sessionPool - ._prepareTransaction(fakeSession, options) - .then(function() { - assert(fakeSession.txn instanceof FakeTransaction); - assert.strictEqual(fakeSession.txn.options, options); - }); + return sessionPool._prepareTransaction(fakeSession, options).then(() => { + assert(fakeSession.txn instanceof FakeTransaction); + assert.strictEqual(fakeSession.txn.options, options); + }); }); }); - describe('_release', function() { - it('should release the session', function() { + describe('_release', () => { + it('should release the session', () => { const inv = sessionPool._inventory; const fakeSession = {type: 'readonly'}; @@ -1417,7 +1413,7 @@ describe('SessionPool', function() { assert.strictEqual(inv.readonly.indexOf(fakeSession), 0); }); - it('should delete any stack traces', function() { + it('should delete any stack traces', () => { const id = 'abc'; const fakeSession = {type: 'readonly', id}; @@ -1427,7 +1423,7 @@ describe('SessionPool', function() { assert.strictEqual(sessionPool._traces.has(id), false); }); - it('should emit the available event', function(done) { + it('should emit the available event', done => { const fakeSession = {type: 'readonly'}; sessionPool.on('available', done); @@ -1435,18 +1431,18 @@ describe('SessionPool', function() { }); }); - describe('_startHouseKeeping', function() { + describe('_startHouseKeeping', () => { let _setInterval; - before(function() { + before(() => { _setInterval = global.setInterval; }); - afterEach(function() { + afterEach(() => { global.setInterval = _setInterval; }); - it('should set an interval to evict idle sessions', function(done) { + it('should set an interval to evict idle sessions', done => { const callIndex = 0; const expectedInterval = sessionPool.options.idlesAfter * 60000; @@ -1478,7 +1474,7 @@ describe('SessionPool', function() { sessionPool._startHouseKeeping(); }); - it('should set an interval to ping sessions', function(done) { + it('should set an interval to ping sessions', done => { const callIndex = 1; const expectedInterval = sessionPool.options.keepAlive * 60000; @@ -1511,18 +1507,18 @@ describe('SessionPool', function() { }); }); - describe('_stopHouseKeeping', function() { + describe('_stopHouseKeeping', () => { let _clearInterval; - before(function() { + before(() => { _clearInterval = global.clearInterval; }); - afterEach(function() { + afterEach(() => { global.clearInterval = _clearInterval; }); - it('should clear the intervals', function() { + it('should clear the intervals', () => { sessionPool._pingHandle = 'a'; sessionPool._evictHandle = 'b'; diff --git a/test/session.js b/test/session.js index c7b9aa1a0..1b1a8964c 100644 --- a/test/session.js +++ b/test/session.js @@ -46,7 +46,7 @@ function FakeTransaction() { this.calledWith_ = arguments; } -describe('Session', function() { +describe('Session', () => { let Session; let session; @@ -57,7 +57,7 @@ describe('Session', function() { const NAME = 'session-name'; - before(function() { + before(() => { Session = proxyquire('../src/session.js', { '@google-cloud/common-grpc': { ServiceObject: FakeGrpcServiceObject, @@ -67,24 +67,24 @@ describe('Session', function() { }); }); - beforeEach(function() { + beforeEach(() => { session = new Session(DATABASE, NAME); }); - describe('instantiation', function() { - it('should promisify all the things', function() { + describe('instantiation', () => { + it('should promisify all the things', () => { assert(promisified); }); - it('should localize the request function', function() { + it('should localize the request function', () => { assert.strictEqual(session.request, DATABASE.request); }); - it('should localize the requestStream function', function() { + it('should localize the requestStream function', () => { assert.strictEqual(session.requestStream, DATABASE.requestStream); }); - it('should format the name', function() { + it('should format the name', () => { const formatName_ = Session.formatName_; const formattedName = 'formatted-name'; @@ -101,7 +101,7 @@ describe('Session', function() { assert(instance.formattedName_, formattedName); }); - it('should inherit from ServiceObject', function() { + it('should inherit from ServiceObject', () => { assert(session instanceof FakeGrpcServiceObject); const calledWith = session.calledWith_[0]; @@ -115,8 +115,8 @@ describe('Session', function() { }); }); - describe('createMethod', function() { - it('should create and return a Session', function(done) { + describe('createMethod', () => { + it('should create and return a Session', done => { const options = {}; const apiResponse = {}; @@ -135,7 +135,7 @@ describe('Session', function() { const session = new Session(databaseInstance, NAME); assert(session instanceof FakeGrpcServiceObject); - session.calledWith_[0].createMethod(options, function(err, sess, resp) { + session.calledWith_[0].createMethod(options, (err, sess, resp) => { assert.ifError(err); assert.strictEqual(sess, session); @@ -148,7 +148,7 @@ describe('Session', function() { }); }); - it('should return an error from creating a Session', function(done) { + it('should return an error from creating a Session', done => { const error = new Error('Error.'); const apiResponse = {}; @@ -161,7 +161,7 @@ describe('Session', function() { const session = new Session(databaseInstance, NAME); assert(session instanceof FakeGrpcServiceObject); - session.calledWith_[0].createMethod({}, function(err, sess, resp) { + session.calledWith_[0].createMethod({}, (err, sess, resp) => { assert.strictEqual(err, error); assert.strictEqual(sess, null); assert.strictEqual(resp, apiResponse); @@ -171,33 +171,33 @@ describe('Session', function() { }); }); - describe('formatName_', function() { + describe('formatName_', () => { const PATH = DATABASE.formattedName_ + '/sessions/' + NAME; - it('should return the name if already formatted', function() { + it('should return the name if already formatted', () => { assert.strictEqual( Session.formatName_(DATABASE.formattedName_, PATH), PATH ); }); - it('should format the name', function() { + it('should format the name', () => { const formattedName = Session.formatName_(DATABASE.formattedName_, NAME); assert.strictEqual(formattedName, PATH); }); }); - describe('beginTransaction', function() { + describe('beginTransaction', () => { let TRANSACTION; let RESPONSE; - beforeEach(function() { + beforeEach(() => { TRANSACTION = {begin: util.noop}; RESPONSE = {}; session.transaction = () => TRANSACTION; }); - it('should pass the transaction options', function(done) { + it('should pass the transaction options', done => { const OPTIONS = {}; session.transaction = function(options) { @@ -208,12 +208,12 @@ describe('Session', function() { session.beginTransaction(OPTIONS, assert.ifError); }); - it('should begin a transaction', function(done) { + it('should begin a transaction', done => { TRANSACTION.begin = function(callback) { callback(null, RESPONSE); }; - session.beginTransaction(function(err, transaction, response) { + session.beginTransaction((err, transaction, response) => { assert.ifError(err); assert.strictEqual(transaction, TRANSACTION); assert.strictEqual(response, RESPONSE); @@ -221,14 +221,14 @@ describe('Session', function() { }); }); - it('should return any api errors', function(done) { + it('should return any api errors', done => { const ERROR = new Error('err'); TRANSACTION.begin = function(callback) { callback(ERROR, RESPONSE); }; - session.beginTransaction(function(err, transaction, response) { + session.beginTransaction((err, transaction, response) => { assert.strictEqual(err, ERROR); assert.strictEqual(transaction, null); assert.strictEqual(response, RESPONSE); @@ -237,8 +237,8 @@ describe('Session', function() { }); }); - describe('delete', function() { - it('should correctly call and return the request', function() { + describe('delete', () => { + it('should correctly call and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -258,8 +258,8 @@ describe('Session', function() { }); }); - describe('getMetadata', function() { - it('should correctly call and return the request', function() { + describe('getMetadata', () => { + it('should correctly call and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -279,8 +279,8 @@ describe('Session', function() { }); }); - describe('keepAlive', function() { - it('should correctly call and return the request', function() { + describe('keepAlive', () => { + it('should correctly call and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -301,10 +301,10 @@ describe('Session', function() { }); }); - describe('transaction', function() { + describe('transaction', () => { const ID = 'transaction-id'; - it('should return a Transaction object', function() { + it('should return a Transaction object', () => { const transaction = session.transaction(ID); assert(transaction instanceof FakeTransaction); assert.strictEqual(transaction.calledWith_[0], session); diff --git a/test/table.js b/test/table.js index cc18288d0..95dc4ad73 100644 --- a/test/table.js +++ b/test/table.js @@ -37,7 +37,7 @@ const fakePfy = extend({}, pfy, { function FakeTransactionRequest() {} -describe('Table', function() { +describe('Table', () => { let Table; let TableCached; let table; @@ -54,7 +54,7 @@ describe('Table', function() { const NAME = 'table-name'; - before(function() { + before(() => { Table = proxyquire('../src/table.js', { '@google-cloud/promisify': fakePfy, './transaction-request.js': FakeTransactionRequest, @@ -62,43 +62,43 @@ describe('Table', function() { TableCached = extend({}, Table); }); - beforeEach(function() { + beforeEach(() => { extend(Table, TableCached); table = new Table(DATABASE, NAME); }); - describe('instantiation', function() { - it('should promisify all the things', function() { + describe('instantiation', () => { + it('should promisify all the things', () => { assert(promisified); }); - it('should localize API', function() { + it('should localize API', () => { assert.strictEqual(table.api, DATABASE.api); }); - it('should localize database', function() { + it('should localize database', () => { assert.strictEqual(table.database, DATABASE); }); - it('should localize name', function() { + it('should localize name', () => { assert.strictEqual(table.name, NAME); }); - it('should localize request from pool', function() { + it('should localize request from pool', () => { assert.strictEqual(table.request(), util.noop); }); - it('should localize requestStream from pool', function() { + it('should localize requestStream from pool', () => { assert.strictEqual(table.requestStream(), util.noop); }); - it('should inherit from TransactionRequest', function() { + it('should inherit from TransactionRequest', () => { assert(table instanceof FakeTransactionRequest); }); }); - describe('create', function() { - it('should create a table from the database', function(done) { + describe('create', () => { + it('should create a table from the database', done => { const schema = 'schema'; table.database = { @@ -112,8 +112,8 @@ describe('Table', function() { }); }); - describe('createReadStream', function() { - it('should call and return parent method', function() { + describe('createReadStream', () => { + it('should call and return parent method', () => { const query = 'SELECT * from Everything'; const parentMethodReturnValue = {}; @@ -133,7 +133,7 @@ describe('Table', function() { assert.strictEqual(readStream, parentMethodReturnValue); }); - it('should accept an array of keys', function(done) { + it('should accept an array of keys', done => { const QUERY = ['a', 'b']; FakeTransactionRequest.prototype = { @@ -146,7 +146,7 @@ describe('Table', function() { table.createReadStream(QUERY); }); - it('should support timestamp options', function(done) { + it('should support timestamp options', done => { const QUERY = 'SELECT * from Everything'; const OPTIONS = {}; const FORMATTED_OPTIONS = {}; @@ -177,20 +177,20 @@ describe('Table', function() { }); }); - describe('delete', function() { - it('should throw an error if any arguments are provided', function() { + describe('delete', () => { + it('should throw an error if any arguments are provided', () => { const expectedErr = /Unexpected argument, please see Table#deleteRows to delete rows\./; assert.throws(() => table.delete([]), expectedErr); }); - it('should update the schema on the database', function() { + it('should update the schema on the database', () => { const updateSchemaReturnValue = {}; function callback() {} table.database = { - updateSchema: function(schema, callback_) { + updateSchema: (schema, callback_) => { assert.strictEqual(schema, 'DROP TABLE `' + table.name + '`'); assert.strictEqual(callback_, callback); return updateSchemaReturnValue; @@ -202,8 +202,8 @@ describe('Table', function() { }); }); - describe('deleteRows', function() { - it('should call and return parent method', function() { + describe('deleteRows', () => { + it('should call and return parent method', () => { const keys = []; function callback() {} @@ -225,11 +225,11 @@ describe('Table', function() { }); }); - describe('drop', function() { - it('should call through to Table#delete', function(done) { + describe('drop', () => { + it('should call through to Table#delete', done => { const returnVal = Promise.resolve(); - table.delete = function(callback) { + table.delete = callback => { setImmediate(callback); // the done fn return returnVal; }; @@ -240,15 +240,15 @@ describe('Table', function() { }); }); - describe('insert', function() { - it('should call and return mutate_ method', function() { + describe('insert', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const keyVals = []; function callback() {} - table.mutate_ = function(method, name, keyVals_, callback_) { + table.mutate_ = (method, name, keyVals_, callback_) => { assert.strictEqual(method, 'insert'); assert.strictEqual(name, table.name); assert.strictEqual(keyVals_, keyVals); @@ -261,8 +261,8 @@ describe('Table', function() { }); }); - describe('read', function() { - it('should call and collect results from a stream', function(done) { + describe('read', () => { + it('should call and collect results from a stream', done => { const keyVals = []; const rows = [{}, {}]; @@ -273,8 +273,8 @@ describe('Table', function() { const stream = through.obj(); - setImmediate(function() { - split(rows, stream).then(function() { + setImmediate(() => { + split(rows, stream).then(() => { stream.end(); }); }); @@ -282,14 +282,14 @@ describe('Table', function() { return stream; }; - table.read(keyVals, function(err, rows_) { + table.read(keyVals, (err, rows_) => { assert.ifError(err); assert.deepStrictEqual(rows_, rows); done(); }); }); - it('should accept an options object', function(done) { + it('should accept an options object', done => { const OPTIONS = {}; table.createReadStream = function(keyVals, options) { @@ -297,7 +297,7 @@ describe('Table', function() { const stream = through.obj(); - setImmediate(function() { + setImmediate(() => { stream.end(); }); @@ -307,28 +307,28 @@ describe('Table', function() { table.read([], OPTIONS, done); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); table.createReadStream = function() { const stream = through.obj(); - setImmediate(function() { + setImmediate(() => { stream.destroy(error); }); return stream; }; - table.read([], function(err) { + table.read([], err => { assert.strictEqual(err, error); done(); }); }); }); - describe('replace', function() { - it('should call and return mutate_ method', function() { + describe('replace', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const keyVals = []; @@ -348,8 +348,8 @@ describe('Table', function() { }); }); - describe('update', function() { - it('should call and return mutate_ method', function() { + describe('update', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const keyVals = []; @@ -369,8 +369,8 @@ describe('Table', function() { }); }); - describe('upsert', function() { - it('should call and return mutate_ method', function() { + describe('upsert', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const keyVals = []; diff --git a/test/transaction-request.js b/test/transaction-request.js index 63f92b7a1..b5fe44646 100644 --- a/test/transaction-request.js +++ b/test/transaction-request.js @@ -48,11 +48,11 @@ const fakeCodec = { encode: util.noop, }; -describe('TransactionRequest', function() { +describe('TransactionRequest', () => { let TransactionRequest; let transactionRequest; - before(function() { + before(() => { TransactionRequest = proxyquire('../src/transaction-request', { '@google-cloud/common-grpc': { Service: FakeGrpcService, @@ -63,7 +63,7 @@ describe('TransactionRequest', function() { }); }); - beforeEach(function() { + beforeEach(() => { FakeGrpcService.encodeValue_ = util.noop; fakeCodec.encode = util.noop; transactionRequest = new TransactionRequest(); @@ -71,26 +71,26 @@ describe('TransactionRequest', function() { transactionRequest.requestStream = util.noop; }); - describe('instantiation', function() { + describe('instantiation', () => { let formatTimestamp; - before(function() { + before(() => { formatTimestamp = TransactionRequest.formatTimestampOptions_; }); - beforeEach(function() { + beforeEach(() => { TransactionRequest.formatTimestampOptions_ = function() {}; }); - after(function() { + after(() => { TransactionRequest.formatTimestampOptions_ = formatTimestamp; }); - it('should default readOnly to false', function() { + it('should default readOnly to false', () => { assert.strictEqual(transactionRequest.readOnly, false); }); - it('should localize the transaction options', function() { + it('should localize the transaction options', () => { const UNFORMATTED_OPTIONS = { b: 'b', }; @@ -111,7 +111,7 @@ describe('TransactionRequest', function() { TransactionRequest.formatTimestampOptions_ = formatTimestamp; }); - it('should not localize an empty options object', function() { + it('should not localize an empty options object', () => { const formatTimestamp = TransactionRequest.formatTimestampOptions_; TransactionRequest.formatTimestampOptions_ = function() { @@ -124,7 +124,7 @@ describe('TransactionRequest', function() { TransactionRequest.formatTimestampOptions_ = formatTimestamp; }); - it('should capture the readOnly option', function() { + it('should capture the readOnly option', () => { TransactionRequest.formatTimestampOptions_ = function(options) { assert.strictEqual(options.readOnly, undefined); }; @@ -136,13 +136,13 @@ describe('TransactionRequest', function() { assert.strictEqual(transaction.readOnly, true); }); - it('should promisify all the things', function() { + it('should promisify all the things', () => { assert(promisified); }); }); - describe('formatTimestampOptions_', function() { - it('should format all the options', function() { + describe('formatTimestampOptions_', () => { + it('should format all the options', () => { const options = { strong: true, minReadTimestamp: new Date('2016-12-04'), @@ -178,8 +178,8 @@ describe('TransactionRequest', function() { }); }); - describe('fromProtoTimestamp_', function() { - it('should format into a date object', function() { + describe('fromProtoTimestamp_', () => { + it('should format into a date object', () => { const now = new Date(); const protoTimestamp = { @@ -193,17 +193,17 @@ describe('TransactionRequest', function() { }); }); - describe('createReadStream', function() { + describe('createReadStream', () => { const TABLE = 'table-name'; const QUERY = {e: 'f'}; - beforeEach(function() { + beforeEach(() => { fakeCodec.encodeRead = function() { return QUERY; }; }); - it('should accept a query object', function(done) { + it('should accept a query object', done => { const query = { a: 'b', c: 'd', @@ -228,7 +228,7 @@ describe('TransactionRequest', function() { makeRequestFn(); }); - it('should set the transaction id', function(done) { + it('should set the transaction id', done => { const ID = 'abc'; transactionRequest.transaction = true; @@ -255,13 +255,13 @@ describe('TransactionRequest', function() { makeRequestFn(); }); - describe('PartialResultStream', function() { - it('should return PartialResultStream', function() { + describe('PartialResultStream', () => { + it('should return PartialResultStream', () => { const stream = transactionRequest.createReadStream(TABLE, QUERY); assert(stream instanceof FakePartialResultStream); }); - it('should make and return the correct request', function(done) { + it('should make and return the correct request', done => { const query = { a: 'b', }; @@ -284,7 +284,7 @@ describe('TransactionRequest', function() { makeRequestFn(); }); - it('should respect gaxOptions', function(done) { + it('should respect gaxOptions', done => { const query = { gaxOptions: {}, }; @@ -299,7 +299,7 @@ describe('TransactionRequest', function() { makeRequestFn(); }); - it('should assign a resumeToken to the request', function(done) { + it('should assign a resumeToken to the request', done => { const resumeToken = 'resume-token'; transactionRequest.requestStream = function(config) { @@ -312,7 +312,7 @@ describe('TransactionRequest', function() { makeRequestFn(resumeToken); }); - it('should accept json and jsonOptions', function() { + it('should accept json and jsonOptions', () => { const query = { json: {}, jsonOptions: {}, @@ -325,7 +325,7 @@ describe('TransactionRequest', function() { assert.strictEqual(streamOptions.jsonOptions, query.jsonOptions); }); - it('should delete json, jsonOptions from reqOpts', function(done) { + it('should delete json, jsonOptions from reqOpts', done => { const query = { json: {}, jsonOptions: {}, @@ -344,7 +344,7 @@ describe('TransactionRequest', function() { }); }); - describe('deleteRows', function() { + describe('deleteRows', () => { const TABLE = 'table-name'; const KEYS = ['key', ['composite', 'key']]; @@ -368,13 +368,13 @@ describe('TransactionRequest', function() { }, }; - beforeEach(function() { + beforeEach(() => { fakeCodec.encode = function() { return ENCODED_VALUE; }; }); - it('should correctly make and return the request', function() { + it('should correctly make and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -421,7 +421,7 @@ describe('TransactionRequest', function() { assert.strictEqual(returnValue, requestReturnValue); }); - it('should push the request to the queue if a transaction', function(done) { + it('should push the request to the queue if a transaction', done => { transactionRequest.transaction = true; transactionRequest.queue_ = function(mutation) { @@ -432,7 +432,7 @@ describe('TransactionRequest', function() { transactionRequest.deleteRows(TABLE, KEYS, assert.ifError); }); - it('should accept just a key', function(done) { + it('should accept just a key', done => { transactionRequest.transaction = true; const encodedValue = { @@ -457,8 +457,8 @@ describe('TransactionRequest', function() { }); }); - describe('insert', function() { - it('should call and return mutate_ method', function() { + describe('insert', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const table = 'table-name'; @@ -478,8 +478,8 @@ describe('TransactionRequest', function() { }); }); - describe('read', function() { - it('should call and collect results from a stream', function(done) { + describe('read', () => { + it('should call and collect results from a stream', done => { const table = 'table-name'; const keyVals = []; @@ -491,8 +491,8 @@ describe('TransactionRequest', function() { const stream = through.obj(); - setImmediate(function() { - split(rows, stream).then(function() { + setImmediate(() => { + split(rows, stream).then(() => { stream.end(); }); }); @@ -500,35 +500,35 @@ describe('TransactionRequest', function() { return stream; }; - transactionRequest.read(table, keyVals, function(err, rows_) { + transactionRequest.read(table, keyVals, (err, rows_) => { assert.ifError(err); assert.deepStrictEqual(rows_, rows); done(); }); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); transactionRequest.createReadStream = function() { const stream = through.obj(); - setImmediate(function() { + setImmediate(() => { stream.destroy(error); }); return stream; }; - transactionRequest.read('table-name', [], function(err) { + transactionRequest.read('table-name', [], err => { assert.strictEqual(err, error); done(); }); }); }); - describe('replace', function() { - it('should call and return mutate_ method', function() { + describe('replace', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const table = 'table-name'; @@ -548,8 +548,8 @@ describe('TransactionRequest', function() { }); }); - describe('update', function() { - it('should call and return mutate_ method', function() { + describe('update', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const table = 'table-name'; @@ -569,8 +569,8 @@ describe('TransactionRequest', function() { }); }); - describe('upsert', function() { - it('should call and return mutate_ method', function() { + describe('upsert', () => { + it('should call and return mutate_ method', () => { const mutateReturnValue = {}; const table = 'table-name'; @@ -590,7 +590,7 @@ describe('TransactionRequest', function() { }); }); - describe('mutate_', function() { + describe('mutate_', () => { const METHOD = 'methodName'; const TABLE = 'table-name'; const KEYVALS = [ @@ -633,13 +633,13 @@ describe('TransactionRequest', function() { ], }; - beforeEach(function() { + beforeEach(() => { fakeCodec.encode = function(value) { return value; }; }); - it('should correctly make and return the request', function() { + it('should correctly make and return the request', () => { const requestReturnValue = {}; function callback() {} @@ -710,7 +710,7 @@ describe('TransactionRequest', function() { assert.strictEqual(returnValue, requestReturnValue); }); - it('should throw when rows have incorrect amount of columns', function() { + it('should throw when rows have incorrect amount of columns', () => { const invalidEntry = {key1: 'val'}; let caughtError; @@ -737,7 +737,7 @@ describe('TransactionRequest', function() { assert.strictEqual(caughtError.message, expectedErrorMessage); }); - it('should push the request to the queue if a transaction', function(done) { + it('should push the request to the queue if a transaction', done => { transactionRequest.transaction = true; transactionRequest.queue_ = function(mutation) { @@ -748,7 +748,7 @@ describe('TransactionRequest', function() { transactionRequest.mutate_(METHOD, TABLE, KEYVALS, assert.ifError); }); - it('should accept just a key', function(done) { + it('should accept just a key', done => { transactionRequest.transaction = true; transactionRequest.queue_ = function(mutation) { diff --git a/test/transaction.js b/test/transaction.js index 2116d5e47..3bb144941 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -86,7 +86,7 @@ const fakeConfig = { }, }; -describe('Transaction', function() { +describe('Transaction', () => { let TransactionCached; let Transaction; let transaction; @@ -98,7 +98,7 @@ describe('Transaction', function() { const ID = 'transaction-id'; - before(function() { + before(() => { Transaction = proxyquire('../src/transaction', { 'google-gax': fakeGax, '@google-cloud/common-grpc': { @@ -114,7 +114,7 @@ describe('Transaction', function() { TransactionCached = extend({}, Transaction); }); - beforeEach(function() { + beforeEach(() => { FakeGrpcService.objToStruct_ = util.noop; FakeRetryInfo.decode = util.noop; @@ -122,36 +122,36 @@ describe('Transaction', function() { transaction = new Transaction(SESSION); }); - describe('instantiation', function() { - it('should promisify all the things', function() { + describe('instantiation', () => { + it('should promisify all the things', () => { assert(promisified); }); - it('should localize the session', function() { + it('should localize the session', () => { assert.strictEqual(transaction.session, SESSION); }); - it('should set flag to identify as a Transaction object', function() { + it('should set flag to identify as a Transaction object', () => { assert.strictEqual(transaction.transaction, true); }); - it('should track the number of attempts made', function() { + it('should track the number of attempts made', () => { assert.strictEqual(transaction.attempts_, 0); }); - it('should initialize an empty queue', function() { + it('should initialize an empty queue', () => { assert.deepStrictEqual(transaction.queuedMutations_, []); }); - it('should initialize a null run function', function() { + it('should initialize a null run function', () => { assert.strictEqual(transaction.runFn_, null); }); - it('should set ended_ to false', function() { + it('should set ended_ to false', () => { assert.strictEqual(transaction.ended_, false); }); - it('should inherit from TransactionRequest', function() { + it('should inherit from TransactionRequest', () => { const OPTIONS = {}; transaction = new Transaction(SESSION, OPTIONS); @@ -160,12 +160,12 @@ describe('Transaction', function() { assert(transaction.calledWith_[0], OPTIONS); }); - describe('timeout_', function() { - it('should default to the commit timeout', function() { + describe('timeout_', () => { + it('should default to the commit timeout', () => { assert.strictEqual(transaction.timeout_, FAKE_COMMIT_TIMEOUT); }); - it('should capture the user timeout', function() { + it('should capture the user timeout', () => { const timeout = 321; const transaction = new Transaction(SESSION, {timeout}); @@ -174,14 +174,14 @@ describe('Transaction', function() { assert.deepStrictEqual(transaction.calledWith_[0], {}); }); - it('should ignore non-number values', function() { + it('should ignore non-number values', () => { const timeout = 'abc'; const transaction = new Transaction(SESSION, {timeout}); assert.strictEqual(transaction.timeout_, FAKE_COMMIT_TIMEOUT); }); - it('should not alter user options', function() { + it('should not alter user options', () => { const options = {timeout: 1234}; const optionsCopy = Object.assign({}, options); const transaction = new Transaction(SESSION, options); @@ -192,8 +192,8 @@ describe('Transaction', function() { }); }); - describe('createDeadlineError_', function() { - it('should augment the error', function() { + describe('createDeadlineError_', () => { + it('should augment the error', () => { const originalError = { code: 10, message: 'Transaction aborted.', @@ -214,8 +214,8 @@ describe('Transaction', function() { }); }); - describe('getRetryDelay_', function() { - it('should return the retry delay when available', function() { + describe('getRetryDelay_', () => { + it('should return the retry delay when available', () => { const fakeError = new Error('err'); const fakeRetryInfo = Buffer.from('hi'); @@ -250,7 +250,7 @@ describe('Transaction', function() { assert.strictEqual(delay, expectedDelay); }); - it('should create backoff from counter when delay is absent', function() { + it('should create backoff from counter when delay is absent', () => { const fakeError = new Error('err'); fakeError.metadata = { @@ -277,7 +277,7 @@ describe('Transaction', function() { }); }); - describe('begin', function() { + describe('begin', () => { const OPTIONS = { readOnly: true, boundOptions: true, @@ -290,7 +290,7 @@ describe('Transaction', function() { }, }; - it('should make the correct request', function(done) { + it('should make the correct request', done => { const transaction = new Transaction(SESSION, OPTIONS); transaction.readOnly = true; @@ -304,7 +304,7 @@ describe('Transaction', function() { transaction.begin(assert.ifError); }); - it('should not require options', function(done) { + it('should not require options', done => { transaction.readOnly = false; transaction.request = function(config) { assert.deepStrictEqual(config.reqOpts, { @@ -318,71 +318,71 @@ describe('Transaction', function() { transaction.begin(assert.ifError); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); transaction.request = function(config, callback) { callback(error); }; - transaction.begin(function(err) { + transaction.begin(err => { assert.strictEqual(err, error); done(); }); }); - describe('success', function() { + describe('success', () => { const API_RESPONSE = { id: 'transaction-id', }; - beforeEach(function() { + beforeEach(() => { transaction.request = function(config, callback) { callback(null, API_RESPONSE); }; }); - it('should increment the attempts property', function(done) { - transaction.begin(function(err) { + it('should increment the attempts property', done => { + transaction.begin(err => { assert.ifError(err); assert.strictEqual(transaction.attempts_, 1); done(); }); }); - it('should set ended_ to false', function(done) { - transaction.begin(function(err) { + it('should set ended_ to false', done => { + transaction.begin(err => { assert.ifError(err); assert.strictEqual(transaction.ended_, false); done(); }); }); - it('should update ID', function(done) { - transaction.begin(function(err) { + it('should update ID', done => { + transaction.begin(err => { assert.ifError(err); assert.strictEqual(transaction.id, API_RESPONSE.id); done(); }); }); - it('should update metadata', function(done) { - transaction.begin(function(err) { + it('should update metadata', done => { + transaction.begin(err => { assert.ifError(err); assert.strictEqual(transaction.metadata, API_RESPONSE); done(); }); }); - it('should execute callback with API response', function(done) { - transaction.begin(function(err, apiResponse) { + it('should execute callback with API response', done => { + transaction.begin((err, apiResponse) => { assert.ifError(err); assert.strictEqual(apiResponse, API_RESPONSE); done(); }); }); - it('should set the timestamp if applicable', function(done) { + it('should set the timestamp if applicable', done => { const fakeProtoTimestamp = {}; const fakeDate = new Date(); @@ -403,7 +403,7 @@ describe('Transaction', function() { return fakeDate; }; - transaction.begin(function(err) { + transaction.begin(err => { assert.ifError(err); assert.strictEqual(transaction.readTimestamp, fakeDate); done(); @@ -412,22 +412,22 @@ describe('Transaction', function() { }); }); - describe('commit', function() { + describe('commit', () => { const QUEUED_MUTATIONS = [{}]; - beforeEach(function() { + beforeEach(() => { transaction.queuedMutations_ = QUEUED_MUTATIONS; }); - it('should throw an error if the transaction was ended', function() { + it('should throw an error if the transaction was ended', () => { transaction.ended_ = true; - assert.throws(function() { + assert.throws(() => { transaction.commit(assert.ifError); }, /Transaction has already been ended\./); }); - it('should make the correct request with an ID', function(done) { + it('should make the correct request with an ID', done => { transaction.id = 'transaction-id'; transaction.request = function(config) { @@ -444,7 +444,7 @@ describe('Transaction', function() { transaction.commit(assert.ifError); }); - it('should make the correct request without an ID', function(done) { + it('should make the correct request without an ID', done => { delete transaction.id; transaction.request = function(config) { @@ -460,18 +460,18 @@ describe('Transaction', function() { transaction.commit(assert.ifError); }); - describe('error', function() { + describe('error', () => { const ERROR = new Error('Error.'); const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { transaction.request = function(config, callback) { callback(ERROR, API_RESPONSE); }; }); - it('should execute callback with error and API response', function(done) { - transaction.commit(function(err, apiResponse) { + it('should execute callback with error and API response', done => { + transaction.commit((err, apiResponse) => { assert.strictEqual(err, ERROR); assert.strictEqual(apiResponse, API_RESPONSE); done(); @@ -479,22 +479,22 @@ describe('Transaction', function() { }); }); - describe('success', function() { + describe('success', () => { const API_RESPONSE = {}; - beforeEach(function() { + beforeEach(() => { transaction.request = function(config, callback) { callback(null, API_RESPONSE); }; }); - it('should destroy the transaction', function(done) { + it('should destroy the transaction', done => { transaction.end = done; transaction.commit(assert.ifError); }); - it('should execute callback with the API response', function(done) { - transaction.commit(function(err, apiResponse) { + it('should execute callback with the API response', done => { + transaction.commit((err, apiResponse) => { assert.ifError(err); assert.strictEqual(apiResponse, API_RESPONSE); done(); @@ -503,22 +503,22 @@ describe('Transaction', function() { }); }); - describe('end', function() { - it('should throw an error if the transaction was ended', function() { + describe('end', () => { + it('should throw an error if the transaction was ended', () => { transaction.ended_ = true; - assert.throws(function() { + assert.throws(() => { transaction.end(assert.ifError); }, /Transaction has already been ended\./); }); - it('should set ended_ to true', function() { + it('should set ended_ to true', () => { transaction.end(); assert.strictEqual(transaction.ended_, true); }); - it('should empty the queue', function() { + it('should empty the queue', () => { transaction.queuedMutations_ = [{}, {}]; transaction.end(); @@ -526,7 +526,7 @@ describe('Transaction', function() { assert.strictEqual(transaction.queuedMutations_.length, 0); }); - it('should nullify the run function', function() { + it('should nullify the run function', () => { transaction.runFn_ = function() {}; transaction.end(); @@ -534,14 +534,14 @@ describe('Transaction', function() { assert.strictEqual(transaction.runFn_, null); }); - it('should reset the attempts property', function() { + it('should reset the attempts property', () => { transaction.attempts_ = 100; transaction.end(); assert.strictEqual(transaction.attempts_, 0); }); - it('should delete the ID', function() { + it('should delete the ID', () => { transaction.id = 'transaction-id'; transaction.end(); @@ -549,13 +549,13 @@ describe('Transaction', function() { assert.strictEqual(transaction.id, undefined); }); - it('should optionally execute a callback', function(done) { + it('should optionally execute a callback', done => { transaction.end(done); }); }); - describe('queue_', function() { - it('should push a mutation object into the queue array', function() { + describe('queue_', () => { + it('should push a mutation object into the queue array', () => { const mutation = {}; assert.deepStrictEqual(transaction.queuedMutations_, []); @@ -566,8 +566,8 @@ describe('Transaction', function() { }); }); - describe('request', function() { - it('should make the correct request', function(done) { + describe('request', () => { + it('should make the correct request', done => { const config = { reqOpts: { a: 'b', @@ -587,7 +587,7 @@ describe('Transaction', function() { transaction.request(config, assert.ifError); }); - it('should pass the response back to the callback', function(done) { + it('should pass the response back to the callback', done => { const resp = {}; const config = { @@ -598,14 +598,14 @@ describe('Transaction', function() { callback(null, resp); }; - transaction.request(config, function(err, apiResponse) { + transaction.request(config, (err, apiResponse) => { assert.ifError(err); assert.strictEqual(apiResponse, resp); done(); }); }); - describe('aborted errors', function() { + describe('aborted errors', () => { const abortedError = {code: 10}; const resp = {}; @@ -613,11 +613,11 @@ describe('Transaction', function() { const config = {}; let getRetryDelay; - before(function() { + before(() => { getRetryDelay = Transaction.getRetryDelay_; }); - beforeEach(function() { + beforeEach(() => { transaction.session.request = function(config, callback) { callback(abortedError, resp); }; @@ -627,11 +627,11 @@ describe('Transaction', function() { }; }); - after(function() { + after(() => { Transaction.getRetryDelay_ = getRetryDelay; }); - it('should pass error code to isRetryableErrorCode', function(done) { + it('should pass error code to isRetryableErrorCode', done => { transaction.runFn_ = function() {}; const config = { @@ -643,10 +643,10 @@ describe('Transaction', function() { done(); }; - transaction.request(config, function() {}); + transaction.request(config, () => {}); }); - it('should retry the txn if abort occurs', function(done) { + it('should retry the txn if abort occurs', done => { const attempts_ = 123; Transaction.getRetryDelay_ = function(err, attempts) { @@ -671,12 +671,12 @@ describe('Transaction', function() { transaction.attempts_ = attempts_; - transaction.request(config, function() { + transaction.request(config, () => { done(new Error('Should not have been called.')); }); }); - it('should return a deadline error if not retrying', function(done) { + it('should return a deadline error if not retrying', done => { transaction.retry_ = function() { done(new Error('Should not have been called.')); }; @@ -701,15 +701,15 @@ describe('Transaction', function() { done(); }; - transaction.request(config, function() { + transaction.request(config, () => { done(new Error('Should not have been called.')); }); }); - it('should return the aborted error if no runFn', function(done) { + it('should return the aborted error if no runFn', done => { transaction.runFn_ = null; - transaction.request(config, function(err) { + transaction.request(config, err => { assert.strictEqual(err, abortedError); done(); }); @@ -717,8 +717,8 @@ describe('Transaction', function() { }); }); - describe('requestStream', function() { - it('should make the correct request', function() { + describe('requestStream', () => { + it('should make the correct request', () => { const methodReturnValue = {}; const config = { @@ -742,14 +742,14 @@ describe('Transaction', function() { assert.strictEqual(returnValue, methodReturnValue); }); - describe('runTransaction mode', function() { + describe('runTransaction mode', () => { let fakeStream; const config = { reqOpts: {}, }; - beforeEach(function() { + beforeEach(() => { fakeStream = through.obj(); transaction.session.requestStream = function() { return fakeStream; @@ -757,7 +757,7 @@ describe('Transaction', function() { transaction.runFn_ = function() {}; }); - it('should pipe the request stream to the user stream', function(done) { + it('should pipe the request stream to the user stream', done => { const fakeData = { a: 'a', }; @@ -765,7 +765,7 @@ describe('Transaction', function() { transaction .requestStream(config) .on('error', done) - .on('data', function(data) { + .on('data', data => { assert.strictEqual(data, fakeData); done(); }); @@ -773,7 +773,7 @@ describe('Transaction', function() { fakeStream.push(fakeData); }); - it('should emit non-abort errors to the user stream', function(done) { + it('should emit non-abort errors to the user stream', done => { const error = new Error('ohnoes'); const userStream = transaction.requestStream(config); @@ -785,7 +785,7 @@ describe('Transaction', function() { fakeStream.emit('error', error); }); - it('isRetryableErrorCode should be called on error', function(done) { + it('isRetryableErrorCode should be called on error', done => { const error = {code: 'sentinel'}; const userStream = transaction.requestStream(config); @@ -799,7 +799,7 @@ describe('Transaction', function() { fakeStream.emit('error', error); }); - it('should retry the transaction for UNKNOWN', function(done) { + it('should retry the transaction for UNKNOWN', done => { const error = {code: 2}; const fakeDelay = 123; const attempts_ = 321; @@ -832,7 +832,7 @@ describe('Transaction', function() { fakeStream.emit('error', error); }); - it('should retry the transaction for ABORTED', function(done) { + it('should retry the transaction for ABORTED', done => { const error = {code: 10}; const fakeDelay = 123; const getRetryDelay = Transaction.getRetryDelay_; @@ -862,7 +862,7 @@ describe('Transaction', function() { fakeStream.emit('error', error); }); - it('should send a deadline error to the runFn', function(done) { + it('should send a deadline error to the runFn', done => { const error = {code: 10}; const deadlineError = {}; const createDeadlineError = Transaction.createDeadlineError_; @@ -894,20 +894,20 @@ describe('Transaction', function() { }); }); - describe('rollback', function() { - beforeEach(function() { + describe('rollback', () => { + beforeEach(() => { transaction.id = ID; }); - it('should throw if a transaction ID is not set', function() { + it('should throw if a transaction ID is not set', () => { delete transaction.id; - assert.throws(function() { + assert.throws(() => { transaction.rollback(assert.ifError); }, /Transaction ID is unknown, nothing to rollback\./); }); - it('should make the correct request', function(done) { + it('should make the correct request', done => { transaction.request = function(config) { assert.strictEqual(config.client, 'SpannerClient'); assert.strictEqual(config.method, 'rollback'); @@ -921,7 +921,7 @@ describe('Transaction', function() { transaction.rollback(assert.ifError); }); - it('should execute callback with error & API response', function(done) { + it('should execute callback with error & API response', done => { const error = new Error('Error.'); const apiResponse = {}; @@ -933,14 +933,14 @@ describe('Transaction', function() { done(new Error('Should not be destroyed.')); }; - transaction.rollback(function(err, apiResponse_) { + transaction.rollback((err, apiResponse_) => { assert.strictEqual(err, error); assert.strictEqual(apiResponse_, apiResponse); done(); }); }); - it('should destroy the transaction if rollback worked', function(done) { + it('should destroy the transaction if rollback worked', done => { const apiResponse = {}; transaction.request = function(config, callback) { @@ -952,7 +952,7 @@ describe('Transaction', function() { destroyed = true; }; - transaction.rollback(function(err, apiResponse_) { + transaction.rollback((err, apiResponse_) => { assert.strictEqual(err, null); assert.strictEqual(apiResponse_, apiResponse); assert.strictEqual(destroyed, true); @@ -961,8 +961,8 @@ describe('Transaction', function() { }); }); - describe('run', function() { - it('should call and collect results from a stream', function(done) { + describe('run', () => { + it('should call and collect results from a stream', done => { const query = {}; const rows = [{}, {}]; @@ -972,8 +972,8 @@ describe('Transaction', function() { const stream = through.obj(); - setImmediate(function() { - split(rows, stream).then(function() { + setImmediate(() => { + split(rows, stream).then(() => { stream.end(); }); }); @@ -981,33 +981,33 @@ describe('Transaction', function() { return stream; }; - transaction.run(query, function(err, rows_) { + transaction.run(query, (err, rows_) => { assert.ifError(err); assert.deepStrictEqual(rows_, rows); done(); }); }); - it('should execute callback with error', function(done) { + it('should execute callback with error', done => { const error = new Error('Error.'); transaction.runStream = function() { const stream = through.obj(); - setImmediate(function() { + setImmediate(() => { stream.destroy(error); }); return stream; }; - transaction.run({}, function(err) { + transaction.run({}, err => { assert.strictEqual(err, error); done(); }); }); - it('should return a promise when callback is not specified', function() { + it('should return a promise when callback is not specified', () => { const query = {}; const rows = [{}, {}]; @@ -1017,8 +1017,8 @@ describe('Transaction', function() { const stream = through.obj(); - setImmediate(function() { - split(rows, stream).then(function() { + setImmediate(() => { + split(rows, stream).then(() => { stream.end(); }); }); @@ -1026,13 +1026,13 @@ describe('Transaction', function() { return stream; }; - return transaction.run(query).then(function(args) { + return transaction.run(query).then(args => { assert.deepStrictEqual(args[0], rows); }); }); }); - describe('runStream', function() { + describe('runStream', () => { const QUERY = { sql: 'SELECT * FROM table', a: 'b', @@ -1051,22 +1051,22 @@ describe('Transaction', function() { }, }); - beforeEach(function() { + beforeEach(() => { transaction = new Transaction(SESSION, OPTIONS); transaction.id = ID; - fakeCodec.encodeQuery = function() { + fakeCodec.encodeQuery = () => { return ENCODED_QUERY; }; }); - it('should make the correct request', function(done) { - fakeCodec.encodeQuery = function(query) { + it('should make the correct request', done => { + fakeCodec.encodeQuery = query => { assert.strictEqual(query, QUERY); return ENCODED_QUERY; }; - transaction.requestStream = function(config) { + transaction.requestStream = config => { assert.strictEqual(config.client, 'SpannerClient'); assert.strictEqual(config.method, 'executeStreamingSql'); assert.deepStrictEqual(config.reqOpts, EXPECTED_REQ_OPTS); @@ -1078,7 +1078,7 @@ describe('Transaction', function() { makeRequestFn(); }); - it('should accept a query string', function(done) { + it('should accept a query string', done => { fakeCodec.encodeQuery = function(query) { assert.strictEqual(query.sql, QUERY.sql); return ENCODED_QUERY; @@ -1094,7 +1094,7 @@ describe('Transaction', function() { makeRequestFn(); }); - it('should not require a transaction ID', function(done) { + it('should not require a transaction ID', done => { delete transaction.id; transaction.requestStream = function(options) { @@ -1118,7 +1118,7 @@ describe('Transaction', function() { makeRequestFn(); }); - it('should not require timestamp bounds', function(done) { + it('should not require timestamp bounds', done => { delete transaction.id; delete transaction.options; @@ -1143,12 +1143,12 @@ describe('Transaction', function() { makeRequestFn(); }); - it('should return PartialResultStream', function() { + it('should return PartialResultStream', () => { const stream = transaction.runStream(QUERY, OPTIONS); assert(stream instanceof FakePartialResultStream); }); - it('should assign a resumeToken to the request', function(done) { + it('should assign a resumeToken to the request', done => { const resumeToken = 'resume-token'; transaction.requestStream = function(options) { @@ -1162,8 +1162,8 @@ describe('Transaction', function() { }); }); - describe('retry_', function() { - it('should begin the transaction', function(done) { + describe('retry_', () => { + it('should begin the transaction', done => { transaction.begin = function() { done(); }; @@ -1171,7 +1171,7 @@ describe('Transaction', function() { transaction.retry_(); }); - it('should return an error if transaction cannot begin', function(done) { + it('should return an error if transaction cannot begin', done => { const error = new Error('Error.'); transaction.begin = function(callback) { @@ -1186,15 +1186,15 @@ describe('Transaction', function() { transaction.retry_(); }); - describe('transaction began successfully', function() { + describe('transaction began successfully', () => { const fakeDelay = 1123123; let _setTimeout; - before(function() { + before(() => { _setTimeout = global.setTimeout; }); - beforeEach(function() { + beforeEach(() => { global.setTimeout = function() {}; transaction.runFn_ = function() {}; @@ -1203,18 +1203,18 @@ describe('Transaction', function() { }; }); - after(function() { + after(() => { global.setTimeout = _setTimeout; }); - it('should empty queued mutations', function() { + it('should empty queued mutations', () => { transaction.queuedMutations_ = [{}]; transaction.retry_(fakeDelay); assert.deepStrictEqual(transaction.queuedMutations_, []); }); - it('should execute run function after timeout', function(done) { + it('should execute run function after timeout', done => { global.setTimeout = function(cb, timeout) { assert.strictEqual(timeout, fakeDelay); cb(); @@ -1231,11 +1231,11 @@ describe('Transaction', function() { }); }); - describe('shouldRetry_', function() { + describe('shouldRetry_', () => { let abortedError; let unknownError; - beforeEach(function() { + beforeEach(() => { abortedError = { code: 10, metadata: { @@ -1254,7 +1254,7 @@ describe('Transaction', function() { }; }); - it('should pass error code to isRetryableErrorCode', function() { + it('should pass error code to isRetryableErrorCode', () => { const error = {code: 'sentinel'}; const isRetryableErrorCode = Transaction.isRetryableErrorCode_; @@ -1266,19 +1266,19 @@ describe('Transaction', function() { transaction.shouldRetry_(error); }); - it('should not retry if non-aborted error', function() { + it('should not retry if non-aborted error', () => { const shouldRetry = transaction.shouldRetry_({code: 4}); assert.strictEqual(shouldRetry, false); }); - it('should not retry if runFn is missing', function() { + it('should not retry if runFn is missing', () => { transaction.runFn_ = null; const shouldRetry = transaction.shouldRetry_(abortedError); assert.strictEqual(shouldRetry, false); }); - it('should not retry if deadline is exceeded', function() { + it('should not retry if deadline is exceeded', () => { transaction.timeout_ = 1; transaction.beginTime_ = Date.now() - 2; @@ -1286,7 +1286,7 @@ describe('Transaction', function() { assert.strictEqual(shouldRetry, false); }); - it('should retry if all conditions are met - Aborted', function() { + it('should retry if all conditions are met - Aborted', () => { transaction.runFn_ = function() {}; transaction.timeout_ = 1000; transaction.beginTime_ = Date.now() - 2; @@ -1299,7 +1299,7 @@ describe('Transaction', function() { assert.strictEqual(shouldRetry, true); }); - it('should retry if all conditions are met - Unknown', function() { + it('should retry if all conditions are met - Unknown', () => { transaction.runFn_ = function() {}; transaction.timeout_ = 1000; transaction.beginTime_ = Date.now() - 2; @@ -1313,21 +1313,21 @@ describe('Transaction', function() { }); }); - describe('isRetryableErrorCode_', function() { + describe('isRetryableErrorCode_', () => { const abortedErrorCode = 10; const unknownErrorCode = 2; - it('should return true for ABORTED', function() { + it('should return true for ABORTED', () => { const isRetryable = transaction.isRetryableErrorCode_(abortedErrorCode); assert.strictEqual(isRetryable, true); }); - it('should return true for UNKNOWN', function() { + it('should return true for UNKNOWN', () => { const isRetryable = transaction.isRetryableErrorCode_(unknownErrorCode); assert.strictEqual(isRetryable, true); }); - it('should return false for other error codes', function() { + it('should return false for other error codes', () => { const isRetryable = transaction.isRetryableErrorCode_(4); assert.strictEqual(isRetryable, false); });