This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
forked from mafintosh/etcd-registry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
66 lines (63 loc) · 1.64 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
var test = require('tap').test;
var registry = require('./');
test('adding a service', function(test) {
test.plan(4);
var reg = registry('127.0.0.1:4001');
reg.join('test', {port:1000, hostname:'127.0.0.1'}, function(err) {
test.ok(!err, 'no error on join');
setTimeout(function() {
reg.lookup('test', function(err, s) {
test.ok(!err, 'no error on lookup');
test.ok(!!s, 'service exists');
test.deepEqual(s, {
name: 'test',
port:1000,
hostname: '127.0.0.1',
host: '127.0.0.1:1000',
url: 'http://127.0.0.1:1000'
}, 'valid service');
reg.leave(function() {
test.end();
});
});
}, 100);
});
});
test('listing services', function(test) {
test.plan(4);
var reg = registry('127.0.0.1:4001');
reg.join('test', {port:1000}, function(err) {
test.ok(!err, 'no error on join');
reg.join('test', {port:1001}, function(err) {
test.ok(!err, 'no error on join');
setTimeout(function() {
reg.list('test', function(err, list) {
test.ok(!err, 'no error on list');
test.equal(list.length, 2, '2 services exists');
reg.leave(function() {
test.end();
});
});
}, 100);
});
});
});
test('removing services', function(test) {
test.plan(4);
var reg = registry('127.0.0.1:4001');
reg.join('test', {port:1000}, function(err) {
test.ok(!err, 'no error on join');
reg.leave('test', function(err) {
test.ok(!err, 'no error on join');
setTimeout(function() {
reg.lookup('test', function(err, s) {
test.ok(!err, 'no error on lookup');
test.ok(!s, 'all services removed');
reg.leave(function() {
test.end();
});
});
}, 100);
});
});
});