forked from nest-cloud/nestcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consul-service.class.spec.ts
52 lines (47 loc) · 1.63 KB
/
consul-service.class.spec.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
import { ConsulService } from './consul-service.class';
import * as Consul from 'consul';
import { expect } from 'chai';
describe('Consul Service Store', () => {
let consul: Consul;
let service: ConsulService;
before(async () => {
consul = new Consul({ host: '127.0.0.1', port: 8500, promisify: true });
await consul.agent.service.register({
id: 'my-consul-service',
name: 'my-consul-service',
address: '127.0.0.1',
port: 8500,
check: {
http: 'http://127.0.0.1:8500',
interval: '5s',
},
status: 'passing',
});
service = new ConsulService(consul, {
discoveryHost: '127.0.0.1',
healthCheck: {
http: 'http://127.0.0.1:8500',
interval: '5s',
},
service: {
id: 'my-test-service',
name: 'my-test-service',
port: 8500,
},
});
await service.init();
});
it(`service.onModuleInit()`, async () => {
await service.onModuleInit();
await new Promise(resolve => setTimeout(() => resolve(), 500));
expect(service.getServiceNodes('my-test-service').length).equal(1);
});
it(`service.onModuleDestroy()`, async () => {
await service.onModuleDestroy();
await new Promise(resolve => setTimeout(() => resolve(), 500));
expect(service.getServiceNodes('my-test-service').length).equal(0);
});
after(async () => {
await consul.agent.service.deregister({ id: 'my-consul-service' });
});
});