Skip to content

Commit

Permalink
Fixed integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalieWolfe committed Mar 5, 2018
1 parent 8bd70a1 commit 439571f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 38 deletions.
23 changes: 13 additions & 10 deletions test/integration/agent/send-errors.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
var helper = require('../../lib/agent_helper')
var tap = require('tap')

var DESTS = require('../../../lib/config/attribute-filter').DESTINATIONS


tap.test('Agent#_sendErrors', function(t) {
t.plan(2)

Expand Down Expand Up @@ -83,19 +86,19 @@ tap.test('Agent#_sendErrors', function(t) {

helper.runInTransaction(agent, function(tx) {
tx.finalizeNameFromUri('/nonexistent', 501)
tx.addAgentAttribute('foo', 'bar')
tx.addAgentAttribute('request.uri', '/nonexistent')
tx.trace.addAttribute(DESTS.ERROR_EVENT, 'foo', 'bar')
tx.trace.addAttribute(DESTS.ERROR_EVENT, 'request.uri', '/nonexistent')
agent.errors.add(tx, new Error('test error'))
tx.end()
})
})
}

function setupAgent(t, config) {
var agent = helper.loadMockedAgent(null, config)
t.tearDown(function() {
helper.unloadAgent(agent)
})
return agent
}
})

function setupAgent(t, config) {
var agent = helper.loadMockedAgent(null, config)
t.tearDown(function() {
helper.unloadAgent(agent)
})
return agent
}
34 changes: 23 additions & 11 deletions test/integration/config/attribute-cat.tap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

var _ = require('lodash')
var Config = require('../../../lib/config')
var helper = require('../../lib/agent_helper')
var tap = require('tap')
var tests = require('../../lib/cross_agent_tests/attribute_configuration')
Expand All @@ -14,21 +16,31 @@ var DEST_TO_ID = {
tap.test('Attribute include/exclude configurations', function(t) {
t.plan(tests.length)

var agent = helper.loadMockedAgent()
t.tearDown(function() {
helper.unloadAgent(agent)
})

tests.forEach(function(test) {
runTest(t, test)
})
})

function runTest(t, test) {
// Load the agent and set the test configuration as if from the server.
// We don't actually need the agent, so unload it immediately after.
var agent = helper.loadMockedAgent(null, {attributes: {enabled: true}})
agent.config.onConnect(test.config)
helper.unloadAgent(agent)
// The tests list the configurations in flat, dot notation (i.e.
// `transaction_tracer.attributes.enabled`). We need to expand that into a
// deep object in order for our config to load it as though it came from the
// `newrelic.js` file.
var config = Object.keys(test.config).reduce(function(conf, key) {
return _.set(conf, key, test.config[key])
}, {})
config = new Config(config)


// Filter the destinations.
var destinations = test.input_default_destinations.filter(function(dest) {
return agent.config.attributeFilter.test(DEST_TO_ID[dest], test.input_key)
var destId = DEST_TO_ID[dest]
return config.attributeFilter.filter(destId, test.input_key) & destId
})

// Did we pass?
Expand All @@ -40,11 +52,11 @@ function runTest(t, test) {
input: test.config,
key: test.input_key,
___: '___',
attrs: agent.config.attributes,
trace_attrs: agent.config.transaction_tracer.attributes,
tx_event_attrs: agent.config.transaction_events.attributes,
error_attrs: agent.config.error_collector.attributes,
browser_attrs: agent.config.browser_monitoring.attributes
attrs: config.attributes,
trace_attrs: config.transaction_tracer.attributes,
tx_event_attrs: config.transaction_events.attributes,
error_attrs: config.error_collector.attributes,
browser_attrs: config.browser_monitoring.attributes
}, null, 2))
}
}
63 changes: 50 additions & 13 deletions test/integration/flatten.tap.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
'use strict'

var tap = require('tap')
, test = tap.test
, flatten = require('../../lib/util/flatten')

var flatten = require('../../lib/util/flatten')

