-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
44 lines (35 loc) · 888 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const test = require('tape')
const proxyquire = require('proxyquire')
const infoSpies = []
const plugin = proxyquire('.', {
'ec2-info': function (...args) {
infoSpies.shift()(...args)
}
})
test('basic', function (t) {
t.plan(4)
infoSpies.push((properties, callback) => {
t.same(properties, ['dynamic/instance-identity/document'])
process.nextTick(callback, null, new Map([
['dynamic/instance-identity/document', JSON.stringify({
region: 'fake_region'
})]
]))
})
const p = plugin()
const metric = { tags: { existing: '1' } }
p.start((err) => {
t.ifError(err, 'no start error')
t.is(infoSpies.length, 0, 'ec2-info called')
p.on('metric', (metric) => {
t.same(metric, {
tags: {
existing: '1',
region: 'fake_region'
}
})
})
p.process(metric)
})
})