Repository navigation
Add unit tests for modules/ping and fix Windows ping failures - #2141
Merged
Seanstoppable merged 3 commits intoJul 26, 2026
Merged
Conversation
Cover buildhosts YAML parsing (labels, defaults, invalid entries), NewSettingsFromYAML, ConfigText, and Widget.content status/color formatting via table-driven tests. doPings is left untested since it performs real ICMP network calls.
Introduce a pinger interface (Run/Statistics) and a pingerFactory field on Widget, defaulting to newRealPinger which wraps probing.NewPinger. This lets tests substitute a fake pinger instead of sending real ICMP packets, enabling coverage of doPings and Refresh. Also extract hostUpFromStatistics as a small pure function, and change the ping-error path from log.Fatalf to log.Printf so a single failed ping no longer kills the whole app. Coverage: 62.7% -> 100%.
pro-bing defaults to unprivileged (UDP) ICMP mode, which Windows does not support at all: Run() immediately fails with 'socket: the requested protocol has not been configured into the system', leaving every host marked as down. Use privileged (raw ICMP) mode on Windows, where sending raw ICMP echo requests works without elevation in testing. Other platforms are left on the unprivileged default so they don't require root/CAP_NET_RAW. Verified against 8.8.8.8, 1.1.1.1, and github.com - all now report Up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
modules/ping, taking coverage from 0% to 100%.Widgetto inject a mockablepingerinterface (pingerFactoryfield, defaulting tonewRealPinger), sodoPings/Refreshcan be tested without sending real ICMP packets.pro-bing's default unprivileged (UDP) ICMP mode isn't supported at all (socket: the requested protocol has not been configured into the system), so every host was silently reported as DOWN. Now uses privileged (raw ICMP) mode on Windows; other platforms keep the unprivileged default so they don't need root/CAP_NET_RAW.log.Fatalftolog.Printf, so a single failed ping no longer terminates the whole app.Testing
go test ./modules/ping/... -cover→ 100.0% coverage, all tests pass.golangci-lint run ./modules/ping/...→ 0 issues.go build ./...succeeds.