Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit 0fbca43

Browse files
committed
Fix misleading /30 test names and add third-peer-no-room case
1 parent 94fe837 commit 0fbca43

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

main_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,24 @@ func TestComputeIPCandidates(t *testing.T) {
497497
[]string{"10.0.0.2", "10.0.0.1"})
498498
})
499499

500-
t.Run("/30 minimal subnet, 2 peers — second peer has no room", func(t *testing.T) {
501-
// peer 0 gets .2, peer 1 needs broadcast-3 = .0 = network addr → no candidates
500+
t.Run("/30 minimal subnet, 2 peers each get 1 IP", func(t *testing.T) {
501+
// /30: network=.0, broadcast=.3, usable=.1 and .2
502+
// peer 0: startOffset=1 → .2; peer 1: startOffset=2 → .1
502503
ipNet := mustParseCIDR(t, "10.0.0.0/30")
503504
assertIPs(t, "peer 0",
504505
computeIPCandidates(ipNet, []string{"10.0.0.1", "10.0.0.2"}, "10.0.0.1", 1),
505506
[]string{"10.0.0.2"})
507+
assertIPs(t, "peer 1",
508+
computeIPCandidates(ipNet, []string{"10.0.0.1", "10.0.0.2"}, "10.0.0.2", 1),
509+
[]string{"10.0.0.1"})
510+
})
506511

507-
got := computeIPCandidates(ipNet, []string{"10.0.0.1", "10.0.0.2"}, "10.0.0.2", 1)
508-
if len(got) != 1 || got[0].String() != "10.0.0.1" {
509-
t.Errorf("peer 1 on /30: got %v, want [10.0.0.1]", ipsToStrings(got))
512+
t.Run("/30 minimal subnet, 3 peers — third has no room", func(t *testing.T) {
513+
// peer 2: startOffset=1+2*1=3, broadcast(.3)-3=.0=network addr → no candidates
514+
ipNet := mustParseCIDR(t, "10.0.0.0/30")
515+
got := computeIPCandidates(ipNet, []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"}, "10.0.0.3", 1)
516+
if len(got) != 0 {
517+
t.Errorf("peer 2 on /30: got %v, want empty", ipsToStrings(got))
510518
}
511519
})
512520

0 commit comments

Comments
 (0)