-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnaming.test.ts
72 lines (59 loc) · 1.52 KB
/
naming.test.ts
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
import test from 'ava';
import * as _ from 'lodash';
import * as mock from 'mock-require';
import { SrvRecord } from 'dns';
let srvRecords = [];
mock('dns', {
resolveSrv(name, cb) {
return cb(null, srvRecords);
},
});
import { DNSResolver, UpdateOp } from '../src/naming';
test('#naming dns resolver', async t => {
const resolver = new DNSResolver();
const watcher = resolver.resolve('_grpc._tcp.test?intervalMs=100');
srvRecords = _.map([1111, 2222, 3333], port => {
return <SrvRecord>{
name: 'localhost',
port,
weight: 1,
priority: 10,
};
});
t.log(srvRecords);
const updates1 = await watcher.next();
const addrs1 = ['localhost:1111', 'localhost:2222', 'localhost:3333'];
_.each(updates1, (update, i) => {
t.is(update.op, UpdateOp.ADD);
t.is(update.addr, addrs1[i]);
});
srvRecords = _.map([2222, 3333], port => {
return <SrvRecord>{
name: 'localhost',
port,
weight: 1,
priority: 10,
};
});
t.log(srvRecords);
const updates2 = await watcher.next();
_.each(updates2, (update, i) => {
t.is(update.op, UpdateOp.DEL);
t.is(update.addr, 'localhost:1111');
});
srvRecords = _.map([2222, 3333, 4444], port => {
return <SrvRecord>{
name: 'localhost',
port,
weight: 1,
priority: 10,
};
});
t.log(srvRecords);
const updates3 = await watcher.next();
_.each(updates3, (update, i) => {
t.is(update.op, UpdateOp.ADD);
t.is(update.addr, 'localhost:4444');
});
watcher.close();
});