link_test.go 891 B

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