Files
ctrld/net_ipv6_test.go
T
Anthony Wong 8ae09ac98e feat(cli): put the network state of the host in the log journal
The journal records the network state of the host and each change of
that state. The support team reads one file to see the interfaces, the
routes, the resolvers, and the recoveries around an incident. The same
file shows the health of the query path. A change that touches only
AirDrop or virtual interfaces runs no DNS work.
2026-09-28 16:49:05 +07:00

38 lines
855 B
Go

package ctrld
import (
"sync"
"testing"
)
// resetIPv6Probe clears the one-time IPv6 probe. Test only: the process runs
// the probe once, so a test cannot see it without this reset.
func resetIPv6Probe(t *testing.T) {
t.Helper()
reset := func() {
hasIPv6Once = sync.Once{}
ipv6Available.Store(false)
}
reset()
t.Cleanup(reset)
}
func TestHasIPv6KeepsTheProbeThenTakesTheStoredFlag(t *testing.T) {
resetIPv6Probe(t)
probed := HasIPv6()
if got := HasIPv6(); got != probed {
t.Fatalf("HasIPv6 = %v on the second call, want the probe value %v", got, probed)
}
SetIPv6Available(!probed)
if got := HasIPv6(); got == probed {
t.Fatalf("HasIPv6 = %v after SetIPv6Available(%v), want the stored value", got, !probed)
}
SetIPv6Available(false)
if HasIPv6() {
t.Fatal("HasIPv6 = true after SetIPv6Available(false), want false")
}
}