41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
|
|
|
import * as smartnetwork from '../ts/index.js';
|
|
|
|
let testSmartnetwork: smartnetwork.SmartNetwork;
|
|
|
|
tap.test('should create a valid instance of SmartNetwork', async () => {
|
|
testSmartnetwork = new smartnetwork.SmartNetwork();
|
|
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
|
});
|
|
|
|
tap.test('should start the Rust bridge', async () => {
|
|
await testSmartnetwork.start();
|
|
});
|
|
|
|
tap.test('should send a ping to Google', async () => {
|
|
const res = await testSmartnetwork.ping('google.com');
|
|
console.log(res);
|
|
// 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();
|
|
});
|
|
|
|
tap.test('should send a ping to an invalid IP', async () => {
|
|
const res = await testSmartnetwork.ping('192.168.186.999');
|
|
expect(res.alive).toBeFalse();
|
|
});
|
|
|
|
tap.test('should stop the Rust bridge', async () => {
|
|
await testSmartnetwork.stop();
|
|
});
|
|
|
|
export default tap.start();
|