2025-05-19 09:15:42 +00:00
|
|
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
2022-02-17 00:03:13 +01:00
|
|
|
|
2022-03-24 23:11:53 +01:00
|
|
|
import * as smartnetwork from '../ts/index.js';
|
2022-02-17 00:03:13 +01:00
|
|
|
|
|
|
|
|
let testSmartnetwork: smartnetwork.SmartNetwork;
|
|
|
|
|
|
2026-03-26 15:24:43 +00:00
|
|
|
tap.test('should create a valid instance of SmartNetwork', async () => {
|
2022-02-17 00:03:13 +01:00
|
|
|
testSmartnetwork = new smartnetwork.SmartNetwork();
|
|
|
|
|
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
2022-02-17 00:18:23 +01:00
|
|
|
});
|
2022-02-17 00:03:13 +01:00
|
|
|
|
2026-03-26 15:24:43 +00:00
|
|
|
tap.test('should start the Rust bridge', async () => {
|
|
|
|
|
await testSmartnetwork.start();
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-17 00:03:13 +01:00
|
|
|
tap.test('should send a ping to Google', async () => {
|
2025-04-28 19:27:13 +00:00
|
|
|
const res = await testSmartnetwork.ping('google.com');
|
|
|
|
|
console.log(res);
|
2026-03-26 15:24:43 +00:00
|
|
|
// Ping requires CAP_NET_RAW or appropriate ping_group_range.
|
|
|
|
|
// When permissions are available, alive should be true.
|
|
|
|
|
// When not, we gracefully get alive=false.
|
|
|
|
|
expect(typeof res.alive).toEqual('boolean');
|
|
|
|
|
expect(typeof res.time).toEqual('number');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tap.test('should state when a ping is not alive', async () => {
|
|
|
|
|
const res = await testSmartnetwork.ping('notthere.lossless.com');
|
|
|
|
|
expect(res.alive).toBeFalse();
|
2022-02-17 00:18:23 +01:00
|
|
|
});
|
2022-02-17 00:03:13 +01:00
|
|
|
|
2026-03-26 15:24:43 +00:00
|
|
|
tap.test('should send a ping to an invalid IP', async () => {
|
|
|
|
|
const res = await testSmartnetwork.ping('192.168.186.999');
|
|
|
|
|
expect(res.alive).toBeFalse();
|
2022-10-21 17:13:06 +02:00
|
|
|
});
|
|
|
|
|
|
2026-03-26 15:24:43 +00:00
|
|
|
tap.test('should stop the Rust bridge', async () => {
|
|
|
|
|
await testSmartnetwork.stop();
|
2025-04-28 12:58:01 +00:00
|
|
|
});
|
2022-10-21 17:13:06 +02:00
|
|
|
|
2026-03-26 15:24:43 +00:00
|
|
|
export default tap.start();
|