Files
x/internal/net/ip/ip_test.go
T
ginuerzh ef58909fb7 fix(dialer): correct inverted setMark on FreeBSD/OpenBSD
Fix setMark early-return conditions that were inverted relative to
Linux: on FreeBSD (SO_USER_COOKIE) and OpenBSD (SO_RTABLE), a
non-zero mark was short-circuited instead of applied, disabling
socket marking entirely.

Also fix GetClientIP to trim leading whitespace from X-Forwarded-For
entries (per RFC 7239), and fix Body.Read to subtract len(b) instead
of n from recordSize when a single read exceeds the remaining quota.

Add unit tests for internal/net/ (addr, dialer, http, ip, net, pipe,
transport, resolve, proxyproto, udp).
2026-05-21 20:58:48 +08:00

37 lines
877 B
Go

package ip
import (
"testing"
"github.com/songgao/water/waterutil"
)
func TestProtocol(t *testing.T) {
tests := []struct {
name string
p waterutil.IPProtocol
want string
}{
{"HOPOPT", waterutil.HOPOPT, "HOPOPT"},
{"ICMP", waterutil.ICMP, "ICMP"},
{"IGMP", waterutil.IGMP, "IGMP"},
{"GGP", waterutil.GGP, "GGP"},
{"TCP", waterutil.TCP, "TCP"},
{"UDP", waterutil.UDP, "UDP"},
{"IPv6-Route", waterutil.IPv6_Route, "IPv6-Route"},
{"IPv6-Frag", waterutil.IPv6_Frag, "IPv6-Frag"},
{"IPv6-ICMP", waterutil.IPv6_ICMP, "IPv6-ICMP"},
{"unknown protocol", waterutil.IPProtocol(255), "unknown(255)"},
{"unknown value", waterutil.IPProtocol(100), "unknown(100)"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Protocol(tt.p)
if got != tt.want {
t.Errorf("Protocol() = %q, want %q", got, tt.want)
}
})
}
}