Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed coverage issue #61

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions test/host_scan_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:universal_io/io.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late HostScannerServiceFlutterImpl service;
int port = 0;
int firstHostId = 0;
int lastHostId = 0;
Expand All @@ -18,6 +19,7 @@ void main() {
setUpAll(() async {
HttpOverrides.global = FakeResponseHttpOverrides();
await configureNetworkToolsFlutter('build');
service = HostScannerService.instance as HostScannerServiceFlutterImpl;

//open a port in shared way because of portscanner using same,
//if passed false then two hosts come up in search and breaks test.
Expand Down Expand Up @@ -47,7 +49,7 @@ void main() {
test('Running getAllPingableDevices emits tests', () {
expectLater(
//There should be at least one device pingable in network
HostScannerService.instance.getAllPingableDevices(
service.getAllPingableDevices(
interfaceIp,
firstHostId: firstHostId,
lastHostId: lastHostId,
Expand All @@ -58,7 +60,7 @@ void main() {
test('Running getAllPingableDevices emitsThrough tests', () {
expectLater(
//Should emit at least our own local machine when pinging all hosts.
HostScannerService.instance.getAllPingableDevices(
service.getAllPingableDevices(
interfaceIp,
firstHostId: firstHostId,
lastHostId: lastHostId,
Expand All @@ -70,7 +72,7 @@ void main() {
test('Running getAllPingableDevices emits tests', () {
expectLater(
//There should be at least one device pingable in network
HostScannerService.instance.getAllPingableDevices(
service.getAllPingableDevices(
interfaceIp,
firstHostId: firstHostId,
lastHostId: lastHostId,
Expand All @@ -82,7 +84,7 @@ void main() {
test('Running getAllPingableDevices limiting hostId tests', () {
expectLater(
//There should be at least one device pingable in network when limiting to own hostId
HostScannerService.instance.getAllPingableDevices(
service.getAllPingableDevices(
interfaceIp,
timeoutInSeconds: 3,
hostIds: [hostId],
Expand All @@ -93,7 +95,7 @@ void main() {
);
expectLater(
//There should be at least one device pingable in network when limiting to hostId other than own
HostScannerService.instance.getAllPingableDevices(
service.getAllPingableDevices(
interfaceIp,
timeoutInSeconds: 3,
hostIds: [0],
Expand Down
14 changes: 8 additions & 6 deletions test/port_scan_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:universal_io/io.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late PortScannerServiceFlutterImpl service;
int port = 0; // keep this value between 1-2034
final List<ActiveHost> hostsWithOpenPort = [];
late ServerSocket server;
Expand All @@ -16,6 +17,7 @@ void main() {
setUpAll(() async {
HttpOverrides.global = FakeResponseHttpOverrides();
await configureNetworkToolsFlutter('build');
service = PortScannerService.instance as PortScannerServiceFlutterImpl;

//open a port in shared way because of HostScannerService.instance using same,
//if passed false then two hosts come up in search and breaks test.
Expand All @@ -40,7 +42,7 @@ void main() {
for (final activeHost in hostsWithOpenPort) {
final port = activeHost.openPorts.elementAt(0).port;
expectLater(
PortScannerService.instance.scanPortsForSingleDevice(
service.scanPortsForSingleDevice(
activeHost.address,
startPort: port - 1,
endPort: port + 1,
Expand All @@ -60,7 +62,7 @@ void main() {
for (final activeHost in hostsWithOpenPort) {
final port = activeHost.openPorts.elementAt(0).port;
expectLater(
PortScannerService.instance.scanPortsForSingleDevice(
service.scanPortsForSingleDevice(
activeHost.address,
startPort: port - 1,
endPort: port + 1,
Expand All @@ -80,7 +82,7 @@ void main() {
test('Running connectToPort tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScannerService.instance.connectToPort(
service.connectToPort(
address: activeHost.address,
port: port,
timeout: const Duration(seconds: 5),
Expand All @@ -99,7 +101,7 @@ void main() {
test('Running customDiscover tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScannerService.instance.customDiscover(activeHost.address,
service.customDiscover(activeHost.address,
portList: [port - 1, port, port + 1]),
emits(isA<ActiveHost>()),
);
Expand All @@ -109,7 +111,7 @@ void main() {
test('Running customDiscover Async tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScannerService.instance.customDiscover(
service.customDiscover(
activeHost.address,
portList: [port - 1, port, port + 1],
async: true,
Expand All @@ -122,7 +124,7 @@ void main() {
test('Running isOpen tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScannerService.instance.isOpen(activeHost.address, port),
service.isOpen(activeHost.address, port),
completion(
isA<ActiveHost>().having(
(p0) => p0.openPorts.contains(OpenPort(port)),
Expand Down
Loading