From 20321f4f5159de08501726875e2136b39a444a89 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 7 Sep 2018 20:24:07 -0700 Subject: [PATCH] Use let and const --- samples/fluent.js | 10 +- src/entry.js | 32 +++--- src/index.js | 162 +++++++++++++------------- src/log.js | 158 +++++++++++++------------- src/metadata.js | 4 +- src/sink.js | 72 ++++++------ system-test/logging.js | 96 ++++++++-------- test/entry.js | 70 ++++++------ test/index.js | 250 ++++++++++++++++++++--------------------- test/log.js | 146 ++++++++++++------------ test/metadata.js | 68 +++++------ test/sink.js | 46 ++++---- 12 files changed, 556 insertions(+), 558 deletions(-) diff --git a/samples/fluent.js b/samples/fluent.js index 611b2228..dd34b262 100644 --- a/samples/fluent.js +++ b/samples/fluent.js @@ -15,22 +15,22 @@ 'use strict'; -var express = require('express'); -var app = express(); +const express = require('express'); +const app = express(); app.get('*', function(req, res, next) { return next('oops'); }); // [START fluent] -var structuredLogger = require('fluent-logger').createFluentSender('myapp', { +const structuredLogger = require('fluent-logger').createFluentSender('myapp', { host: 'localhost', port: 24224, timeout: 3.0, }); -var report = function(err, req) { - var payload = { +const report = function(err, req) { + const payload = { serviceContext: { service: 'myapp', }, diff --git a/src/entry.js b/src/entry.js index d142e8cc..203dee57 100644 --- a/src/entry.js +++ b/src/entry.js @@ -16,12 +16,12 @@ 'use strict'; -var {Service} = require('@google-cloud/common-grpc'); -var EventId = require('eventid'); -var extend = require('extend'); -var is = require('is'); +const {Service} = require('@google-cloud/common-grpc'); +const EventId = require('eventid'); +const extend = require('extend'); +const is = require('is'); -var eventId = new EventId(); +const eventId = new EventId(); /** * Create an entry object to define new data to insert into a log. @@ -46,11 +46,11 @@ var eventId = new EventId(); * Any other types are stringified with `String(value)`. * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var syslog = logging.log('syslog'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const syslog = logging.log('syslog'); * - * var metadata = { + * const metadata = { * resource: { * type: 'gce_instance', * labels: { @@ -60,7 +60,7 @@ var eventId = new EventId(); * } * }; * - * var entry = syslog.entry(metadata, { + * const entry = syslog.entry(metadata, { * delegate: 'my_username' * }); * @@ -123,16 +123,16 @@ function Entry(metadata, data) { * @returns {Entry} */ Entry.fromApiResponse_ = function(entry) { - var data = entry[entry.payload]; + let data = entry[entry.payload]; if (entry.payload === 'jsonPayload') { data = Service.structToObj_(data); } - var serializedEntry = new Entry(entry, data); + const serializedEntry = new Entry(entry, data); if (serializedEntry.metadata.timestamp) { - var ms = serializedEntry.metadata.timestamp.seconds * 1000; + let ms = serializedEntry.metadata.timestamp.seconds * 1000; ms += serializedEntry.metadata.timestamp.nanos / 1e6; serializedEntry.metadata.timestamp = new Date(ms); } @@ -150,7 +150,7 @@ Entry.fromApiResponse_ = function(entry) { Entry.prototype.toJSON = function(options) { options = options || {}; - var entry = extend(true, {}, this.metadata); + const entry = extend(true, {}, this.metadata); if (is.object(this.data)) { entry.jsonPayload = Service.objToStruct_(this.data, { @@ -162,8 +162,8 @@ Entry.prototype.toJSON = function(options) { } if (is.date(entry.timestamp)) { - var seconds = entry.timestamp.getTime() / 1000; - var secondsRounded = Math.floor(seconds); + const seconds = entry.timestamp.getTime() / 1000; + const secondsRounded = Math.floor(seconds); entry.timestamp = { seconds: secondsRounded, diff --git a/src/index.js b/src/index.js index 17b60e9d..b003c4a2 100644 --- a/src/index.js +++ b/src/index.js @@ -16,24 +16,24 @@ 'use strict'; -var arrify = require('arrify'); -var common = require('@google-cloud/common-grpc'); +const arrify = require('arrify'); +const common = require('@google-cloud/common-grpc'); const {promisifyAll} = require('@google-cloud/promisify'); const {paginator} = require('@google-cloud/paginator'); const {replaceProjectIdToken} = require('@google-cloud/projectify'); -var extend = require('extend'); -var {GoogleAuth} = require('google-auth-library'); -var is = require('is'); -var pumpify = require('pumpify'); -var streamEvents = require('stream-events'); -var through = require('through2'); +const extend = require('extend'); +const {GoogleAuth} = require('google-auth-library'); +const is = require('is'); +const pumpify = require('pumpify'); +const streamEvents = require('stream-events'); +const through = require('through2'); -var PKG = require('../package.json'); -var v2 = require('./v2'); +const PKG = require('../package.json'); +const v2 = require('./v2'); -var Entry = require('./entry.js'); -var Log = require('./log.js'); -var Sink = require('./sink.js'); +const Entry = require('./entry.js'); +const Log = require('./log.js'); +const Sink = require('./sink.js'); /** * @namespace google @@ -130,7 +130,7 @@ function Logging(options) { } } - var options_ = extend( + const options_ = extend( { libName: 'gccl', libVersion: PKG.version, @@ -189,14 +189,14 @@ function Logging(options) { * @see Sink#create * * @example - * var Storage = require('@google-cloud/storage'); - * var storage = new Storage({ + * const Storage = require('@google-cloud/storage'); + * const storage = new Storage({ * projectId: 'grape-spaceship-123' * }); - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * - * var config = { + * const config = { * destination: storage.bucket('logging-bucket'), * filter: 'severity = ALERT' * }; @@ -211,8 +211,8 @@ function Logging(options) { * // If the callback is omitted, we'll return a Promise. * //- * logging.createSink('new-sink-name', config).then(function(data) { - * var sink = data[0]; - * var apiResponse = data[1]; + * const sink = data[0]; + * const apiResponse = data[1]; * }); * * @example include:samples/sinks.js @@ -221,7 +221,7 @@ function Logging(options) { */ Logging.prototype.createSink = function(name, config, callback) { // jscs:enable maximumLineLength - var self = this; + const self = this; if (!is.string(name)) { throw new Error('A sink name must be provided.'); @@ -246,7 +246,7 @@ Logging.prototype.createSink = function(name, config, callback) { return; } - var reqOpts = { + const reqOpts = { parent: 'projects/' + this.projectId, sink: extend({}, config, {name: name}), }; @@ -266,7 +266,7 @@ Logging.prototype.createSink = function(name, config, callback) { return; } - var sink = self.sink(resp.name); + const sink = self.sink(resp.name); sink.metadata = resp; callback(null, sink, resp); @@ -290,10 +290,10 @@ Logging.prototype.createSink = function(name, config, callback) { * @returns {Entry} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * - * var resource = { + * const resource = { * type: 'gce_instance', * labels: { * zone: 'global', @@ -301,7 +301,7 @@ Logging.prototype.createSink = function(name, config, callback) { * } * }; * - * var entry = logging.entry(resource, { + * const entry = logging.entry(resource, { * delegate: 'my_username' * }); * @@ -365,8 +365,8 @@ Logging.prototype.entry = function(resource, data) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * * logging.getEntries(function(err, entries) { * // `entries` is an array of Stackdriver Logging entry objects. @@ -392,7 +392,7 @@ Logging.prototype.entry = function(resource, data) { * // If the callback is omitted, we'll return a Promise. * //- * logging.getEntries().then(function(data) { - * var entries = data[0]; + * const entries = data[0]; * }); * * @example include:samples/logs.js @@ -409,7 +409,7 @@ Logging.prototype.getEntries = function(options, callback) { options = {}; } - var reqOpts = extend( + const reqOpts = extend( { orderBy: 'timestamp desc', }, @@ -418,7 +418,7 @@ Logging.prototype.getEntries = function(options, callback) { reqOpts.resourceNames = arrify(reqOpts.resourceNames); - var resourceName = 'projects/' + this.projectId; + const resourceName = 'projects/' + this.projectId; if (reqOpts.resourceNames.indexOf(resourceName) === -1) { reqOpts.resourceNames.push(resourceName); @@ -427,7 +427,7 @@ Logging.prototype.getEntries = function(options, callback) { delete reqOpts.autoPaginate; delete reqOpts.gaxOptions; - var gaxOptions = extend( + const gaxOptions = extend( { autoPaginate: options.autoPaginate, }, @@ -442,7 +442,7 @@ Logging.prototype.getEntries = function(options, callback) { gaxOpts: gaxOptions, }, function() { - var entries = arguments[1]; + const entries = arguments[1]; if (entries) { arguments[1] = entries.map(Entry.fromApiResponse_); @@ -463,8 +463,8 @@ Logging.prototype.getEntries = function(options, callback) { * instances. * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * * logging.getEntriesStream() * .on('error', console.error) @@ -486,13 +486,11 @@ Logging.prototype.getEntries = function(options, callback) { * }); */ Logging.prototype.getEntriesStream = function(options) { - var self = this; - + const self = this; options = options || {}; - var requestStream; - - var userStream = streamEvents(pumpify.obj()); + let requestStream; + const userStream = streamEvents(pumpify.obj()); userStream.abort = function() { if (requestStream) { @@ -500,12 +498,12 @@ Logging.prototype.getEntriesStream = function(options) { } }; - var toEntryStream = through.obj(function(entry, _, next) { + const toEntryStream = through.obj(function(entry, _, next) { next(null, Entry.fromApiResponse_(entry)); }); userStream.once('reading', function() { - var reqOpts = extend( + const reqOpts = extend( { orderBy: 'timestamp desc', }, @@ -517,7 +515,7 @@ Logging.prototype.getEntriesStream = function(options) { delete reqOpts.autoPaginate; delete reqOpts.gaxOptions; - var gaxOptions = extend( + const gaxOptions = extend( { autoPaginate: options.autoPaginate, }, @@ -573,8 +571,8 @@ Logging.prototype.getEntriesStream = function(options) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * * logging.getSinks(function(err, sinks) { * // sinks is an array of Sink objects. @@ -584,7 +582,7 @@ Logging.prototype.getEntriesStream = function(options) { * // If the callback is omitted, we'll return a Promise. * //- * logging.getSinks().then(function(data) { - * var sinks = data[0]; + * const sinks = data[0]; * }); * * @example include:samples/sinks.js @@ -592,21 +590,21 @@ Logging.prototype.getEntriesStream = function(options) { * Another example: */ Logging.prototype.getSinks = function(options, callback) { - var self = this; + const self = this; if (is.fn(options)) { callback = options; options = {}; } - var reqOpts = extend({}, options, { + const reqOpts = extend({}, options, { parent: 'projects/' + this.projectId, }); delete reqOpts.autoPaginate; delete reqOpts.gaxOptions; - var gaxOptions = extend( + const gaxOptions = extend( { autoPaginate: options.autoPaginate, }, @@ -621,11 +619,11 @@ Logging.prototype.getSinks = function(options, callback) { gaxOpts: gaxOptions, }, function() { - var sinks = arguments[1]; + const sinks = arguments[1]; if (sinks) { arguments[1] = sinks.map(function(sink) { - var sinkInstance = self.sink(sink.name); + const sinkInstance = self.sink(sink.name); sinkInstance.metadata = sink; return sinkInstance; }); @@ -646,8 +644,8 @@ Logging.prototype.getSinks = function(options, callback) { * instances. * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); * * logging.getSinksStream() * .on('error', console.error) @@ -668,12 +666,12 @@ Logging.prototype.getSinks = function(options, callback) { * }); */ Logging.prototype.getSinksStream = function(options) { - var self = this; + const self = this; options = options || {}; - var requestStream; - var userStream = streamEvents(pumpify.obj()); + let requestStream; + const userStream = streamEvents(pumpify.obj()); userStream.abort = function() { if (requestStream) { @@ -681,20 +679,20 @@ Logging.prototype.getSinksStream = function(options) { } }; - var toSinkStream = through.obj(function(sink, _, next) { - var sinkInstance = self.sink(sink.name); + const toSinkStream = through.obj(function(sink, _, next) { + const sinkInstance = self.sink(sink.name); sinkInstance.metadata = sink; next(null, sinkInstance); }); userStream.once('reading', function() { - var reqOpts = extend({}, options, { + const reqOpts = extend({}, options, { parent: 'projects/' + self.projectId, }); delete reqOpts.gaxOptions; - var gaxOptions = extend( + const gaxOptions = extend( { autoPaginate: options.autoPaginate, }, @@ -726,9 +724,9 @@ Logging.prototype.getSinksStream = function(options) { * @returns {Log} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); */ Logging.prototype.log = function(name, options) { return new Log(this, name, options); @@ -743,9 +741,9 @@ Logging.prototype.log = function(name, options) { * @returns {Sink} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); */ Logging.prototype.sink = function(name) { return new Sink(this, name); @@ -761,11 +759,11 @@ Logging.prototype.sink = function(name) { * @param {function} [callback] Callback function. */ Logging.prototype.request = function(config, callback) { - var self = this; - var isStreamMode = !callback; + const self = this; + const isStreamMode = !callback; - var gaxStream; - var stream; + let gaxStream; + let stream; if (isStreamMode) { stream = streamEvents(through.obj()); @@ -790,7 +788,7 @@ Logging.prototype.request = function(config, callback) { self.projectId = projectId; - var gaxClient = self.api[config.client]; + let gaxClient = self.api[config.client]; if (!gaxClient) { // Lazily instantiate client. @@ -798,10 +796,10 @@ Logging.prototype.request = function(config, callback) { self.api[config.client] = gaxClient; } - var reqOpts = extend(true, {}, config.reqOpts); + let reqOpts = extend(true, {}, config.reqOpts); reqOpts = replaceProjectIdToken(reqOpts, projectId); - var requestFn = gaxClient[config.method].bind( + const requestFn = gaxClient[config.method].bind( gaxClient, reqOpts, config.gaxOpts @@ -859,8 +857,8 @@ Logging.prototype.request = function(config, callback) { * @private */ Logging.prototype.setAclForBucket_ = function(name, config, callback) { - var self = this; - var bucket = config.destination; + const self = this; + const bucket = config.destination; bucket.acl.owners.addGroup('cloud-logs@google.com', function(err, apiResp) { if (err) { @@ -884,8 +882,8 @@ Logging.prototype.setAclForBucket_ = function(name, config, callback) { * @private */ Logging.prototype.setAclForDataset_ = function(name, config, callback) { - var self = this; - var dataset = config.destination; + const self = this; + const dataset = config.destination; dataset.getMetadata(function(err, metadata, apiResp) { if (err) { @@ -893,7 +891,7 @@ Logging.prototype.setAclForDataset_ = function(name, config, callback) { return; } - var access = [].slice.call(arrify(metadata.access)); + const access = [].slice.call(arrify(metadata.access)); access.push({ role: 'WRITER', @@ -929,8 +927,8 @@ Logging.prototype.setAclForDataset_ = function(name, config, callback) { * @private */ Logging.prototype.setAclForTopic_ = function(name, config, callback) { - var self = this; - var topic = config.destination; + const self = this; + const topic = config.destination; topic.iam.getPolicy(function(err, policy, apiResp) { if (err) { diff --git a/src/log.js b/src/log.js index 77214c6d..ff8572ef 100644 --- a/src/log.js +++ b/src/log.js @@ -16,14 +16,14 @@ 'use strict'; -var arrify = require('arrify'); +const arrify = require('arrify'); const {promisifyAll} = require('@google-cloud/promisify'); -var extend = require('extend'); -var is = require('is'); -var snakeCaseKeys = require('snakecase-keys'); +const extend = require('extend'); +const is = require('is'); +const snakeCaseKeys = require('snakecase-keys'); -var Entry = require('./entry.js'); -var Metadata = require('./metadata.js'); +const Entry = require('./entry.js'); +const Metadata = require('./metadata.js'); /** * A log is a named collection of entries, each entry representing a timestamped @@ -43,9 +43,9 @@ var Metadata = require('./metadata.js'); * logged objects with a string value, `[Circular]`. (Default: false) * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('syslog'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('syslog'); */ function Log(logging, name, options) { options = options || {}; @@ -72,7 +72,7 @@ function Log(logging, name, options) { */ Log.assignSeverityToEntries_ = function(entries, severity) { return arrify(entries).map(function(entry) { - var metadata = extend(true, {}, entry.metadata, { + const metadata = extend(true, {}, entry.metadata, { severity: severity, }); @@ -91,7 +91,7 @@ Log.assignSeverityToEntries_ = function(entries, severity) { * @returns {string} */ Log.formatName_ = function(projectId, name) { - var path = 'projects/' + projectId + '/logs/'; + const path = 'projects/' + projectId + '/logs/'; name = name.replace(path, ''); if (decodeURIComponent(name) === name) { @@ -113,11 +113,11 @@ Log.formatName_ = function(projectId, name) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -127,7 +127,7 @@ Log.formatName_ = function(projectId, name) { * // If the callback is omitted, we'll return a Promise. * //- * log.alert(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.alert = function(entry, options, callback) { @@ -145,11 +145,11 @@ Log.prototype.alert = function(entry, options, callback) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -159,11 +159,11 @@ Log.prototype.alert = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.critical(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.critical = function(entry, options, callback) { - var entries = Log.assignSeverityToEntries_(entry, 'CRITICAL'); + const entries = Log.assignSeverityToEntries_(entry, 'CRITICAL'); this.write(entries, options, callback); }; @@ -178,11 +178,11 @@ Log.prototype.critical = function(entry, options, callback) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -192,7 +192,7 @@ Log.prototype.critical = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.debug(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.debug = function(entry, options, callback) { @@ -219,9 +219,9 @@ Log.prototype.debug = function(entry, options, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * * log.delete(function(err, apiResponse) { * if (!err) { @@ -233,7 +233,7 @@ Log.prototype.debug = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.delete().then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); * * @example include:samples/logs.js @@ -246,7 +246,7 @@ Log.prototype.delete = function(gaxOptions, callback) { gaxOptions = {}; } - var reqOpts = { + const reqOpts = { logName: this.formattedName_, }; @@ -272,11 +272,11 @@ Log.prototype.delete = function(gaxOptions, callback) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -286,11 +286,11 @@ Log.prototype.delete = function(gaxOptions, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.emergency(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.emergency = function(entry, options, callback) { - var entries = Log.assignSeverityToEntries_(entry, 'EMERGENCY'); + const entries = Log.assignSeverityToEntries_(entry, 'EMERGENCY'); this.write(entries, options, callback); }; @@ -310,11 +310,11 @@ Log.prototype.emergency = function(entry, options, callback) { * @returns {Entry} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var metadata = { + * const metadata = { * resource: { * type: 'gce_instance', * labels: { @@ -324,7 +324,7 @@ Log.prototype.emergency = function(entry, options, callback) { * } * }; * - * var entry = log.entry(metadata, { + * const entry = log.entry(metadata, { * delegate: 'my_username' * }); * @@ -363,11 +363,11 @@ Log.prototype.entry = function(metadata, data) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -377,7 +377,7 @@ Log.prototype.entry = function(metadata, data) { * // If the callback is omitted, we'll return a Promise. * //- * log.error(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.error = function(entry, options, callback) { @@ -395,9 +395,9 @@ Log.prototype.error = function(entry, options, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * * log.getEntries(function(err, entries) { * // `entries` is an array of Stackdriver Logging entry objects. @@ -423,7 +423,7 @@ Log.prototype.error = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.getEntries().then(function(data) { - * var entries = data[0]; + * const entries = data[0]; * }); */ Log.prototype.getEntries = function(options, callback) { @@ -452,9 +452,9 @@ Log.prototype.getEntries = function(options, callback) { * instances. * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * * log.getEntriesStream() * .on('error', console.error) @@ -497,11 +497,11 @@ Log.prototype.getEntriesStream = function(options) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -511,7 +511,7 @@ Log.prototype.getEntriesStream = function(options) { * // If the callback is omitted, we'll return a Promise. * //- * log.info(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.info = function(entry, options, callback) { @@ -529,11 +529,11 @@ Log.prototype.info = function(entry, options, callback) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -543,7 +543,7 @@ Log.prototype.info = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.notice(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.notice = function(entry, options, callback) { @@ -561,11 +561,11 @@ Log.prototype.notice = function(entry, options, callback) { * @param {LogWriteCallback} [callback] Callback function. * @returns {Promise} * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var log = logging.log('my-log'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const log = logging.log('my-log'); * - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -575,7 +575,7 @@ Log.prototype.notice = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.warning(entry).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Log.prototype.warning = function(entry, options, callback) { @@ -612,7 +612,7 @@ Log.prototype.warning = function(entry, options, callback) { * @returns {Promise} * * @example - * var entry = log.entry('gce_instance', { + * const entry = log.entry('gce_instance', { * instance: 'my_instance' * }); * @@ -625,7 +625,7 @@ Log.prototype.warning = function(entry, options, callback) { * //- * // You may also pass multiple log entries to write. * //- - * var secondEntry = log.entry('compute.googleapis.com', { + * const secondEntry = log.entry('compute.googleapis.com', { * user: 'my_username' * }); * @@ -643,7 +643,7 @@ Log.prototype.warning = function(entry, options, callback) { * // Note, however, that you must provide a configuration object to specify the * // resource. * //- - * var entries = [ + * const entries = [ * { * user: 'my_username' * }, @@ -652,7 +652,7 @@ Log.prototype.warning = function(entry, options, callback) { * } * ]; * - * var options = { + * const options = { * resource: 'compute.googleapis.com' * }; * @@ -662,7 +662,7 @@ Log.prototype.warning = function(entry, options, callback) { * // If the callback is omitted, we'll return a Promise. * //- * log.write(entries).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); * * @example include:samples/logs.js @@ -674,7 +674,7 @@ Log.prototype.warning = function(entry, options, callback) { * Another example: */ Log.prototype.write = function(entry, options, callback) { - var self = this; + const self = this; if (is.fn(options)) { callback = options; @@ -694,14 +694,14 @@ Log.prototype.write = function(entry, options, callback) { } function writeWithResource(resource) { - var decoratedEntries; + let decoratedEntries; try { decoratedEntries = self.decorateEntries_(arrify(entry)); } catch (err) { // Ignore errors (the API will speak up if it has an issue). } - var reqOpts = extend( + const reqOpts = extend( { logName: self.formattedName_, entries: decoratedEntries, @@ -734,7 +734,7 @@ Log.prototype.write = function(entry, options, callback) { * @throws if there is an error during serialization. */ Log.prototype.decorateEntries_ = function(entries) { - var self = this; + const self = this; return entries.map(function(entry) { if (!(entry instanceof Entry)) { diff --git a/src/metadata.js b/src/metadata.js index 71cea404..f775bb41 100644 --- a/src/metadata.js +++ b/src/metadata.js @@ -16,8 +16,8 @@ 'use strict'; -var fs = require('fs'); -var gcpMetadata = require('gcp-metadata'); +const fs = require('fs'); +const gcpMetadata = require('gcp-metadata'); /** * The Metadata class attempts to contact the metadata service and determine, diff --git a/src/sink.js b/src/sink.js index 6a7583f4..5b9e1dac 100644 --- a/src/sink.js +++ b/src/sink.js @@ -16,10 +16,10 @@ 'use strict'; -var common = require('@google-cloud/common-grpc'); +const common = require('@google-cloud/common-grpc'); const {promisifyAll} = require('@google-cloud/promisify'); -var extend = require('extend'); -var is = require('is'); +const extend = require('extend'); +const is = require('is'); /** * A sink is an object that lets you to specify a set of log entries to export @@ -36,9 +36,9 @@ var is = require('is'); * @param {string} name Name of the sink. * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); */ function Sink(logging, name) { this.logging = logging; @@ -60,11 +60,11 @@ function Sink(logging, name) { * @see Logging#createSink * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); * - * var config = { + * const config = { * destination: { * // ... * } @@ -80,8 +80,8 @@ function Sink(logging, name) { * // If the callback is omitted, we'll return a Promise. * //- * sink.create(config).then(function(data) { - * var sink = data[0]; - * var apiResponse = data[1]; + * const sink = data[0]; + * const apiResponse = data[1]; * }); * * @example include:samples/sinks.js @@ -112,9 +112,9 @@ Sink.prototype.create = function(config, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); * * sink.delete(function(err, apiResponse) { * if (!err) { @@ -126,7 +126,7 @@ Sink.prototype.create = function(config, callback) { * // If the callback is omitted, we'll return a Promise. * //- * sink.delete().then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); * * @example include:samples/sinks.js @@ -139,7 +139,7 @@ Sink.prototype.delete = function(gaxOptions, callback) { gaxOptions = {}; } - var reqOpts = { + const reqOpts = { sinkName: this.formattedName_, }; @@ -177,9 +177,9 @@ Sink.prototype.delete = function(gaxOptions, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); * * sink.getMetadata(function(err, metadata, apiResponse) {}); * @@ -187,8 +187,8 @@ Sink.prototype.delete = function(gaxOptions, callback) { * // If the callback is omitted, we'll return a Promise. * //- * sink.getMetadata().then(function(data) { - * var metadata = data[0]; - * var apiResponse = data[1]; + * const metadata = data[0]; + * const apiResponse = data[1]; * }); * * @example include:samples/sinks.js @@ -196,14 +196,14 @@ Sink.prototype.delete = function(gaxOptions, callback) { * Another example: */ Sink.prototype.getMetadata = function(gaxOptions, callback) { - var self = this; + const self = this; if (is.fn(gaxOptions)) { callback = gaxOptions; gaxOptions = {}; } - var reqOpts = { + const reqOpts = { sinkName: this.formattedName_, }; @@ -245,11 +245,11 @@ Sink.prototype.getMetadata = function(gaxOptions, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); * - * var filter = 'metadata.severity = ALERT'; + * const filter = 'metadata.severity = ALERT'; * * sink.setFilter(filter, function(err, apiResponse) {}); * @@ -257,7 +257,7 @@ Sink.prototype.getMetadata = function(gaxOptions, callback) { * // If the callback is omitted, we'll return a Promise. * //- * sink.setFilter(filter).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); */ Sink.prototype.setFilter = function(filter, callback) { @@ -292,11 +292,11 @@ Sink.prototype.setFilter = function(filter, callback) { * @returns {Promise} * * @example - * var Logging = require('@google-cloud/logging'); - * var logging = new Logging(); - * var sink = logging.sink('my-sink'); + * const Logging = require('@google-cloud/logging'); + * const logging = new Logging(); + * const sink = logging.sink('my-sink'); * - * var metadata = { + * const metadata = { * filter: 'metadata.severity = ALERT' * }; * @@ -306,7 +306,7 @@ Sink.prototype.setFilter = function(filter, callback) { * // If the callback is omitted, we'll return a Promise. * //- * sink.setMetadata(metadata).then(function(data) { - * var apiResponse = data[0]; + * const apiResponse = data[0]; * }); * * @example include:samples/sinks.js @@ -314,7 +314,7 @@ Sink.prototype.setFilter = function(filter, callback) { * Another example: */ Sink.prototype.setMetadata = function(metadata, callback) { - var self = this; + const self = this; callback = callback || common.util.noop; @@ -324,7 +324,7 @@ Sink.prototype.setMetadata = function(metadata, callback) { return; } - var reqOpts = { + const reqOpts = { sinkName: self.formattedName_, sink: extend({}, currentMetadata, metadata), }; diff --git a/system-test/logging.js b/system-test/logging.js index 06b405eb..4747ef7a 100644 --- a/system-test/logging.js +++ b/system-test/logging.js @@ -16,34 +16,34 @@ 'use strict'; -var assert = require('assert'); -var async = require('async'); -var bigqueryLibrary = require('@google-cloud/bigquery'); -var exec = require('methmeth'); -var extend = require('extend'); -var is = require('is'); -var prop = require('propprop'); -var pubsubLibrary = require('@google-cloud/pubsub'); -var storageLibrary = require('@google-cloud/storage'); -var uuid = require('uuid'); - -var Logging = require('../'); +const assert = require('assert'); +const async = require('async'); +const bigqueryLibrary = require('@google-cloud/bigquery'); +const exec = require('methmeth'); +const extend = require('extend'); +const is = require('is'); +const prop = require('propprop'); +const pubsubLibrary = require('@google-cloud/pubsub'); +const {Storage} = require('@google-cloud/storage'); +const uuid = require('uuid'); + +const Logging = require('../'); describe('Logging', function() { - var PROJECT_ID; - var TESTS_PREFIX = 'gcloud-logging-test'; - var WRITE_CONSISTENCY_DELAY_MS = 10000; + let PROJECT_ID; + const TESTS_PREFIX = 'gcloud-logging-test'; + const WRITE_CONSISTENCY_DELAY_MS = 10000; - var bigQuery = bigqueryLibrary(); - var pubsub = pubsubLibrary(); - var storage = storageLibrary(); + const bigQuery = bigqueryLibrary(); + const pubsub = pubsubLibrary(); + const storage = new Storage(); - var logging = new Logging(); + const logging = new Logging(); // Create the possible destinations for sinks that we will create. - var bucket = storage.bucket(generateName()); - var dataset = bigQuery.dataset(generateName().replace(/-/g, '_')); - var topic = pubsub.topic(generateName()); + const bucket = storage.bucket(generateName()); + const dataset = bigQuery.dataset(generateName().replace(/-/g, '_')); + const topic = pubsub.topic(generateName()); before(function(done) { async.parallel( @@ -135,7 +135,7 @@ describe('Logging', function() { describe('sinks', function() { it('should create a sink with a Bucket destination', function(done) { - var sink = logging.sink(generateName()); + const sink = logging.sink(generateName()); sink.create( { @@ -144,7 +144,7 @@ describe('Logging', function() { function(err, sink, apiResponse) { assert.ifError(err); - var destination = 'storage.googleapis.com/' + bucket.name; + const destination = 'storage.googleapis.com/' + bucket.name; assert.strictEqual(apiResponse.destination, destination); done(); @@ -153,7 +153,7 @@ describe('Logging', function() { }); it('should create a sink with a Dataset destination', function(done) { - var sink = logging.sink(generateName()); + const sink = logging.sink(generateName()); sink.create( { @@ -162,7 +162,7 @@ describe('Logging', function() { function(err, sink, apiResponse) { assert.ifError(err); - var destination = 'bigquery.googleapis.com/datasets/' + dataset.id; + const destination = 'bigquery.googleapis.com/datasets/' + dataset.id; // The projectId may have been replaced depending on how the system // tests are being run, so let's not care about that. @@ -179,7 +179,7 @@ describe('Logging', function() { }); it('should create a sink with a Topic destination', function(done) { - var sink = logging.sink(generateName()); + const sink = logging.sink(generateName()); sink.create( { @@ -188,7 +188,7 @@ describe('Logging', function() { function(err, sink, apiResponse) { assert.ifError(err); - var destination = 'pubsub.googleapis.com/' + topic.name; + const destination = 'pubsub.googleapis.com/' + topic.name; // The projectId may have been replaced depending on how the system // tests are being run, so let's not care about that. @@ -203,8 +203,8 @@ describe('Logging', function() { }); describe('metadata', function() { - var sink = logging.sink(generateName()); - var FILTER = 'severity = ALERT'; + const sink = logging.sink(generateName()); + const FILTER = 'severity = ALERT'; before(function(done) { sink.create( @@ -216,7 +216,7 @@ describe('Logging', function() { }); it('should set metadata', function(done) { - var metadata = { + const metadata = { filter: FILTER, }; @@ -237,7 +237,7 @@ describe('Logging', function() { }); describe('listing sinks', function() { - var sink = logging.sink(generateName()); + const sink = logging.sink(generateName()); before(function(done) { sink.create( @@ -282,9 +282,9 @@ describe('Logging', function() { }); describe('logs', function() { - var log = logging.log('syslog'); + const log = logging.log('syslog'); - var logEntries = [ + const logEntries = [ // string data log.entry('log entry 1'), @@ -306,7 +306,7 @@ describe('Logging', function() { }), ]; - var options = { + const options = { resource: { type: 'gce_instance', labels: { @@ -418,11 +418,11 @@ describe('Logging', function() { }); it('should preserve order of entries', function(done) { - var entry1 = log.entry('1'); + const entry1 = log.entry('1'); setTimeout(function() { - var entry2 = log.entry('2'); - var entry3 = log.entry({timestamp: entry2.metadata.timestamp}, '3'); + const entry2 = log.entry('2'); + const entry3 = log.entry({timestamp: entry2.metadata.timestamp}, '3'); // Re-arrange to confirm the timestamp is sent and honored. log.write([entry2, entry3, entry1], options, function(err) { @@ -450,7 +450,7 @@ describe('Logging', function() { }); it('should preserve order for sequential write calls', function(done) { - var messages = ['1', '2', '3', '4', '5']; + const messages = ['1', '2', '3', '4', '5']; messages.forEach(function(message) { log.write(log.entry(message)); @@ -475,7 +475,7 @@ describe('Logging', function() { }); it('should write an entry with primitive values', function(done) { - var logEntry = log.entry({ + const logEntry = log.entry({ when: new Date(), matchUser: /username: (.+)/, matchUserError: new Error('No user found.'), @@ -494,7 +494,7 @@ describe('Logging', function() { function(err, entries) { assert.ifError(err); - var entry = entries[0]; + const entry = entries[0]; assert.deepStrictEqual(entry.data, { when: logEntry.data.when.toString(), @@ -510,15 +510,15 @@ describe('Logging', function() { }); it('should write a log with metadata', function(done) { - var metadata = extend({}, options, { + const metadata = extend({}, options, { severity: 'DEBUG', }); - var data = { + const data = { embeddedData: true, }; - var logEntry = log.entry(metadata, data); + const logEntry = log.entry(metadata, data); log.write(logEntry, function(err) { assert.ifError(err); @@ -532,7 +532,7 @@ describe('Logging', function() { function(err, entries) { assert.ifError(err); - var entry = entries[0]; + const entry = entries[0]; assert.strictEqual(entry.metadata.severity, metadata.severity); assert.deepStrictEqual(entry.data, data); @@ -545,8 +545,8 @@ describe('Logging', function() { }); it('should set the default resource', function(done) { - var text = 'entry-text'; - var entry = log.entry(text); + const text = 'entry-text'; + const entry = log.entry(text); log.write(entry, function(err) { assert.ifError(err); @@ -560,7 +560,7 @@ describe('Logging', function() { function(err, entries) { assert.ifError(err); - var entry = entries[0]; + const entry = entries[0]; assert.strictEqual(entry.data, text); assert.deepStrictEqual(entry.metadata.resource, { diff --git a/test/entry.js b/test/entry.js index f58e15a9..06045232 100644 --- a/test/entry.js +++ b/test/entry.js @@ -16,14 +16,14 @@ 'use strict'; -var assert = require('assert'); -var extend = require('extend'); -var {GrpcService, util} = require('@google-cloud/common-grpc'); -var proxyquire = require('proxyquire'); +const assert = require('assert'); +const extend = require('extend'); +const {GrpcService, util} = require('@google-cloud/common-grpc'); +const proxyquire = require('proxyquire'); function FakeGrpcService() {} -var fakeEventIdNewOverride; +let fakeEventIdNewOverride; function FakeEventId() {} FakeEventId.prototype.new = function() { @@ -31,11 +31,11 @@ FakeEventId.prototype.new = function() { }; describe('Entry', function() { - var Entry; - var entry; + let Entry; + let entry; - var METADATA = {}; - var DATA = {}; + const METADATA = {}; + const DATA = {}; before(function() { Entry = proxyquire('../src/entry.js', { @@ -54,9 +54,9 @@ describe('Entry', function() { describe('instantiation', function() { it('should assign timestamp to metadata', function() { - var now = new Date(); + const now = new Date(); - var expectedTimestampBoundaries = { + const expectedTimestampBoundaries = { start: new Date(now.getTime() - 1000), end: new Date(now.getTime() + 1000), }; @@ -66,9 +66,9 @@ describe('Entry', function() { }); it('should not assign timestamp if one is already set', function() { - var timestamp = new Date('2012'); + const timestamp = new Date('2012'); - var entry = new Entry({ + const entry = new Entry({ timestamp: timestamp, }); @@ -76,27 +76,27 @@ describe('Entry', function() { }); it('should assign insertId to metadata', function() { - var eventId = 'event-id'; + const eventId = 'event-id'; fakeEventIdNewOverride = function() { return eventId; }; - var entry = new Entry(); + const entry = new Entry(); assert.strictEqual(entry.metadata.insertId, eventId); }); it('should not assign insertId if one is already set', function() { - var eventId = 'event-id'; + const eventId = 'event-id'; fakeEventIdNewOverride = function() { return eventId; }; - var userDefinedInsertId = 'user-defined-insert-id'; + const userDefinedInsertId = 'user-defined-insert-id'; - var entry = new Entry({ + const entry = new Entry({ insertId: userDefinedInsertId, }); @@ -109,13 +109,13 @@ describe('Entry', function() { }); describe('fromApiResponse_', function() { - var RESOURCE = {}; - var entry; - var date = new Date(); + const RESOURCE = {}; + let entry; + const date = new Date(); beforeEach(function() { - var seconds = date.getTime() / 1000; - var secondsRounded = Math.floor(seconds); + const seconds = date.getTime() / 1000; + const secondsRounded = Math.floor(seconds); FakeGrpcService.structToObj_ = function(data) { return data; @@ -142,7 +142,7 @@ describe('Entry', function() { }); it('should extend the entry with proto data', function() { - var entry = Entry.fromApiResponse_({ + const entry = Entry.fromApiResponse_({ resource: RESOURCE, payload: 'protoPayload', protoPayload: DATA, @@ -157,7 +157,7 @@ describe('Entry', function() { }); it('should extend the entry with text data', function() { - var entry = Entry.fromApiResponse_({ + const entry = Entry.fromApiResponse_({ resource: RESOURCE, payload: 'textPayload', textPayload: DATA, @@ -174,15 +174,15 @@ describe('Entry', function() { }); it('should not modify the original instance', function() { - var entryBefore = extend(true, {}, entry); + const entryBefore = extend(true, {}, entry); entry.toJSON(); - var entryAfter = extend(true, {}, entry); + const entryAfter = extend(true, {}, entry); assert.deepStrictEqual(entryBefore, entryAfter); }); it('should convert data as a struct and assign to jsonPayload', function() { - var input = {}; - var converted = {}; + const input = {}; + const converted = {}; FakeGrpcService.objToStruct_ = function(obj, options) { assert.strictEqual(obj, input); @@ -194,7 +194,7 @@ describe('Entry', function() { }; entry.data = input; - var json = entry.toJSON(); + const json = entry.toJSON(); assert.strictEqual(json.jsonPayload, converted); }); @@ -210,18 +210,18 @@ describe('Entry', function() { it('should assign string data as textPayload', function() { entry.data = 'string'; - var json = entry.toJSON(); + const json = entry.toJSON(); assert.strictEqual(json.textPayload, entry.data); }); it('should convert a date', function() { - var date = new Date(); + const date = new Date(); entry.metadata.timestamp = date; - var json = entry.toJSON(); + const json = entry.toJSON(); - var seconds = date.getTime() / 1000; - var secondsRounded = Math.floor(seconds); + const seconds = date.getTime() / 1000; + const secondsRounded = Math.floor(seconds); assert.deepStrictEqual(json.timestamp, { seconds: secondsRounded, diff --git a/test/index.js b/test/index.js index 1963f877..8250fff3 100644 --- a/test/index.js +++ b/test/index.js @@ -16,19 +16,19 @@ 'use strict'; -var arrify = require('arrify'); -var assert = require('assert'); -var extend = require('extend'); -var proxyquire = require('proxyquire'); -var through = require('through2'); -var {util} = require('@google-cloud/common-grpc'); +const arrify = require('arrify'); +const assert = require('assert'); +const extend = require('extend'); +const proxyquire = require('proxyquire'); +const through = require('through2'); +const {util} = require('@google-cloud/common-grpc'); -var v2 = require('../src/v2'); +const v2 = require('../src/v2'); -var PKG = require('../package.json'); +const PKG = require('../package.json'); -var extended = false; -var fakePaginator = { +let extended = false; +const fakePaginator = { paginator: { extend: function(Class, methods) { if (Class.name !== 'Logging') { @@ -44,15 +44,15 @@ var fakePaginator = { }, }; -var googleAuthOverride; +let googleAuthOverride; function fakeGoogleAuth() { return (googleAuthOverride || util.noop).apply(null, arguments); } -var isCustomTypeOverride; -var promisifed = false; -var replaceProjectIdTokenOverride; -var fakeUtil = extend({}, util, { +let isCustomTypeOverride; +let promisifed = false; +let replaceProjectIdTokenOverride; +const fakeUtil = extend({}, util, { isCustomType: function() { if (isCustomTypeOverride) { return isCustomTypeOverride.apply(null, arguments); @@ -83,7 +83,7 @@ const fakeProjectify = { }, }; -var originalFakeUtil = extend(true, {}, fakeUtil); +const originalFakeUtil = extend(true, {}, fakeUtil); function fakeV2() {} @@ -104,10 +104,10 @@ function FakeSink() { } describe('Logging', function() { - var Logging; - var logging; + let Logging; + let logging; - var PROJECT_ID = 'project-id'; + const PROJECT_ID = 'project-id'; before(function() { Logging = proxyquire('../', { @@ -174,8 +174,8 @@ describe('Logging', function() { }); it('should cache a local GoogleAuth instance', function() { - var fakeGoogleAuthInstance = {}; - var options = { + const fakeGoogleAuthInstance = {}; + const options = { a: 'b', c: 'd', }; @@ -195,17 +195,17 @@ describe('Logging', function() { return fakeGoogleAuthInstance; }; - var logging = new Logging(options); + const logging = new Logging(options); assert.strictEqual(logging.auth, fakeGoogleAuthInstance); }); it('should localize the options', function() { - var options = { + const options = { a: 'b', c: 'd', }; - var logging = new Logging(options); + const logging = new Logging(options); assert.notStrictEqual(logging.options, options); @@ -227,13 +227,13 @@ describe('Logging', function() { }); it('should default the projectId to the token', function() { - var logging = new Logging({}); + const logging = new Logging({}); assert.strictEqual(logging.projectId, '{{projectId}}'); }); }); describe('createSink', function() { - var SINK_NAME = 'name'; + const SINK_NAME = 'name'; it('should throw if a name is not provided', function() { assert.throws(function() { @@ -248,9 +248,9 @@ describe('Logging', function() { }); it('should set acls for a Dataset destination', function(done) { - var dataset = {}; + const dataset = {}; - var CONFIG = { + const CONFIG = { destination: dataset, }; @@ -269,9 +269,9 @@ describe('Logging', function() { }); it('should set acls for a Topic destination', function(done) { - var topic = {}; + const topic = {}; - var CONFIG = { + const CONFIG = { destination: topic, }; @@ -290,9 +290,9 @@ describe('Logging', function() { }); it('should set acls for a Bucket destination', function(done) { - var bucket = {}; + const bucket = {}; - var CONFIG = { + const CONFIG = { destination: bucket, }; @@ -312,12 +312,12 @@ describe('Logging', function() { describe('API request', function() { it('should make the correct API request', function(done) { - var config = { + const config = { a: 'b', c: 'd', }; - var expectedConfig = extend({}, config, { + const expectedConfig = extend({}, config, { name: SINK_NAME, }); @@ -325,7 +325,7 @@ describe('Logging', function() { assert.strictEqual(config.client, 'ConfigServiceV2Client'); assert.strictEqual(config.method, 'createSink'); - var expectedParent = 'projects/' + logging.projectId; + const expectedParent = 'projects/' + logging.projectId; assert.strictEqual(config.reqOpts.parent, expectedParent); assert.deepStrictEqual(config.reqOpts.sink, expectedConfig); @@ -338,7 +338,7 @@ describe('Logging', function() { }); it('should accept GAX options', function(done) { - var config = { + const config = { a: 'b', c: 'd', gaxOptions: {}, @@ -354,8 +354,8 @@ describe('Logging', function() { }); describe('error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { logging.request = function(config, callback) { @@ -375,7 +375,7 @@ describe('Logging', function() { }); describe('success', function() { - var apiResponse = { + const apiResponse = { name: SINK_NAME, }; @@ -386,7 +386,7 @@ describe('Logging', function() { }); it('should exec callback with Sink & API response', function(done) { - var sink = {}; + const sink = {}; logging.sink = function(name_) { assert.strictEqual(name_, SINK_NAME); @@ -408,11 +408,11 @@ describe('Logging', function() { }); describe('entry', function() { - var RESOURCE = {}; - var DATA = {}; + const RESOURCE = {}; + const DATA = {}; it('should return an Entry object', function() { - var entry = logging.entry(RESOURCE, DATA); + const entry = logging.entry(RESOURCE, DATA); assert(entry instanceof FakeEntry); assert.strictEqual(entry.calledWith_[0], RESOURCE); assert.strictEqual(entry.calledWith_[1], DATA); @@ -433,7 +433,7 @@ describe('Logging', function() { }); it('should make the correct API request', function(done) { - var options = {}; + const options = {}; logging.request = function(config) { assert.strictEqual(config.client, 'LoggingServiceV2Client'); @@ -458,7 +458,7 @@ describe('Logging', function() { }); it('should not push the same resourceName again', function(done) { - var options = { + const options = { resourceNames: ['projects/' + logging.projectId], }; @@ -473,7 +473,7 @@ describe('Logging', function() { }); it('should allow overriding orderBy', function(done) { - var options = { + const options = { orderBy: 'timestamp asc', }; @@ -486,7 +486,7 @@ describe('Logging', function() { }); it('should accept GAX options', function(done) { - var options = { + const options = { a: 'b', c: 'd', gaxOptions: { @@ -504,7 +504,7 @@ describe('Logging', function() { }); describe('error', function() { - var ARGS = [new Error('Error.'), [], {}]; + const ARGS = [new Error('Error.'), [], {}]; beforeEach(function() { logging.request = function(config, callback) { @@ -514,7 +514,7 @@ describe('Logging', function() { it('should execute callback with error & API response', function(done) { logging.getEntries({}, function() { - var args = [].slice.call(arguments); + const args = [].slice.call(arguments); assert.deepStrictEqual(args, ARGS); done(); }); @@ -522,7 +522,7 @@ describe('Logging', function() { }); describe('success', function() { - var ARGS = [ + const ARGS = [ null, [ { @@ -541,7 +541,7 @@ describe('Logging', function() { logging.getEntries({}, function(err, entries) { assert.ifError(err); - var argsPassedToFromApiResponse_ = entries[0]; + const argsPassedToFromApiResponse_ = entries[0]; assert.strictEqual(argsPassedToFromApiResponse_[0], ARGS[1][0]); done(); @@ -551,7 +551,7 @@ describe('Logging', function() { }); describe('getEntriesStream', function() { - var OPTIONS = { + const OPTIONS = { a: 'b', c: 'd', gaxOptions: { @@ -560,8 +560,8 @@ describe('Logging', function() { }, }; - var REQUEST_STREAM; - var RESULT = {}; + let REQUEST_STREAM; + const RESULT = {}; beforeEach(function() { REQUEST_STREAM = through.obj(); @@ -595,15 +595,15 @@ describe('Logging', function() { return REQUEST_STREAM; }; - var stream = logging.getEntriesStream(OPTIONS); + const stream = logging.getEntriesStream(OPTIONS); stream.emit('reading'); }); it('should convert results from request to Entry', function(done) { - var stream = logging.getEntriesStream(OPTIONS); + const stream = logging.getEntriesStream(OPTIONS); stream.on('data', function(entry) { - var argsPassedToFromApiResponse_ = entry[0]; + const argsPassedToFromApiResponse_ = entry[0]; assert.strictEqual(argsPassedToFromApiResponse_, RESULT); done(); @@ -615,7 +615,7 @@ describe('Logging', function() { it('should expose abort function', function(done) { REQUEST_STREAM.abort = done; - var stream = logging.getEntriesStream(OPTIONS); + const stream = logging.getEntriesStream(OPTIONS); stream.emit('reading'); @@ -624,14 +624,14 @@ describe('Logging', function() { it('should not require an options object', function() { assert.doesNotThrow(function() { - var stream = logging.getEntriesStream(); + const stream = logging.getEntriesStream(); stream.emit('reading'); }); }); }); describe('getSinks', function() { - var OPTIONS = { + const OPTIONS = { a: 'b', c: 'd', gaxOptions: { @@ -672,7 +672,7 @@ describe('Logging', function() { }); describe('error', function() { - var ARGS = [new Error('Error.'), [], {}]; + const ARGS = [new Error('Error.'), [], {}]; beforeEach(function() { logging.request = function(config, callback) { @@ -682,7 +682,7 @@ describe('Logging', function() { it('should execute callback with error & API response', function(done) { logging.getEntries(OPTIONS, function() { - var args = [].slice.call(arguments); + const args = [].slice.call(arguments); assert.deepStrictEqual(args, ARGS); done(); }); @@ -690,7 +690,7 @@ describe('Logging', function() { }); describe('success', function() { - var ARGS = [ + const ARGS = [ null, [ { @@ -707,7 +707,7 @@ describe('Logging', function() { }); it('should execute callback with Logs & API resp', function(done) { - var sinkInstance = {}; + const sinkInstance = {}; logging.sink = function(name) { assert.strictEqual(name, ARGS[1][0].name); @@ -727,7 +727,7 @@ describe('Logging', function() { }); describe('getSinksStream', function() { - var OPTIONS = { + const OPTIONS = { a: 'b', c: 'd', gaxOptions: { @@ -736,8 +736,8 @@ describe('Logging', function() { }, }; - var REQUEST_STREAM; - var RESULT = { + let REQUEST_STREAM; + const RESULT = { name: 'sink-name', }; @@ -772,14 +772,14 @@ describe('Logging', function() { return REQUEST_STREAM; }; - var stream = logging.getSinksStream(OPTIONS); + const stream = logging.getSinksStream(OPTIONS); stream.emit('reading'); }); it('should convert results from request to Sink', function(done) { - var stream = logging.getSinksStream(OPTIONS); + const stream = logging.getSinksStream(OPTIONS); - var sinkInstance = {}; + const sinkInstance = {}; logging.sink = function(name) { assert.strictEqual(name, RESULT.name); @@ -798,7 +798,7 @@ describe('Logging', function() { it('should expose abort function', function(done) { REQUEST_STREAM.abort = done; - var stream = logging.getSinksStream(OPTIONS); + const stream = logging.getSinksStream(OPTIONS); stream.emit('reading'); @@ -807,10 +807,10 @@ describe('Logging', function() { }); describe('log', function() { - var NAME = 'log-name'; + const NAME = 'log-name'; it('should return a Log object', function() { - var log = logging.log(NAME); + const log = logging.log(NAME); assert(log instanceof FakeLog); assert.strictEqual(log.calledWith_[0], logging); assert.strictEqual(log.calledWith_[1], NAME); @@ -818,7 +818,7 @@ describe('Logging', function() { }); describe('request', function() { - var CONFIG = { + const CONFIG = { client: 'client', method: 'method', reqOpts: { @@ -828,7 +828,7 @@ describe('Logging', function() { gaxOpts: {}, }; - var PROJECT_ID = 'project-id'; + const PROJECT_ID = 'project-id'; beforeEach(function() { logging.auth = { @@ -863,7 +863,7 @@ describe('Logging', function() { }); it('should return error if getting project ID failed', function(done) { - var error = new Error('Error.'); + const error = new Error('Error.'); logging.auth.getProjectId = function(callback) { callback(error); @@ -876,7 +876,7 @@ describe('Logging', function() { }); it('should initiate and cache the client', function() { - var fakeClient = { + const fakeClient = { [CONFIG.method]: util.noop, }; @@ -902,7 +902,7 @@ describe('Logging', function() { }); it('should replace the project ID token', function(done) { - var replacedReqOpts = {}; + const replacedReqOpts = {}; replaceProjectIdTokenOverride = function(reqOpts, projectId) { assert.notStrictEqual(reqOpts, CONFIG.reqOpts); @@ -933,7 +933,7 @@ describe('Logging', function() { }; global.GCLOUD_SANDBOX_ENV = true; - var returnValue = logging.request(CONFIG, assert.ifError); + const returnValue = logging.request(CONFIG, assert.ifError); delete global.GCLOUD_SANDBOX_ENV; assert.strictEqual(returnValue, undefined); @@ -957,10 +957,10 @@ describe('Logging', function() { }); it('should execute callback with error', function(done) { - var error = new Error('Error.'); + const error = new Error('Error.'); logging.api[CONFIG.client][CONFIG.method] = function() { - var callback = [].slice.call(arguments).pop(); + const callback = [].slice.call(arguments).pop(); callback(error); }; @@ -972,7 +972,7 @@ describe('Logging', function() { it('should execute the request function', function() { logging.api[CONFIG.client][CONFIG.method] = function(done) { - var callback = [].slice.call(arguments).pop(); + const callback = [].slice.call(arguments).pop(); callback(null, done); // so it ends the test }; @@ -981,7 +981,7 @@ describe('Logging', function() { }); describe('makeRequestStream', function() { - var GAX_STREAM; + let GAX_STREAM; beforeEach(function() { GAX_STREAM = through(); @@ -1001,7 +1001,7 @@ describe('Logging', function() { }; global.GCLOUD_SANDBOX_ENV = true; - var returnValue = logging.request(CONFIG); + const returnValue = logging.request(CONFIG); returnValue.emit('reading'); delete global.GCLOUD_SANDBOX_ENV; @@ -1012,7 +1012,7 @@ describe('Logging', function() { it('should expose an abort function', function(done) { GAX_STREAM.cancel = done; - var requestStream = logging.request(CONFIG); + const requestStream = logging.request(CONFIG); requestStream.emit('reading'); requestStream.abort(); }); @@ -1032,18 +1032,18 @@ describe('Logging', function() { }, }; - var requestStream = logging.request(CONFIG); + const requestStream = logging.request(CONFIG); requestStream.emit('reading'); }); it('should destroy the stream with prepare error', function(done) { - var error = new Error('Error.'); + const error = new Error('Error.'); logging.auth.getProjectId = function(callback) { callback(error); }; - var requestStream = logging.request(CONFIG); + const requestStream = logging.request(CONFIG); requestStream.emit('reading'); requestStream.on('error', function(err) { @@ -1053,9 +1053,9 @@ describe('Logging', function() { }); it('should destroy the stream with GAX error', function(done) { - var error = new Error('Error.'); + const error = new Error('Error.'); - var requestStream = logging.request(CONFIG); + const requestStream = logging.request(CONFIG); requestStream.emit('reading'); requestStream.on('error', function(err) { @@ -1069,10 +1069,10 @@ describe('Logging', function() { }); describe('sink', function() { - var NAME = 'sink-name'; + const NAME = 'sink-name'; it('should return a Log object', function() { - var sink = logging.sink(NAME); + const sink = logging.sink(NAME); assert(sink instanceof FakeSink); assert.strictEqual(sink.calledWith_[0], logging); assert.strictEqual(sink.calledWith_[1], NAME); @@ -1080,10 +1080,10 @@ describe('Logging', function() { }); describe('setAclForBucket_', function() { - var SINK_NAME = 'name'; - var CONFIG; + const SINK_NAME = 'name'; + let CONFIG; - var bucket; + let bucket; beforeEach(function() { bucket = { @@ -1110,8 +1110,8 @@ describe('Logging', function() { }); describe('error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { bucket.acl.owners.addGroup = function(entity, callback) { @@ -1131,7 +1131,7 @@ describe('Logging', function() { }); describe('success', function() { - var apiResponse = {}; + const apiResponse = {}; beforeEach(function() { bucket.acl.owners.addGroup = function(entity, callback) { @@ -1146,7 +1146,7 @@ describe('Logging', function() { assert.strictEqual(config, CONFIG); - var expectedDestination = 'storage.googleapis.com/' + bucket.name; + const expectedDestination = 'storage.googleapis.com/' + bucket.name; assert.strictEqual(config.destination, expectedDestination); callback(); // done() @@ -1161,9 +1161,9 @@ describe('Logging', function() { }); describe('setAclForDataset_', function() { - var SINK_NAME = 'name'; - var CONFIG; - var dataset; + const SINK_NAME = 'name'; + let CONFIG; + let dataset; beforeEach(function() { dataset = { @@ -1180,8 +1180,8 @@ describe('Logging', function() { describe('metadata refresh', function() { describe('error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { dataset.getMetadata = function(callback) { @@ -1200,11 +1200,11 @@ describe('Logging', function() { }); describe('success', function() { - var apiResponse = { + const apiResponse = { access: [{}, {}], }; - var originalAccess = [].slice.call(apiResponse.access); + const originalAccess = [].slice.call(apiResponse.access); beforeEach(function() { dataset.getMetadata = function(callback) { @@ -1213,12 +1213,12 @@ describe('Logging', function() { }); it('should set the correct metadata', function(done) { - var access = { + const access = { role: 'WRITER', groupByEmail: 'cloud-logs@google.com', }; - var expectedAccess = [].slice.call(originalAccess).concat(access); + const expectedAccess = [].slice.call(originalAccess).concat(access); dataset.setMetadata = function(metadata) { assert.deepStrictEqual(apiResponse.access, originalAccess); @@ -1230,8 +1230,8 @@ describe('Logging', function() { }); describe('updating metadata error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { dataset.setMetadata = function(metadata, callback) { @@ -1250,7 +1250,7 @@ describe('Logging', function() { }); describe('updating metadata success', function() { - var apiResponse = {}; + const apiResponse = {}; beforeEach(function() { dataset.setMetadata = function(metadata, callback) { @@ -1260,7 +1260,7 @@ describe('Logging', function() { it('should call createSink with string destination', function(done) { logging.createSink = function(name, config, callback) { - var expectedDestination = [ + const expectedDestination = [ 'bigquery.googleapis.com', 'projects', dataset.parent.projectId, @@ -1282,9 +1282,9 @@ describe('Logging', function() { }); describe('setAclForTopic_', function() { - var SINK_NAME = 'name'; - var CONFIG; - var topic; + const SINK_NAME = 'name'; + let CONFIG; + let topic; beforeEach(function() { topic = { @@ -1302,8 +1302,8 @@ describe('Logging', function() { describe('get policy', function() { describe('error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { topic.iam.getPolicy = function(callback) { @@ -1322,11 +1322,11 @@ describe('Logging', function() { }); describe('success', function() { - var apiResponse = { + const apiResponse = { bindings: [{}, {}], }; - var originalBindings = [].slice.call(apiResponse.bindings); + const originalBindings = [].slice.call(apiResponse.bindings); beforeEach(function() { topic.iam.getPolicy = function(callback) { @@ -1335,12 +1335,12 @@ describe('Logging', function() { }); it('should set the correct policy bindings', function(done) { - var binding = { + const binding = { role: 'roles/pubsub.publisher', members: ['serviceAccount:cloud-logs@system.gserviceaccount.com'], }; - var expectedBindings = [].slice.call(originalBindings); + const expectedBindings = [].slice.call(originalBindings); expectedBindings.push(binding); topic.iam.setPolicy = function(policy) { @@ -1353,8 +1353,8 @@ describe('Logging', function() { }); describe('updating policy error', function() { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; beforeEach(function() { topic.iam.setPolicy = function(policy, callback) { @@ -1373,7 +1373,7 @@ describe('Logging', function() { }); describe('updating policy success', function() { - var apiResponse = {}; + const apiResponse = {}; beforeEach(function() { topic.iam.setPolicy = function(policy, callback) { @@ -1383,7 +1383,7 @@ describe('Logging', function() { it('should call createSink with string destination', function(done) { logging.createSink = function(name, config, callback) { - var expectedDestination = 'pubsub.googleapis.com/' + topic.name; + const expectedDestination = 'pubsub.googleapis.com/' + topic.name; assert.strictEqual(name, SINK_NAME); assert.strictEqual(config, CONFIG); assert.strictEqual(config.destination, expectedDestination); diff --git a/test/log.js b/test/log.js index d6a8a0b3..e3f31982 100644 --- a/test/log.js +++ b/test/log.js @@ -16,15 +16,15 @@ 'use strict'; -var assert = require('assert'); -var extend = require('extend'); -var prop = require('propprop'); -var proxyquire = require('proxyquire'); -var {util} = require('@google-cloud/common-grpc'); +const assert = require('assert'); +const extend = require('extend'); +const prop = require('propprop'); +const proxyquire = require('proxyquire'); +const {util} = require('@google-cloud/common-grpc'); const promisify = require('@google-cloud/promisify'); -var promisifed = false; -var fakePromisify = extend({}, promisify, { +let promisifed = false; +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class, options) { if (Class.name !== 'Log') { return; @@ -34,29 +34,29 @@ var fakePromisify = extend({}, promisify, { }, }); -var Entry = require('../src/entry.js'); +const Entry = require('../src/entry.js'); function FakeMetadata() { this.calledWith_ = arguments; } describe('Log', function() { - var Log; - var log; + let Log; + let log; - var PROJECT_ID = 'project-id'; - var LOG_NAME = 'escaping/required/for/this/log-name'; - var LOG_NAME_ENCODED = encodeURIComponent(LOG_NAME); - var LOG_NAME_FORMATTED = [ + const PROJECT_ID = 'project-id'; + const LOG_NAME = 'escaping/required/for/this/log-name'; + const LOG_NAME_ENCODED = encodeURIComponent(LOG_NAME); + const LOG_NAME_FORMATTED = [ 'projects', PROJECT_ID, 'logs', LOG_NAME_ENCODED, ].join('/'); - var LOGGING; + let LOGGING; - var assignSeverityToEntriesOverride = null; + let assignSeverityToEntriesOverride = null; before(function() { Log = proxyquire('../src/log.js', { @@ -64,7 +64,7 @@ describe('Log', function() { './entry.js': Entry, './metadata.js': FakeMetadata, }); - var assignSeverityToEntries_ = Log.assignSeverityToEntries_; + const assignSeverityToEntries_ = Log.assignSeverityToEntries_; Log.assignSeverityToEntries_ = function() { return ( assignSeverityToEntriesOverride || assignSeverityToEntries_ @@ -98,15 +98,15 @@ describe('Log', function() { }); it('should localize the formatted name', function() { - var formattedName = 'formatted-name'; + const formattedName = 'formatted-name'; - var formatName_ = Log.formatName_; + const formatName_ = Log.formatName_; Log.formatName_ = function() { Log.formatName_ = formatName_; return formattedName; }; - var log = new Log(LOGGING, LOG_NAME_FORMATTED); + const log = new Log(LOGGING, LOG_NAME_FORMATTED); assert.strictEqual(log.formattedName_, formattedName); }); @@ -117,8 +117,8 @@ describe('Log', function() { }); it('should accept and localize options.removeCircular', function() { - var options = {removeCircular: true}; - var log = new Log(LOGGING, LOG_NAME_FORMATTED, options); + const options = {removeCircular: true}; + const log = new Log(LOGGING, LOG_NAME_FORMATTED, options); assert.strictEqual(log.removeCircular_, true); }); @@ -132,12 +132,12 @@ describe('Log', function() { }); describe('assignSeverityToEntries_', function() { - var circular = {}; + const circular = {}; circular.circular = circular; - var ENTRIES = [{data: {a: 'b'}}, {data: {c: 'd'}}, {data: {e: circular}}]; + const ENTRIES = [{data: {a: 'b'}}, {data: {c: 'd'}}, {data: {e: circular}}]; - var SEVERITY = 'severity'; + const SEVERITY = 'severity'; it('should assign severity to a single entry', function() { assert.deepStrictEqual( @@ -158,32 +158,32 @@ describe('Log', function() { }); it('should not affect original array', function() { - var originalEntries = ENTRIES.map(x => extend({}, x)); + const originalEntries = ENTRIES.map(x => extend({}, x)); Log.assignSeverityToEntries_(originalEntries, SEVERITY); assert.deepStrictEqual(originalEntries, ENTRIES); }); }); describe('formatName_', function() { - var PROJECT_ID = 'project-id'; - var NAME = 'log-name'; + const PROJECT_ID = 'project-id'; + const NAME = 'log-name'; - var EXPECTED = 'projects/' + PROJECT_ID + '/logs/' + NAME; + const EXPECTED = 'projects/' + PROJECT_ID + '/logs/' + NAME; it('should properly format the name', function() { assert.strictEqual(Log.formatName_(PROJECT_ID, NAME), EXPECTED); }); it('should encode a name that requires it', function() { - var name = 'appengine/logs'; - var expectedName = 'projects/' + PROJECT_ID + '/logs/appengine%2Flogs'; + const name = 'appengine/logs'; + const expectedName = 'projects/' + PROJECT_ID + '/logs/appengine%2Flogs'; assert.strictEqual(Log.formatName_(PROJECT_ID, name), expectedName); }); it('should not encode a name that does not require it', function() { - var name = 'appengine%2Flogs'; - var expectedName = 'projects/' + PROJECT_ID + '/logs/' + name; + const name = 'appengine%2Flogs'; + const expectedName = 'projects/' + PROJECT_ID + '/logs/' + name; assert.strictEqual(Log.formatName_(PROJECT_ID, name), expectedName); }); @@ -208,7 +208,7 @@ describe('Log', function() { }); it('should accept gaxOptions', function(done) { - var gaxOptions = {}; + const gaxOptions = {}; log.logging.request = function(config) { assert.strictEqual(config.gaxOpts, gaxOptions); @@ -221,12 +221,12 @@ describe('Log', function() { describe('entry', function() { it('should return an entry from Logging', function() { - var metadata = { + const metadata = { val: true, }; - var data = {}; + const data = {}; - var entryObject = {}; + const entryObject = {}; log.logging.entry = function(metadata_, data_) { assert.deepStrictEqual(metadata_, metadata); @@ -234,12 +234,12 @@ describe('Log', function() { return entryObject; }; - var entry = log.entry(metadata, data); + const entry = log.entry(metadata, data); assert.strictEqual(entry, entryObject); }); it('should assume one argument means data', function(done) { - var data = {}; + const data = {}; log.logging.entry = function(metadata, data_) { assert.strictEqual(data_, data); @@ -251,7 +251,7 @@ describe('Log', function() { }); describe('getEntries', function() { - var EXPECTED_OPTIONS = { + const EXPECTED_OPTIONS = { filter: 'logName="' + LOG_NAME_FORMATTED + '"', }; @@ -265,7 +265,7 @@ describe('Log', function() { }); it('should allow overriding the options', function(done) { - var options = { + const options = { custom: true, filter: 'custom filter', }; @@ -280,8 +280,8 @@ describe('Log', function() { }); describe('getEntriesStream', function() { - var fakeStream = {}; - var EXPECTED_OPTIONS = { + const fakeStream = {}; + const EXPECTED_OPTIONS = { filter: 'logName="' + LOG_NAME_FORMATTED + '"', }; @@ -292,12 +292,12 @@ describe('Log', function() { return fakeStream; }; - var stream = log.getEntriesStream(); + const stream = log.getEntriesStream(); assert.strictEqual(stream, fakeStream); }); it('should allow overriding the options', function(done) { - var options = { + const options = { custom: true, filter: 'custom filter', }; @@ -308,15 +308,15 @@ describe('Log', function() { return fakeStream; }; - var stream = log.getEntriesStream(options); + const stream = log.getEntriesStream(options); assert.strictEqual(stream, fakeStream); }); }); describe('write', function() { - var ENTRY = {}; - var OPTIONS = {}; - var FAKE_RESOURCE = 'fake-resource'; + const ENTRY = {}; + const OPTIONS = {}; + const FAKE_RESOURCE = 'fake-resource'; beforeEach(function() { log.decorateEntries_ = function(entries) { @@ -328,8 +328,8 @@ describe('Log', function() { }); it('should forward options.resource to request', function(done) { - var CUSTOM_RESOURCE = 'custom-resource'; - var optionsWithResource = extend({}, OPTIONS, { + const CUSTOM_RESOURCE = 'custom-resource'; + const optionsWithResource = extend({}, OPTIONS, { resource: CUSTOM_RESOURCE, }); @@ -352,17 +352,17 @@ describe('Log', function() { }); it('should transform camelcase label keys to snake case', function(done) { - var CUSTOM_RESOURCE = { + const CUSTOM_RESOURCE = { labels: { camelCaseKey: 'camel-case-key-val', }, }; - var EXPECTED_RESOURCE = { + const EXPECTED_RESOURCE = { labels: { camel_case_key: 'camel-case-key-val', }, }; - var optionsWithResource = extend({}, OPTIONS, { + const optionsWithResource = extend({}, OPTIONS, { resource: CUSTOM_RESOURCE, }); @@ -404,7 +404,7 @@ describe('Log', function() { }); it('should arrify & decorate the entries', function(done) { - var decoratedEntries = []; + const decoratedEntries = []; log.decorateEntries_ = function(entries) { assert.strictEqual(entries[0], ENTRY); @@ -429,8 +429,8 @@ describe('Log', function() { }); describe('severity shortcuts', function() { - var ENTRY = {}; - var LABELS = []; + const ENTRY = {}; + const LABELS = []; beforeEach(function() { log.write = util.noop; @@ -449,7 +449,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -478,7 +478,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -507,7 +507,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -536,7 +536,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -565,7 +565,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -594,7 +594,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -623,7 +623,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -652,7 +652,7 @@ describe('Log', function() { }); it('should pass correct arguments to write', function(done) { - var assignedEntries = []; + const assignedEntries = []; assignSeverityToEntriesOverride = function() { return assignedEntries; @@ -670,7 +670,7 @@ describe('Log', function() { }); describe('decorateEntries_', function() { - var toJSONResponse = {}; + const toJSONResponse = {}; function FakeEntry() {} FakeEntry.prototype.toJSON = function() { @@ -688,14 +688,14 @@ describe('Log', function() { }); it('should create an Entry object if one is not provided', function() { - var entry = {}; + const entry = {}; log.entry = function(entry_) { assert.strictEqual(entry_, entry); return new FakeEntry(); }; - var decoratedEntries = log.decorateEntries_([entry]); + const decoratedEntries = log.decorateEntries_([entry]); assert.strictEqual(decoratedEntries[0], toJSONResponse); }); @@ -704,19 +704,19 @@ describe('Log', function() { throw new Error('should not be called'); }; - var entry = new Entry(); + const entry = new Entry(); entry.toJSON = function() { return toJSONResponse; }; - var decoratedEntries = log.decorateEntries_([entry]); + const decoratedEntries = log.decorateEntries_([entry]); assert.strictEqual(decoratedEntries[0], toJSONResponse); }); it('should pass log.removeCircular to toJSON', function(done) { log.removeCircular_ = true; - var entry = new Entry(); + const entry = new Entry(); entry.toJSON = function(options_) { assert.deepStrictEqual(options_, {removeCircular: true}); setImmediate(done); @@ -727,9 +727,9 @@ describe('Log', function() { }); it('should throw error from serialization', function() { - var error = new Error('Error.'); + const error = new Error('Error.'); - var entry = new Entry(); + const entry = new Entry(); entry.toJSON = function() { throw error; }; diff --git a/test/metadata.js b/test/metadata.js index 65bbcc63..f8526c62 100644 --- a/test/metadata.js +++ b/test/metadata.js @@ -16,15 +16,15 @@ 'use strict'; -var assert = require('assert'); -var extend = require('extend'); -var proxyquire = require('proxyquire'); +const assert = require('assert'); +const extend = require('extend'); +const proxyquire = require('proxyquire'); -var instanceOverride; -var fakeGcpMetadata = { +let instanceOverride; +const fakeGcpMetadata = { instance: function(path) { if (instanceOverride) { - var override = Array.isArray(instanceOverride) + const override = Array.isArray(instanceOverride) ? instanceOverride.find(entry => entry.path === path) : instanceOverride; @@ -45,10 +45,10 @@ var fakeGcpMetadata = { }, }; -var FAKE_READFILE_ERROR_MESSAGE = 'fake readFile error'; -var FAKE_READFILE_CONTENTS = 'fake readFile contents'; -var readFileShouldError; -var fakeFS = { +const FAKE_READFILE_ERROR_MESSAGE = 'fake readFile error'; +const FAKE_READFILE_CONTENTS = 'fake readFile contents'; +let readFileShouldError; +const fakeFS = { readFile: (filename, encoding, callback) => { setImmediate(() => { if (readFileShouldError) callback(new Error(FAKE_READFILE_ERROR_MESSAGE)); @@ -58,13 +58,13 @@ var fakeFS = { }; describe('metadata', function() { - var MetadataCached; - var Metadata; - var metadata; + let MetadataCached; + let Metadata; + let metadata; - var LOGGING; + let LOGGING; - var ENV_CACHED = extend({}, process.env); + const ENV_CACHED = extend({}, process.env); before(function() { Metadata = proxyquire('../src/metadata.js', { @@ -96,8 +96,8 @@ describe('metadata', function() { }); describe('getCloudFunctionDescriptor', function() { - var FUNCTION_NAME = 'function-name'; - var FUNCTION_REGION = 'function-region'; + const FUNCTION_NAME = 'function-name'; + const FUNCTION_REGION = 'function-region'; beforeEach(function() { process.env.FUNCTION_NAME = FUNCTION_NAME; @@ -116,9 +116,9 @@ describe('metadata', function() { }); describe('getGAEDescriptor', function() { - var GAE_MODULE_NAME = 'gae-module-name'; - var GAE_SERVICE = 'gae-service'; - var GAE_VERSION = 'gae-version'; + const GAE_MODULE_NAME = 'gae-module-name'; + const GAE_SERVICE = 'gae-service'; + const GAE_VERSION = 'gae-version'; beforeEach(function() { process.env.GAE_MODULE_NAME = GAE_MODULE_NAME; @@ -139,13 +139,13 @@ describe('metadata', function() { it('should use GAE_MODULE_NAME for module_id', function() { delete process.env.GAE_SERVICE; - var moduleId = Metadata.getGAEDescriptor().labels.module_id; + const moduleId = Metadata.getGAEDescriptor().labels.module_id; assert.strictEqual(moduleId, GAE_MODULE_NAME); }); }); describe('getGKEDescriptor', function() { - var CLUSTER_NAME = 'gke-cluster-name'; + const CLUSTER_NAME = 'gke-cluster-name'; it('should return the correct descriptor', function(done) { instanceOverride = { @@ -167,7 +167,7 @@ describe('metadata', function() { }); it('should return error on failure to acquire metadata', function(done) { - var FAKE_ERROR = new Error(); + const FAKE_ERROR = new Error(); instanceOverride = { errorArg: FAKE_ERROR, }; @@ -189,9 +189,9 @@ describe('metadata', function() { }); describe('getGCEDescriptor', function() { - var INSTANCE_ID = 'fake-instance-id'; - var ZONE_ID = 'morrowind-vivec-1'; - var ZONE_FULL = `projects/fake-project/zones/${ZONE_ID}`; + const INSTANCE_ID = 'fake-instance-id'; + const ZONE_ID = 'morrowind-vivec-1'; + const ZONE_FULL = `projects/fake-project/zones/${ZONE_ID}`; it('should return the correct descriptor', function(done) { instanceOverride = [ @@ -219,7 +219,7 @@ describe('metadata', function() { }); it('should return error on failure to acquire metadata', function(done) { - var FAKE_ERROR = new Error(); + const FAKE_ERROR = new Error(); instanceOverride = { errorArg: FAKE_ERROR, }; @@ -251,7 +251,7 @@ describe('metadata', function() { describe('environments', function() { describe('app engine', function() { it('should return correct descriptor', function(done) { - var DESCRIPTOR = {}; + const DESCRIPTOR = {}; Metadata.getGAEDescriptor = function() { return DESCRIPTOR; @@ -271,7 +271,7 @@ describe('metadata', function() { describe('cloud function', function() { it('should return correct descriptor', function(done) { - var DESCRIPTOR = {}; + const DESCRIPTOR = {}; Metadata.getCloudFunctionDescriptor = function() { return DESCRIPTOR; @@ -291,9 +291,9 @@ describe('metadata', function() { describe('compute engine', function() { it('should return correct descriptor', function(done) { - var INSTANCE_ID = 'overridden-value'; - var ZONE_ID = 'cyrodiil-anvil-2'; - var ZONE_FULL = `projects/fake-project/zones/${ZONE_ID}`; + const INSTANCE_ID = 'overridden-value'; + const ZONE_ID = 'cyrodiil-anvil-2'; + const ZONE_FULL = `projects/fake-project/zones/${ZONE_ID}`; instanceOverride = [ { path: 'id', @@ -325,7 +325,7 @@ describe('metadata', function() { describe('container engine', function() { it('should return correct descriptor', function(done) { - var CLUSTER_NAME = 'overridden-value'; + const CLUSTER_NAME = 'overridden-value'; instanceOverride = { path: 'attributes/cluster-name', successArg: {data: CLUSTER_NAME}, @@ -351,7 +351,7 @@ describe('metadata', function() { describe('global', function() { it('should return correct descriptor', function(done) { - var DESCRIPTOR = {}; + const DESCRIPTOR = {}; Metadata.getGlobalDescriptor = function() { return DESCRIPTOR; diff --git a/test/sink.js b/test/sink.js index 12151988..1d60e592 100644 --- a/test/sink.js +++ b/test/sink.js @@ -16,14 +16,14 @@ 'use strict'; -var assert = require('assert'); -var extend = require('extend'); -var proxyquire = require('proxyquire'); -var {util} = require('@google-cloud/common-grpc'); +const assert = require('assert'); +const extend = require('extend'); +const proxyquire = require('proxyquire'); +const {util} = require('@google-cloud/common-grpc'); const promisify = require('@google-cloud/promisify'); -var promisifed = false; -var fakePromisify = extend({}, promisify, { +let promisifed = false; +const fakePromisify = extend({}, promisify, { promisifyAll: function(Class) { if (Class.name === 'Sink') { promisifed = true; @@ -32,14 +32,14 @@ var fakePromisify = extend({}, promisify, { }); describe('Sink', function() { - var Sink; - var sink; + let Sink; + let sink; - var LOGGING = { + const LOGGING = { createSink: util.noop, projectId: 'project-id', }; - var SINK_NAME = 'sink-name'; + const SINK_NAME = 'sink-name'; before(function() { Sink = proxyquire('../src/sink.js', { @@ -74,7 +74,7 @@ describe('Sink', function() { describe('create', function() { it('should call parent createSink', function(done) { - var config = {}; + const config = {}; sink.logging.createSink = function(name, config_, callback) { assert.strictEqual(name, sink.name); @@ -105,7 +105,7 @@ describe('Sink', function() { }); it('should accept gaxOptions', function(done) { - var gaxOptions = {}; + const gaxOptions = {}; sink.logging.request = function(config) { assert.strictEqual(config.gaxOpts, gaxOptions); @@ -135,7 +135,7 @@ describe('Sink', function() { }); it('should accept gaxOptions', function(done) { - var gaxOptions = {}; + const gaxOptions = {}; sink.logging.request = function(config) { assert.strictEqual(config.gaxOpts, gaxOptions); @@ -146,7 +146,7 @@ describe('Sink', function() { }); it('should update metadata', function(done) { - var metadata = {}; + const metadata = {}; sink.logging.request = function(config, callback) { callback(null, metadata); @@ -159,7 +159,7 @@ describe('Sink', function() { }); it('should execute callback with original arguments', function(done) { - var args = [{}, {}, {}]; + const args = [{}, {}, {}]; sink.logging.request = function(config, callback) { callback.apply(null, args); @@ -173,7 +173,7 @@ describe('Sink', function() { }); describe('setFilter', function() { - var FILTER = 'filter'; + const FILTER = 'filter'; it('should call set metadata', function(done) { sink.setMetadata = function(metadata, callback) { @@ -186,7 +186,7 @@ describe('Sink', function() { }); describe('setMetadata', function() { - var METADATA = {a: 'b', c: 'd'}; + const METADATA = {a: 'b', c: 'd'}; beforeEach(function() { sink.getMetadata = function(callback) { @@ -203,8 +203,8 @@ describe('Sink', function() { }); it('should exec callback with error from refresh', function(done) { - var error = new Error('Error.'); - var apiResponse = {}; + const error = new Error('Error.'); + const apiResponse = {}; sink.getMetadata = function(callback) { callback(error, null, apiResponse); @@ -218,7 +218,7 @@ describe('Sink', function() { }); it('should make the correct request', function(done) { - var currentMetadata = {a: 'a', e: 'e'}; + const currentMetadata = {a: 'a', e: 'e'}; sink.getMetadata = function(callback) { callback(null, currentMetadata); @@ -242,7 +242,7 @@ describe('Sink', function() { }); it('should accept gaxOptions', function(done) { - var metadata = extend({}, METADATA, { + const metadata = extend({}, METADATA, { gaxOptions: {}, }); @@ -256,7 +256,7 @@ describe('Sink', function() { }); it('should update metadata', function(done) { - var metadata = {}; + const metadata = {}; sink.logging.request = function(config, callback) { callback(null, metadata); @@ -269,7 +269,7 @@ describe('Sink', function() { }); it('should execute callback with original arguments', function(done) { - var args = [{}, {}, {}]; + const args = [{}, {}, {}]; sink.logging.request = function(config, callback) { callback.apply(null, args);