-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
81 lines (65 loc) · 1.86 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict'
const test = require('tape')
const nock = require('nock')
const path = require('path')
const fs = require('fs')
const plugin = require('.')
const FIXTURE_V2_PATH = path.join(__dirname, 'v2-task-metadata-fixture.json')
const FIXTURE_V2 = JSON.parse(fs.readFileSync(FIXTURE_V2_PATH, 'utf8'))
const FIXTURE_V3_PATH = path.join(__dirname, 'v3-task-metadata-fixture.json')
const FIXTURE_V3 = JSON.parse(fs.readFileSync(FIXTURE_V3_PATH, 'utf8'))
test('v2', function (t) {
t.plan(3)
const processor = plugin({ version: 2 })
const metric = { tags: { existing: '1' } }
nock(processor._endpoint)
.get('/metadata').reply(function () {
t.pass('got /metadata request')
return [200, FIXTURE_V2]
})
processor.start((err) => {
t.ifError(err, 'no start error')
processor.on('metric', (metric) => {
t.same(metric, {
tags: {
existing: '1',
cluster: 'default',
region: 'us-west-1'
// Yet to do
// name: 'nginx-curl',
// image: 'nrdlngr/nginx-curl'
}
})
})
processor.process(metric)
})
})
test('v3', function (t) {
t.plan(4)
const processor = plugin({ version: 3, endpoint: 'http://localhost' })
const metric = { tags: { existing: '1' } }
nock(processor._endpoint)
.get('/task').reply(function () {
t.pass('got /task request')
return [200, FIXTURE_V3]
})
.get('/').reply(function () {
t.pass('got / request')
return [200, FIXTURE_V3.Containers[1]]
})
processor.start((err) => {
t.ifError(err, 'no start error')
processor.on('metric', (metric) => {
t.same(metric, {
tags: {
existing: '1',
cluster: 'default',
region: 'us-west-2',
name: 'nginx-curl',
image: 'nrdlngr/nginx-curl'
}
})
})
processor.process(metric)
})
})