Skip to content

Commit

Permalink
Update @xen-orchestra/log/logger.test.js
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Fontanet <[email protected]>
  • Loading branch information
2 people authored and Stephane MEYER committed Sep 24, 2024
1 parent 928e364 commit d2497fa
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions @xen-orchestra/log/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('logger', () => {

const logsTransportDebug = []
const transportDebug = message => {
logsTransportDefault.push(message)
logsTransportDebug.push(message)
}

const logsTransportFatal = []
Expand All @@ -29,12 +29,12 @@ describe('logger', () => {
},
{
level: 'debug',
transport: transportTest,
transport: transportDebug,
},
])
)

logsTransportDefault.length = 0
logsTransportDebug.length = 0
logsTransportFatal.length = 0
})

Expand All @@ -46,10 +46,10 @@ describe('logger', () => {
time: new Date(),
}
logger.debug(expected1.message)
assert.equal(logsTransportDefault[0].message, expected1.message)
assert.equal(typeof logsTransportDefault[0].level, 'number', `level attribute should exist`)
assert.equal(typeof logsTransportDefault[0].namespace, 'string', `namespace attribute should exist`)
assert.equal(logsTransportDefault[0].time instanceof Date, true, 'time attribute should exist')
assert.equal(logsTransportDebug[0].message, expected1.message)
assert.equal(typeof logsTransportDebug[0].level, 'number', `level attribute should exist`)
assert.equal(typeof logsTransportDebug[0].namespace, 'string', `namespace attribute should exist`)
assert.equal(logsTransportDebug[0].time instanceof Date, true, 'time attribute should exist')
})
it('should log test 1 and 2', () => {
const expected1 = {
Expand All @@ -66,8 +66,8 @@ describe('logger', () => {
}
logger.debug(expected1.message)
logger.debug(expected2.message)
assert.equal(logsTransportDefault[0].message, expected1.message)
assert.equal(logsTransportDefault[1].message, expected2.message)
assert.equal(logsTransportDebug[0].message, expected1.message)
assert.equal(logsTransportDebug[1].message, expected2.message)
})
it('should log tests for debug', () => {
const expectedDebug = {
Expand All @@ -78,8 +78,8 @@ describe('logger', () => {
time: new Date(),
}
logger.debug(expectedDebug.message)
assert.deepEqual(logsTransportDefault[0].message, expectedDebug.message)
assert.deepEqual(logsTransportDefault[0].level, expectedDebug.level)
assert.deepEqual(logsTransportDebug[0].message, expectedDebug.message)
assert.deepEqual(logsTransportDebug[0].level, expectedDebug.level)
})
it('should log tests for info', () => {
const expectedInfo = {
Expand All @@ -90,8 +90,8 @@ describe('logger', () => {
time: new Date(),
}
logger.info(expectedInfo.message)
assert.deepEqual(logsTransportDefault[0].message, expectedInfo.message)
assert.deepEqual(logsTransportDefault[0].level, expectedInfo.level)
assert.deepEqual(logsTransportDebug[0].message, expectedInfo.message)
assert.deepEqual(logsTransportDebug[0].level, expectedInfo.level)
})
it('should log tests for warn', () => {
const expectedWarn = {
Expand All @@ -102,8 +102,8 @@ describe('logger', () => {
time: new Date(),
}
logger.warn(expectedWarn.message)
assert.deepEqual(logsTransportDefault[0].message, expectedWarn.message)
assert.deepEqual(logsTransportDefault[0].level, expectedWarn.level)
assert.deepEqual(logsTransportDebug[0].message, expectedWarn.message)
assert.deepEqual(logsTransportDebug[0].level, expectedWarn.level)
})
it('should log tests for error', () => {
const expectedError = {
Expand All @@ -114,8 +114,8 @@ describe('logger', () => {
time: new Date(),
}
logger.error(expectedError.message)
assert.deepEqual(logsTransportDefault[0].message, expectedError.message)
assert.deepEqual(logsTransportDefault[0].level, expectedError.level)
assert.deepEqual(logsTransportDebug[0].message, expectedError.message)
assert.deepEqual(logsTransportDebug[0].level, expectedError.level)
assert.ok(logsTransportFatal.length === 0, 'fatal logs should be empty')
})
it('should log tests for fatal', () => {
Expand All @@ -139,7 +139,7 @@ describe('logger', () => {
time: new Date(),
}
logger.debug(null)
assert.deepEqual(logsTransportDefault[0].data, expected1.data)
assert.deepEqual(logsTransportDebug[0].data, expected1.data)
})
it('should log an error on undefined', () => {
const expected1 = {
Expand All @@ -150,35 +150,35 @@ describe('logger', () => {
time: new Date(),
}
logger.debug(undefined)
assert.deepEqual(logsTransportDefault[0].data, expected1.data)
assert.deepEqual(logsTransportDebug[0].data, expected1.data)
})
it('should not dedup logs', () => {
configure(
createCaptureTransport([
{
transport: transportTest,
transport: transportDebug,
},
])
)

for (let i = 0; i < 3; i++) {
logger.debug('this line should be logged 3 times')
}
assert.equal(logsTransportDefault.length, 3)
assert.equal(logsTransportDebug.length, 3)
})
it('should dedup logs', () => {
configure(
createCaptureTransport([
dedupe({
timeout: 50, // without a defined timeout, the test will wait for 10 minutes
transport: transportTest,
transport: transportDebug,
}),
])
)

for (let i = 0; i < 3; i++) {
logger.debug('this line should be logged only once')
}
assert.equal(logsTransportDefault.length, 1)
assert.equal(logsTransportDebug.length, 1)
})
})

0 comments on commit d2497fa

Please sign in to comment.