Skip to content

Commit

Permalink
chore: Migrate bunyan, pino, and winston tests to node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Oct 4, 2024
1 parent 86231b7 commit 1b20995
Show file tree
Hide file tree
Showing 15 changed files with 1,448 additions and 1,416 deletions.
31 changes: 19 additions & 12 deletions test/lib/logging-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
*/

'use strict'
const helpers = module.exports
const tap = require('tap')

tap.Test.prototype.addAssert('validateAnnotations', 2, validateLogLine)
const assert = require('node:assert')

// NOTE: pino adds hostname to log lines which is why we don't check it here
helpers.CONTEXT_KEYS = [
const CONTEXT_KEYS = [
'entity.name',
'entity.type',
'entity.guid',
Expand All @@ -23,21 +21,30 @@ helpers.CONTEXT_KEYS = [
* To be registered as a tap assertion
*/
function validateLogLine({ line: logLine, message, level, config }) {
this.equal(
assert.equal(
logLine['entity.name'],
config.applications()[0],
'should have entity name that matches app'
)
this.equal(logLine['entity.guid'], 'test-guid', 'should have set entitye guid')
this.equal(logLine['entity.type'], 'SERVICE', 'should have entity type of SERVICE')
this.equal(logLine.hostname, config.getHostnameSafe(), 'should have proper hostname')
this.match(logLine.timestamp, /[0-9]{10}/, 'should have proper unix timestamp')
this.notOk(logLine.message.includes('NR-LINKING'), 'should not contain NR-LINKING metadata')
assert.equal(logLine['entity.guid'], 'test-guid', 'should have set entity guid')
assert.equal(logLine['entity.type'], 'SERVICE', 'should have entity type of SERVICE')
assert.equal(logLine.hostname, config.getHostnameSafe(), 'should have proper hostname')
assert.equal(/[0-9]{10}/.test(logLine.timestamp), true, 'should have proper unix timestamp')
assert.equal(
logLine.message.includes('NR-LINKING'),
false,
'should not contain NR-LINKING metadata'
)
if (message) {
this.equal(logLine.message, message, 'message should be the same as log')
assert.equal(logLine.message, message, 'message should be the same as log')
}

if (level) {
this.equal(logLine.level, level, 'level should be string value not number')
assert.equal(logLine.level, level, 'level should be string value not number')
}
}

module.exports = {
CONTEXT_KEYS,
validateLogLine
}
271 changes: 0 additions & 271 deletions test/versioned/bunyan/bunyan.tap.js

This file was deleted.

Loading

0 comments on commit 1b20995

Please sign in to comment.