|
| 1 | +import { |
| 2 | + getTCP4Endpoints, |
| 3 | +} from 'src/utils/auto-discovery-helper'; |
| 4 | + |
| 5 | +const winNetstat = '' |
| 6 | + + 'Proto Local Address Foreign Address State PID\n' |
| 7 | + + 'TCP 0.0.0.0:5000 0.0.0.0:0 LISTENING 13728\n' |
| 8 | + + 'TCP 0.0.0.0:6379 0.0.0.0:0 LISTENING 13728\n' |
| 9 | + + 'TCP 127.0.0.1:6379 0.0.0.0:0 LISTENING 13728\n' |
| 10 | + + 'TCP *:6380 0.0.0.0:0 LISTENING 13728\n' |
| 11 | + + 'TCP [::]:135 [::]:0 LISTENING 1100\n' |
| 12 | + + 'TCP [::]:445 [::]:0 LISTENING 4\n' |
| 13 | + + 'TCP [::]:808 [::]:0 LISTENING 6084\n' |
| 14 | + + 'TCP [::]:2701 [::]:0 LISTENING 6056\n' |
| 15 | + + 'TCP *:* LISTENING 6056'; |
| 16 | + |
| 17 | +const linuxNetstat = '' |
| 18 | + + 'Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name \n' |
| 19 | + + 'tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN - \n' |
| 20 | + + 'tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN - \n' |
| 21 | + + 'tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN - \n' |
| 22 | + + 'tcp 0 0 *:6380 0.0.0.0:* LISTEN - \n' |
| 23 | + + 'tcp6 0 0 :::28100 :::* LISTEN - \n' |
| 24 | + + 'tcp6 0 0 :::8100 :::* LISTEN - \n' |
| 25 | + + 'tcp6 0 0 :::8101 :::* LISTEN - \n' |
| 26 | + + 'tcp6 0 0 :::8102 :::* LISTEN - \n' |
| 27 | + + 'tcp6 0 0 :::8103 :::* LISTEN - \n' |
| 28 | + + 'tcp6 0 0 :::8200 :::* LISTEN - \n' |
| 29 | + + 'tcp6 0 0 ::1:6379 :::* LISTEN - \n'; |
| 30 | + |
| 31 | +/* eslint-disable max-len */ |
| 32 | +const macNetstat = '' |
| 33 | + + 'Proto Recv-Q Send-Q Local Address Foreign Address (state) rhiwat shiwat pid epid state options\n' |
| 34 | + + 'tcp4 0 0 10.55.1.235.5000 10.55.1.235.52217 FIN_WAIT_2 407280 146988 30555 0 0x2131 0x00000104\n' |
| 35 | + + 'tcp4 0 0 10.55.1.235.6379 10.55.1.235.5001 CLOSE_WAIT 407682 146988 872 0 0x0122 0x00000008\n' |
| 36 | + + 'tcp4 0 0 127.0.0.1.6379 127.0.0.1.52216 FIN_WAIT_2 403346 146988 24687 0 0x2131 0x00000104\n' |
| 37 | + + 'tcp46 0 0 *.6380 *.* LISTEN 131072 131072 31195 0 0x0100 0x00000106\n' |
| 38 | + + 'tcp6 0 0 ::1.5002 ::1.52167 ESTABLISHED 405692 146808 31195 0 0x0102 0x00000104\n' |
| 39 | + + 'tcp6 0 0 ::1.52167 ::1.5002 ESTABLISHED 406172 146808 31200 0 0x0102 0x00000008\n'; |
| 40 | +/* eslint-enable max-len */ |
| 41 | + |
| 42 | +const getTCP4EndpointsTests = [ |
| 43 | + { |
| 44 | + name: 'win output', |
| 45 | + input: winNetstat.split('\n'), |
| 46 | + output: [ |
| 47 | + { host: 'localhost', port: 5000 }, |
| 48 | + { host: 'localhost', port: 6379 }, |
| 49 | + { host: 'localhost', port: 6380 }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + { |
| 53 | + name: 'linux output', |
| 54 | + input: linuxNetstat.split('\n'), |
| 55 | + output: [ |
| 56 | + { host: 'localhost', port: 5000 }, |
| 57 | + { host: 'localhost', port: 6379 }, |
| 58 | + { host: 'localhost', port: 6380 }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + { |
| 62 | + name: 'mac output', |
| 63 | + input: macNetstat.split('\n'), |
| 64 | + output: [ |
| 65 | + { host: 'localhost', port: 5000 }, |
| 66 | + { host: 'localhost', port: 6379 }, |
| 67 | + { host: 'localhost', port: 6380 }, |
| 68 | + ], |
| 69 | + }, |
| 70 | +]; |
| 71 | + |
| 72 | +describe('getTCP4Endpoints', () => { |
| 73 | + getTCP4EndpointsTests.forEach((test) => { |
| 74 | + it(`Should return endpoints to test ${test.name}`, async () => { |
| 75 | + const result = getTCP4Endpoints(test.input); |
| 76 | + |
| 77 | + expect(result).toEqual(test.output); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments