MCPcopy Index your code
hub / github.com/coder/envbox / GetNetLink

Function GetNetLink

cli/clitest/net.go:10–28  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func GetNetLink(t *testing.T) netlink.Link {
11 t.Helper()
12
13 addrs, err := netlink.AddrList(nil, netlink.FAMILY_V4)
14 require.NoError(t, err)
15
16 for _, addr := range addrs {
17 if !addr.IP.IsGlobalUnicast() || addr.IP.To4() == nil || addr.Label == "docker0" {
18 continue
19 }
20
21 nl, err := netlink.LinkByName(addr.Label)
22 require.NoError(t, err)
23 return nl
24 }
25
26 t.Fatalf("failed to find a valid network interface")
27 return nil
28}

Callers 2

TestDockerFunction · 0.92
NewFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestDockerFunction · 0.74