github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/drivers/bridge/link_test.go (about)

     1  package bridge
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/libnetwork/types"
     7  )
     8  
     9  func getPorts() []types.TransportPort {
    10  	return []types.TransportPort{
    11  		{Proto: types.TCP, Port: uint16(5000)},
    12  		{Proto: types.UDP, Port: uint16(400)},
    13  		{Proto: types.TCP, Port: uint16(600)},
    14  	}
    15  }
    16  
    17  func TestLinkNew(t *testing.T) {
    18  	ports := getPorts()
    19  
    20  	link := newLink("172.0.17.3", "172.0.17.2", ports, "docker0")
    21  
    22  	if link == nil {
    23  		t.FailNow()
    24  	}
    25  	if link.parentIP != "172.0.17.3" {
    26  		t.Fail()
    27  	}
    28  	if link.childIP != "172.0.17.2" {
    29  		t.Fail()
    30  	}
    31  	for i, p := range link.ports {
    32  		if p != ports[i] {
    33  			t.Fail()
    34  		}
    35  	}
    36  	if link.bridge != "docker0" {
    37  		t.Fail()
    38  	}
    39  }