github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/drivers/windows/windows_test.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package windows
     5  
     6  import (
     7  	"net"
     8  	"testing"
     9  
    10  	"github.com/docker/docker/libnetwork/driverapi"
    11  	"github.com/docker/docker/libnetwork/netlabel"
    12  	"github.com/docker/docker/libnetwork/types"
    13  )
    14  
    15  func testNetwork(networkType string, t *testing.T) {
    16  	d := newDriver(networkType)
    17  	bnw, _ := types.ParseCIDR("172.16.0.0/24")
    18  	br, _ := types.ParseCIDR("172.16.0.1/16")
    19  
    20  	netOption := make(map[string]interface{})
    21  	networkOptions := map[string]string{
    22  		NetworkName: "TestNetwork",
    23  	}
    24  
    25  	netOption[netlabel.GenericData] = networkOptions
    26  	ipdList := []driverapi.IPAMData{
    27  		{
    28  			Pool:    bnw,
    29  			Gateway: br,
    30  		},
    31  	}
    32  
    33  	err := d.CreateNetwork("dummy", netOption, nil, ipdList, nil)
    34  	if err != nil {
    35  		t.Fatalf("Failed to create bridge: %v", err)
    36  	}
    37  	defer func() {
    38  		err = d.DeleteNetwork("dummy")
    39  		if err != nil {
    40  			t.Fatalf("Failed to create bridge: %v", err)
    41  		}
    42  	}()
    43  
    44  	epOptions := make(map[string]interface{})
    45  	te := &testEndpoint{}
    46  	err = d.CreateEndpoint("dummy", "ep1", te.Interface(), epOptions)
    47  	if err != nil {
    48  		t.Fatalf("Failed to create an endpoint : %s", err.Error())
    49  	}
    50  
    51  	err = d.DeleteEndpoint("dummy", "ep1")
    52  	if err != nil {
    53  		t.Fatalf("Failed to delete an endpoint : %s", err.Error())
    54  	}
    55  }
    56  
    57  func TestNAT(t *testing.T) {
    58  	t.Skip("Test does not work on CI and was never running to begin with")
    59  	testNetwork("nat", t)
    60  }
    61  
    62  func TestTransparent(t *testing.T) {
    63  	t.Skip("Test does not work on CI and was never running to begin with")
    64  	testNetwork("transparent", t)
    65  }
    66  
    67  type testEndpoint struct {
    68  	t                     *testing.T
    69  	src                   string
    70  	dst                   string
    71  	address               string
    72  	macAddress            string
    73  	gateway               string
    74  	disableGatewayService bool
    75  }
    76  
    77  func (test *testEndpoint) Interface() driverapi.InterfaceInfo {
    78  	return test
    79  }
    80  
    81  func (test *testEndpoint) Address() *net.IPNet {
    82  	if test.address == "" {
    83  		return nil
    84  	}
    85  	nw, _ := types.ParseCIDR(test.address)
    86  	return nw
    87  }
    88  
    89  func (test *testEndpoint) AddressIPv6() *net.IPNet {
    90  	return nil
    91  }
    92  
    93  func (test *testEndpoint) MacAddress() net.HardwareAddr {
    94  	if test.macAddress == "" {
    95  		return nil
    96  	}
    97  	mac, _ := net.ParseMAC(test.macAddress)
    98  	return mac
    99  }
   100  
   101  func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
   102  	if test.macAddress != "" {
   103  		return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", test.macAddress, mac)
   104  	}
   105  
   106  	if mac == nil {
   107  		return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
   108  	}
   109  	test.macAddress = mac.String()
   110  	return nil
   111  }
   112  
   113  func (test *testEndpoint) SetIPAddress(address *net.IPNet) error {
   114  	if address.IP == nil {
   115  		return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
   116  	}
   117  
   118  	test.address = address.String()
   119  	return nil
   120  }
   121  
   122  func (test *testEndpoint) InterfaceName() driverapi.InterfaceNameInfo {
   123  	return test
   124  }
   125  
   126  func (test *testEndpoint) SetGateway(ipv4 net.IP) error {
   127  	return nil
   128  }
   129  
   130  func (test *testEndpoint) SetGatewayIPv6(ipv6 net.IP) error {
   131  	return nil
   132  }
   133  
   134  func (test *testEndpoint) SetNames(src string, dst string) error {
   135  	return nil
   136  }
   137  
   138  func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
   139  	return nil
   140  }
   141  
   142  func (test *testEndpoint) DisableGatewayService() {
   143  	test.disableGatewayService = true
   144  }