MCPcopy
hub / github.com/tailscale/tailscale / newTestClient

Function newTestClient

net/portmapper/igd_test.go:267–289  ·  view source on GitHub ↗

newTestClient configures a new test client connected to igd for mapping updates. If bus == nil, a new empty event bus is constructed that is cleaned up when t exits. A cleanup for the resulting client is also added to t.

(t *testing.T, igd *TestIGD, bus *eventbus.Bus)

Source from the content-addressed store, hash-verified

265// If bus == nil, a new empty event bus is constructed that is cleaned up when t exits.
266// A cleanup for the resulting client is also added to t.
267func newTestClient(t *testing.T, igd *TestIGD, bus *eventbus.Bus) *Client {
268 if bus == nil {
269 bus = eventbus.New()
270 t.Log("Created empty event bus for test client")
271 t.Cleanup(bus.Close)
272 }
273 var c *Client
274 c = NewClient(Config{
275 Logf: tstest.WhileTestRunningLogger(t),
276 NetMon: netmon.NewStatic(),
277 EventBus: bus,
278 OnChange: func() { // TODO(creachadair): Remove.
279 t.Logf("port map changed")
280 t.Logf("have mapping: %v", c.HaveMapping())
281 },
282 })
283 c.testPxPPort = igd.TestPxPPort()
284 c.testUPnPPort = igd.TestUPnPPort()
285 c.netMon = netmon.NewStatic()
286 c.SetGatewayLookupFunc(testIPAndGateway)
287 t.Cleanup(func() { c.Close() })
288 return c
289}

Calls 12

HaveMappingMethod · 0.95
SetGatewayLookupFuncMethod · 0.95
CloseMethod · 0.95
NewFunction · 0.92
WhileTestRunningLoggerFunction · 0.92
NewStaticFunction · 0.92
TestPxPPortMethod · 0.80
TestUPnPPortMethod · 0.80
NewClientFunction · 0.70
LogMethod · 0.65
CleanupMethod · 0.65
LogfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…