Skip to content

Commit

Permalink
fix: Minor fixes in previously added extended logging
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Oct 11, 2016
1 parent f663db3 commit 4693b61
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/add-hooks.coffee
Expand Up @@ -46,7 +46,7 @@ addHooks = (runner, transactions, callback) ->
catch error
logger.warn("""\
Skipping hook loading. Error reading hook file '#{filePath}'. \
This probably means one or more of your hook files is invalid.
This probably means one or more of your hook files are invalid.
Message: #{error.message}
Stack: #{error.stack}
""")
Expand Down Expand Up @@ -88,10 +88,10 @@ addHooks = (runner, transactions, callback) ->
loadSandboxHooksFromStrings(callback)
else
# not sandboxed code can't be loaded from the string
msg = """\
msg = '''\
Not sandboxed hooks loading from strings is not implemented, \
Sandbox mode must be enabled when loading hooks from strings.\
"""
'''
callback(new Error(msg))
else

Expand Down
7 changes: 4 additions & 3 deletions src/apply-configuration.coffee → src/configuration.coffee
Expand Up @@ -16,10 +16,11 @@ coerceToArray = (value) ->


applyLoggingOptions = (options) ->
# coerce color to bool
if options.color == 'false'
# Color can be either specified as "stringified bool" or bool (nothing else
# is expected valid value). Here we're coercing the value to boolean.
if options.color is 'false'
options.color = false
else if options.color == 'true'
else if options.color is 'true'
options.color = true

logger.transports.console.colorize = options.color
Expand Down
2 changes: 1 addition & 1 deletion src/dredd-command.coffee
Expand Up @@ -9,7 +9,7 @@ execSync = require('sync-exec')

Dredd = require './dredd'
interactiveConfig = require './interactive-config'
{applyLoggingOptions} = require './apply-configuration'
{applyLoggingOptions} = require './configuration'
configUtils = require './config-utils'
logger = require('./logger')

Expand Down
2 changes: 1 addition & 1 deletion src/dredd.coffee
Expand Up @@ -7,7 +7,7 @@ url = require 'url'
logger = require('./logger')
options = require './options'
Runner = require './transaction-runner'
{applyConfiguration} = require './apply-configuration'
{applyConfiguration} = require './configuration'
handleRuntimeProblems = require './handle-runtime-problems'
dreddTransactions = require 'dredd-transactions'
configureReporters = require './configure-reporters'
Expand Down
22 changes: 11 additions & 11 deletions src/reporters/apiary-reporter.coffee
Expand Up @@ -192,20 +192,20 @@ class ApiaryReporter
res.setEncoding 'utf8'

res.on 'data', (chunk) ->
logger.verbose('Apiary Reporter HTTP response chunk:', chunk)
logger.verbose('Apiary reporter received HTTP response chunk:', chunk)
buffer = buffer + chunk

res.on 'error', (error) ->
logger.debug('Apiary Reporter HTTP response error:', error)
logger.debug('Apiary reporter got HTTP response error:', error)
return callback error, req, res

res.on 'end', ->
logger.verbose('Apiary reporter Response received.')
logger.verbose('Apiary reporter received response from Apiary API.')

try
parsedBody = JSON.parse buffer
catch e
return callback new Error("Apiary reporter: Failed to parse Apiary API response body:\n#{buffer}")
return callback new Error("Apiary reporter failed to parse Apiary API response body: #{e.message}\n#{buffer}")

info = {headers: res.headers, statusCode: res.statusCode, body: parsedBody}
logger.verbose('Apiary reporter response:', JSON.stringify(info, null, 2))
Expand All @@ -229,7 +229,7 @@ class ApiaryReporter
unless @configuration['apiToken'] == null
options.headers['Authentication'] = 'Token ' + @configuration['apiToken']

logger.verbose('Apiary reporter request:', JSON.stringify({options: options, body}, null, 2))
logger.verbose('Apiary reporter request:', JSON.stringify({options, body}, null, 2))

handleReqError = (error) =>
@serverError = true
Expand All @@ -238,16 +238,16 @@ class ApiaryReporter
else
return callback error, req, null

logger.verbose('Starting Apiary reporter HTTP request')
if @configuration.apiUrl.match(/^https/)
logger.verbose('Starting HTTP request from Apiary reporter to Apiary API')
if @configuration.apiUrl?.match(/^https/)
logger.debug('Using HTTPS for Apiary reporter request')
req = https.request options, handleResponse
req = https.request(options, handleResponse)
else
logger.debug('Using unsecured HTTP for Apiary reporter request')
req = http.request options, handleResponse
req = http.request(options, handleResponse)

req.on 'error', handleReqError
req.write postData
req.on('error', handleReqError)
req.write(postData)
req.end()


Expand Down
@@ -1,11 +1,11 @@
{assert} = require('chai')
clone = require('clone')

applyConfiguration = require('../../src/apply-configuration')
configuration = require('../../src/configuration')
logger = require('../../src/logger')


describe('applyLoggingOptions()', ->
describe('configuration.applyLoggingOptions()', ->
loggerSettings = undefined
config = undefined

Expand All @@ -17,7 +17,7 @@ describe('applyLoggingOptions()', ->
)

it('applies logging options', ->
config = applyConfiguration.applyLoggingOptions(
config = configuration.applyLoggingOptions(
color: 'true'
level: 'debug'
)
Expand All @@ -31,21 +31,21 @@ describe('applyLoggingOptions()', ->

describe('with color set to legacy \'true\' string value', ->
it('resulting configuration should contain \'color\' set to boolean true', ->
options = applyConfiguration.applyLoggingOptions({color: 'true'})
options = configuration.applyLoggingOptions({color: 'true'})
assert.propertyVal(options, 'color', true)
)
)

describe('with color option set to legacy \'false\' string value', ->
it('resulting configuration should contain \'color\' set to boolean false', ->
options = applyConfiguration.applyLoggingOptions({color: 'false'})
options = configuration.applyLoggingOptions({color: 'false'})
assert.propertyVal(options, 'color', false)
)
)
)


describe('applyConfiguration()', ->
describe('configuration.applyConfiguration()', ->
loggerSettings = undefined
config = undefined

Expand All @@ -57,7 +57,7 @@ describe('applyConfiguration()', ->
)

it('applies logging options', ->
config = applyConfiguration.applyConfiguration(
config = configuration.applyConfiguration(
options:
color: 'true'
level: 'debug'
Expand Down

0 comments on commit 4693b61

Please sign in to comment.