test('flatten flattens things', function (t) {
t.deepEqual(flatten({}, '', {a: 5, b: true}), {a: 5, b: true}, '1 level')
t.deepEqual(flatten({}, '', {a: 5, b: {c: true, d: 7}}), {a: 5, 'b.c': true, 'b.d': 7}, '2 levels')
t.deepEqual(flatten({}, '', {a: 5, b: {c: true, d: 7, e: {foo: 'efoo', bar: 'ebar'}}}), {a: 5, 'b.c': true, 'b.d': 7, 'b.e.foo': 'efoo', 'b.e.bar': 'ebar'}, '3 levels')
tap.test('util.flatten', function(t) {
t.autoend()

t.end()
t.test('flattens things', function(t) {
t.deepEqual(flatten({}, '', {a: 5, b: true}), {a: 5, b: true}, '1 level')
t.deepEqual(
flatten({}, '', {a: 5, b: {c: true, d: 7}}),
{a: 5, 'b.c': true, 'b.d': 7},
'2 levels'
)
t.deepEqual(
flatten({}, '', {a: 5, b: {c: true, d: 7, e: {foo: 'efoo', bar: 'ebar'}}}),
{a: 5, 'b.c': true, 'b.d': 7, 'b.e.foo': 'efoo', 'b.e.bar': 'ebar'},
'3 levels'
)

t.end()
})

t.test('flattens recursive objects', function(t) {
var obj = {}
obj.x = obj
t.deepEqual(flatten({}, '', obj), {})

t.end()
})
})

test('flatten a recursive object', function (t) {
var obj = {}
obj.x = obj
t.deepEqual(flatten({}, '', obj), {})
tap.test('util.flatten.keys', function(t) {
t.autoend()

t.test('gets flattened keys', function(t) {
t.deepEqual(flatten.keys({a: 5, b: true}), ['a', 'b'], '1 level')
t.deepEqual(
flatten.keys({a: 5, b: {c: true, d: 7}}),
['a', 'b.c', 'b.d'],
'2 levels'
)
t.deepEqual(
flatten.keys({a: 5, b: {c: true, d: 7, e: {foo: 'efoo', bar: 'ebar'}}}),
['a', 'b.c', 'b.d', 'b.e.foo', 'b.e.bar'],
'3 levels'
)

t.end()
})

t.end()
t.test('flattens recursive objects', function(t) {
var obj = {}
obj.x = obj
t.deepEqual(flatten.keys(obj), [])
t.end()
})
})
12 changes: 8 additions & 4 deletions test/integration/transaction/errors.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test('errors in web transactions should gather the query params', function(t) {
var http = require('http')

agent.config.attributes.enabled = true
agent.config.attributes.include = ['request.parameters.*']
agent.config.emit('attributes.include')

http.createServer(function(req, res) {
req.resume()
Expand Down Expand Up @@ -64,12 +66,12 @@ test('errors in web transactions should gather the query params', function(t) {
'should have collected the query, request, and response params'
)
t.equal(
attributes.agentAttributes.some,
attributes.agentAttributes['request.parameters.some'],
'param',
'should have collected a query param with a value'
)
t.equal(
attributes.agentAttributes.data,
attributes.agentAttributes['request.parameters.data'],
true,
'should have collected a query param without a value'
)
Expand All @@ -88,6 +90,8 @@ test('multiple errors in web transactions should gather the query params', funct
]

agent.config.attributes.enabled = true
agent.config.attributes.include = ['request.parameters.*']
agent.config.emit('attributes.include')

http.createServer(function(req, res) {
req.resume()
Expand Down Expand Up @@ -144,12 +148,12 @@ test('multiple errors in web transactions should gather the query params', funct
'should have collected the query, request, and response params'
)
t.equal(
attributes.agentAttributes.some,
attributes.agentAttributes['request.parameters.some'],
'param',
'should have collected a query param with a value'
)
t.equal(
attributes.agentAttributes.data,
attributes.agentAttributes['request.parameters.data'],
true,
'should have collected a query param without a value'
)
Expand Down

0 comments on commit 439571f

Please sign in to comment.