Skip to content

Commit

Permalink
Merge pull request #132 from osociety/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
git-elliot authored Sep 2, 2023
2 parents 0c3a3b8 + 07c3772 commit 71ca352
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 113 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pub" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
19 changes: 16 additions & 3 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
name: Dart

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main", "dev" ]

Expand Down Expand Up @@ -46,4 +44,19 @@ jobs:
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
run: dart test --coverage="coverage"

- name: Install coverage tools
if: contains(github.ref, 'dev') || contains(github.ref, 'main')
run: dart pub global activate coverage

- name: Format Coverage
if: contains(github.ref, 'dev') || contains(github.ref, 'main')
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage

- name: Upload Coverage to CodeCov
if: contains(github.ref, 'dev') || contains(github.ref, 'main')
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coverage/coverage.lcov
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage/coverage.lcov
file: coverage/coverage.lcov

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 3.2.4

1. Bug fixes and improvements. Better code coverage reports.

## 3.2.3

1. Upgraded dependencies and improved pub score, moved network_tools_flutter to new repo
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Network Tools

[![pub package](https://img.shields.io/pub/v/network_tools.svg)](https://pub.dev/packages/network_tools) [![Dart](https://github.com/osociety/network_tools/actions/workflows/dart.yml/badge.svg)](https://github.com/osociety/network_tools/actions/workflows/dart.yml) [![codecov](https://codecov.io/gh/git-elliot/network_tools/branch/main/graph/badge.svg?token=J9G2472GQZ)](https://codecov.io/gh/git-elliot/network_tools)
[![pub package](https://img.shields.io/pub/v/network_tools.svg)](https://pub.dev/packages/network_tools) [![Dart](https://github.com/osociety/network_tools/actions/workflows/dart.yml/badge.svg)](https://github.com/osociety/network_tools/actions/workflows/dart.yml) [![codecov](https://codecov.io/gh/osociety/network_tools/graph/badge.svg?token=J9G2472GQZ)](https://codecov.io/gh/osociety/network_tools)

Network Tools Supported

Expand Down
2 changes: 1 addition & 1 deletion example/mdns_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Future<void> main() async {
for (final ActiveHost activeHost in await MdnsScanner.searchMdnsDevices()) {
final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo;
print(
'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}, Mdns Device Name: ${mdnsInfo.mdnsSrvTarget}',
'Address: ${activeHost.address}, Port: ${mdnsInfo!.mdnsPort}, ServiceType: ${mdnsInfo.mdnsServiceType}, MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}, Mdns Device Name: ${mdnsInfo.mdnsSrvTarget}\n',
);
}
}
14 changes: 14 additions & 0 deletions format_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Run Dart tests and output them at directory `./coverage`:
dart run test --coverage=./coverage

## Activate package `coverage` (if needed):
dart pub global activate coverage

## Format collected coverage to LCOV (only for directory "lib")
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage

## Generate LCOV report:
genhtml -o ./coverage/report ./coverage/lcov.info

## Open the HTML coverage report:
open ./coverage/report/index.html
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: network_tools
description: Networking Tools library which can help you discover open ports, devices on subnet and many other things.
version: 3.2.3
version: 3.2.4
issue_tracker: https://github.com/osociety/network_tools/issues
repository: https://github.com/osociety/network_tools

Expand Down
110 changes: 109 additions & 1 deletion test/host_scanner_test.dart → test/network_tools_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:logging/logging.dart';
import 'package:network_tools/network_tools.dart';
import 'package:test/test.dart';
Expand All @@ -17,6 +19,8 @@ void main() {
int firstHostId = 0;
int lastHostId = 0;
String myOwnHost = "0.0.0.0";
final List<ActiveHost> hostsWithOpenPort = [];
OpenPort? openPort;

String interfaceIp = myOwnHost.substring(0, myOwnHost.lastIndexOf('.'));
late ServerSocket server;
Expand Down Expand Up @@ -45,13 +49,38 @@ void main() {
// Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
firstHostId = hostId <= 1 ? hostId : hostId - 1;
lastHostId = hostId >= 254 ? hostId : hostId + 1;
await for (final host
in HostScanner.scanDevicesForSinglePort(interfaceIp, port)) {
hostsWithOpenPort.add(host);
for (final tempOpenPort in host.openPorts) {
if (tempOpenPort.port == port) {
openPort = tempOpenPort;
break;
}
}
}
log.fine(
'Fetched own host as $myOwnHost and interface address as $interfaceIp',
);
}
}
});

group('Model Coverage', () {
test('Running OpenPort tests', () {
final actualOpenPort = openPort;
final expectedOpenPort = OpenPort(port);

if (actualOpenPort != null) {
expect(actualOpenPort, expectedOpenPort);
expect(actualOpenPort.compareTo(expectedOpenPort), 0);
}
expect(expectedOpenPort.isOpen, equals(true)); // because default is true
expect(expectedOpenPort.hashCode, expectedOpenPort.port.hashCode);
expect(expectedOpenPort.toString(), expectedOpenPort.port.toString());
});
});

group('Testing Host Scanner', () {
test(
'Running getAllPingableDevices tests',
Expand Down Expand Up @@ -105,7 +134,6 @@ void main() {
},
);

//todo: this test is not working on windows, not matter what.
test(
'Running scanDevicesForSinglePort tests',
() {
Expand All @@ -122,6 +150,86 @@ void main() {
);
});

group('Testing Port Scanner', () {
test('Running scanPortsForSingleDevice tests', () {
for (final activeHost in hostsWithOpenPort) {
final port = activeHost.openPorts.elementAt(0).port;
expectLater(
PortScanner.scanPortsForSingleDevice(
activeHost.address,
startPort: port - 1,
endPort: port,
),
emitsThrough(
isA<ActiveHost>().having(
(p0) => p0.openPorts.contains(OpenPort(port)),
"Should match host having same open port",
equals(true),
),
),
);
}
});

test('Running connectToPort tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScanner.connectToPort(
address: activeHost.address,
port: port,
timeout: const Duration(seconds: 5),
activeHostsController: StreamController<ActiveHost>(),
),
completion(
isA<ActiveHost>().having(
(p0) => p0.openPorts.contains(OpenPort(port)),
"Should match host having same open port",
equals(true),
),
),
);
}
});
test('Running customDiscover tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScanner.customDiscover(activeHost.address, portList: [port]),
emits(isA<ActiveHost>()),
);
}
});

test('Running customDiscover tests', () {
for (final activeHost in hostsWithOpenPort) {
expectLater(
PortScanner.isOpen(activeHost.address, port),
completion(
isA<ActiveHost>().having(
(p0) => p0.openPorts.contains(OpenPort(port)),
"Should match host having same open port",
equals(true),
),
),
);
}
});
});

group("Running mdns scanner group", () {
test('Running searchMdnsDevices tests', () async {
final mdnsDevices = await MdnsScanner.searchMdnsDevices();
expectLater(
mdnsDevices,
isA<List<ActiveHost>>(),
);
//todo: mdnsDevices are empty in GHA, open one to be discoverable
// expectLater(
// mdnsDevices,
// contains(predicate<ActiveHost>((host) => host.address == myOwnHost)),
// );
});
});

tearDownAll(() {
server.close();
});
Expand Down
105 changes: 0 additions & 105 deletions test/port_scanner_test.dart

This file was deleted.

0 comments on commit 71ca352

Please sign in to comment.