github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/libnetwork/drivers/bridge/link_test.go (about) 1 //go:build linux 2 3 package bridge 4 5 import ( 6 "net" 7 "testing" 8 9 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/types" 10 ) 11 12 func getPorts() []types.TransportPort { 13 return []types.TransportPort{ 14 {Proto: types.TCP, Port: uint16(5000)}, 15 {Proto: types.UDP, Port: uint16(400)}, 16 {Proto: types.TCP, Port: uint16(600)}, 17 } 18 } 19 20 func TestLinkNew(t *testing.T) { 21 ports := getPorts() 22 23 const ( 24 pIP = "172.0.17.3" 25 cIP = "172.0.17.2" 26 bridgeName = "docker0" 27 ) 28 29 parentIP := net.ParseIP(pIP) 30 childIP := net.ParseIP(cIP) 31 32 l, err := newLink(parentIP, childIP, ports, bridgeName) 33 if err != nil { 34 t.Errorf("unexpected error from newlink(): %v", err) 35 } 36 if l == nil { 37 t.FailNow() 38 } 39 if l.parentIP.String() != pIP { 40 t.Fail() 41 } 42 if l.childIP.String() != cIP { 43 t.Fail() 44 } 45 for i, p := range l.ports { 46 if p != ports[i] { 47 t.Fail() 48 } 49 } 50 if l.bridge != bridgeName { 51 t.Fail() 52 } 53 }