Skip to content

Commit

Permalink
Added test case to keep 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mex committed Jan 27, 2020
1 parent f7f889b commit a8c215c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/metric.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sinon = require('sinon')
describe('src/metric.js', () => {
beforeEach(() => {
this.createKey = sinon.spy(MetricRegistry.prototype, 'createKey')
sinon.useFakeTimers(Date.parse('2017-09-01T13:37:42Z'))
this.clock = sinon.useFakeTimers(Date.parse('2017-09-01T13:37:42Z'))
this.metricRegistry = new MetricRegistry()

process.env.LOG_LEVEL = 'STATISTIC'
Expand Down Expand Up @@ -178,4 +178,37 @@ describe('src/metric.js', () => {
})
)
})

it('does not log old metrics', async () => {
const statistic = sinon.stub(console, 'log')
await this.metricRegistry.gauge('gauge', 4, { brand: 'vw' })
await this.metricRegistry.gauge('gauge', 5, { brand: 'vw' })
this.clock.tick(24 * 60 * 60 * 1000 + 1)
await this.metricRegistry.cumulative('cumulative', 20, { brand: 'vw' })
await this.metricRegistry.logMetrics()

expect(statistic.callCount, 'to be', 1)
expect(statistic.args[0].length, 'to be', 1)
expect(
statistic.args[0][0],
'to equal',
JSON.stringify({
message: 'Metric dump',
context: {
metrics: [
{
name: 'cumulative',
type: 'CUMULATIVE',
value: 20,
labels: { brand: 'vw' },
startTime: '2017-09-02T13:37:42.001Z',
endTime: '2017-09-02T13:37:42.001Z'
}
]
},
severity: 'STATISTIC',
timestamp: '2017-09-02T13:37:42.001Z'
})
)
})
})

0 comments on commit a8c215c

Please sign in to comment.