-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
67 lines (54 loc) · 1.33 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict'
const test = require('tape')
const proxyquire = require('proxyquire')
const spies = []
const plugin = proxyquire('.', {
'ec2-info': function (...args) {
spies.shift()(...args)
}
})
test('basic', function (t) {
t.plan(4)
spies.push((properties, callback) => {
t.same(properties, ['meta-data/instance-id'])
process.nextTick(callback, null, new Map([['meta-data/instance-id', 'beep']]))
})
const p = plugin()
const metric = { tags: { existing: '1' } }
p.start((err) => {
t.ifError(err, 'no start error')
t.is(spies.length, 0, 'ec2-info called')
p.on('metric', (metric) => {
t.same(metric, {
tags: {
existing: '1',
instanceid: 'beep'
}
})
})
p.process(metric)
})
})
test('cached', function (t) {
t.plan(5)
spies.push((properties, callback) => {
t.pass('called only once')
process.nextTick(callback, null, new Map([['meta-data/instance-id', 'beep']]))
})
const p1 = plugin.cached()
const p2 = plugin.cached()
for (const p of [p1, p2]) {
p.start((err) => {
t.ifError(err, 'no start error')
p.on('metric', (metric) => {
t.same(metric, {
tags: {
existing: '1',
instanceid: 'beep'
}
})
})
p.process({ tags: { existing: '1' } })
})
}
})