MCPcopy
hub / github.com/seaweedfs/seaweedfs / TestSetOutboundLocalIP

Function TestSetOutboundLocalIP

weed/util/outbound_dial_test.go:14–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12}
13
14func TestSetOutboundLocalIP(t *testing.T) {
15 t.Cleanup(resetOutbound)
16
17 cases := []struct {
18 name string
19 ip string
20 wantIP string // empty means no binding
21 }{
22 {"ipv4", "10.0.0.5", "10.0.0.5"},
23 {"ipv6", "fe80::1", "fe80::1"},
24 {"empty", "", ""},
25 {"wildcard v4", "0.0.0.0", ""},
26 {"wildcard v6", "::", ""},
27 {"garbage", "not-an-ip", ""},
28 }
29 for _, tc := range cases {
30 t.Run(tc.name, func(t *testing.T) {
31 resetOutbound()
32 SetOutboundLocalIP(tc.ip)
33 got := OutboundLocalAddr()
34 if tc.wantIP == "" {
35 if got != nil {
36 t.Fatalf("expected no bound address, got %v", got)
37 }
38 return
39 }
40 if got == nil {
41 t.Fatalf("expected bound address %s, got nil", tc.wantIP)
42 }
43 if got.IP.String() != tc.wantIP {
44 t.Fatalf("bound address = %s, want %s", got.IP.String(), tc.wantIP)
45 }
46 if got.Port != 0 {
47 t.Fatalf("bound port = %d, want 0 (ephemeral)", got.Port)
48 }
49 })
50 }
51}
52
53// TestSetOutboundLocalIPFirstWins guards the behavior that keeps `weed server`
54// from letting a component's own bind setting clobber the process-wide address.

Callers

nothing calls this directly

Calls 6

resetOutboundFunction · 0.85
SetOutboundLocalIPFunction · 0.85
OutboundLocalAddrFunction · 0.85
StringMethod · 0.65
CleanupMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected