func TestEndpointInvalidLeave(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } err = ep.Leave(containerID) if err == nil { t.Fatal("Expected to fail leave from an endpoint which has no active join") } if _, ok := err.(libnetwork.InvalidContainerIDError); !ok { if err != libnetwork.ErrNoContainer { t.Fatalf("Failed for unexpected reason: %v", err) } } _, err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) if err != nil { t.Fatal(err) } }() err = ep.Leave("") if err == nil { t.Fatal("Expected to fail leave with empty container id") } if _, ok := err.(libnetwork.InvalidContainerIDError); !ok { t.Fatalf("Failed for unexpected reason: %v", err) } err = ep.Leave("container2") if err == nil { t.Fatal("Expected to fail leave with wrong container id") } if _, ok := err.(libnetwork.InvalidContainerIDError); !ok { t.Fatalf("Failed for unexpected reason: %v", err) } }
func createGlobalInstance(t *testing.T) { var err error defer close(start) origns, err = netns.Get() if err != nil { t.Fatal(err) } if netutils.IsRunningInContainer() { testns = origns } else { testns, err = netns.New() if err != nil { t.Fatal(err) } } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "network", "AllowNonDefaultBridge": true, }, } net, err := createTestNetwork(bridgeNetType, "network", netOption) if err != nil { t.Fatal("new network") } _, err = net.CreateEndpoint("ep1") if err != nil { t.Fatal("createendpoint") } }
func TestNetworkType(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, } n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() if n.Type() != bridgeNetType { t.Fatalf("Expected network type %s, got %s", bridgeNetType, n.Type()) } }
func TestDuplicateNetwork(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } controller, err := libnetwork.New() if err != nil { t.Fatal(err) } genericOption := make(map[string]interface{}) genericOption[netlabel.GenericData] = options.Generic{} err = controller.ConfigureNetworkDriver(bridgeNetType, genericOption) if err != nil { t.Fatal(err) } _, err = controller.NewNetwork(bridgeNetType, "testnetwork", libnetwork.NetworkOptionGeneric(genericOption)) if err != nil { t.Fatal(err) } _, err = controller.NewNetwork(bridgeNetType, "testnetwork") if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(libnetwork.NetworkNameError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestUnknownNetwork(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } netOption := options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true} option := options.Generic{ netlabel.GenericData: netOption, } network, err := createTestNetwork(bridgeNetType, "testnetwork", option) if err != nil { t.Fatal(err) } err = network.Delete() if err != nil { t.Fatal(err) } err = network.Delete() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(*libnetwork.UnknownNetworkError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestNetworkID(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, } n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() if n.ID() == "" { t.Fatal("Expected non-empty network id") } }
func createGlobalInstance(t *testing.T) { var err error defer close(start) origns, err = netns.Get() if err != nil { t.Fatal(err) } if netutils.IsRunningInContainer() { testns = origns } else { testns, err = netns.New() if err != nil { t.Fatal(err) } } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "network", "AllowNonDefaultBridge": true, }, } net1, err := controller.NetworkByName("testhost") if err != nil { t.Fatal(err) } net2, err := createTestNetwork("bridge", "network2", netOption) if err != nil { t.Fatal(err) } _, err = net1.CreateEndpoint("pep1") if err != nil { t.Fatal(err) } _, err = net2.CreateEndpoint("pep2") if err != nil { t.Fatal(err) } _, err = net2.CreateEndpoint("pep3") if err != nil { t.Fatal(err) } if sboxes[first-1], err = controller.NewSandbox(fmt.Sprintf("%drace", first), libnetwork.OptionUseDefaultSandbox()); err != nil { t.Fatal(err) } for thd := first + 1; thd <= last; thd++ { if sboxes[thd-1], err = controller.NewSandbox(fmt.Sprintf("%drace", thd)); err != nil { t.Fatal(err) } } }
func TestEndpointJoin(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } // Validate if ep.Info() only gives me IP address info and not names and gateway during CreateEndpoint() info := ep.Info() for _, iface := range info.InterfaceList() { if iface.Address().IP.To4() == nil { t.Fatalf("Invalid IP address returned: %v", iface.Address()) } } if info.Gateway().To4() != nil { t.Fatalf("Expected empty gateway for an empty endpoint. Instead found a gateway: %v", info.Gateway()) } if info.SandboxKey() != "" { t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.SandboxKey()) } _, err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) if err != nil { t.Fatal(err) } }() // Validate if ep.Info() only gives valid gateway and sandbox key after has container has joined. info = ep.Info() if info.Gateway().To4() == nil { t.Fatalf("Expected a valid gateway for a joined endpoint. Instead found an invalid gateway: %v", info.Gateway()) } if info.SandboxKey() == "" { t.Fatalf("Expected an non-empty sandbox key for a joined endpoint. Instead found a empty sandbox key") } checkSandbox(t, info) }
func TestEndpointDeleteWithActiveContainer(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, }) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } defer func() { err = ep.Delete() if err != nil { t.Fatal(err) } }() defer controller.LeaveAll(containerID) err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) runtime.LockOSThread() if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) runtime.LockOSThread() if err != nil { t.Fatal(err) } }() err = ep.Delete() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(*libnetwork.ActiveContainerError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestSandboxAddSamePrio(t *testing.T) { if !netutils.IsRunningInContainer() { defer osl.SetupTestOSContext(t)() } c, nw1, nw2 := getTestEnv(t) ctrlr := c.(*controller) sbx, err := ctrlr.NewSandbox("sandbox1") if err != nil { t.Fatal(err) } sid := sbx.ID() ep1, err := nw1.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } ep2, err := nw2.CreateEndpoint("ep2") if err != nil { t.Fatal(err) } if err := ep1.Join(sbx); err != nil { t.Fatal(err) } if err := ep2.Join(sbx); err != nil { t.Fatal(err) } if ctrlr.sandboxes[sid].endpoints[0] != ep1 { t.Fatal("Expected ep1 to be at the top of the heap. But did not find ep1 at the top of the heap") } if err := ep1.Leave(sbx); err != nil { t.Fatal(err) } if ctrlr.sandboxes[sid].endpoints[0] != ep2 { t.Fatal("Expected ep2 to be at the top of the heap after removing ep3. But did not find ep2 at the top of the heap") } if err := ep2.Leave(sbx); err != nil { t.Fatal(err) } if err := sbx.Delete(); err != nil { t.Fatal(err) } if len(ctrlr.sandboxes) != 0 { t.Fatalf("controller containers is not empty. len = %d", len(ctrlr.sandboxes)) } osl.GC() }
func TestEndpointMultipleJoins(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, }) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } defer func() { if err := ep.Delete(); err != nil { t.Fatal(err) } }() defer controller.LeaveAll(containerID) err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) runtime.LockOSThread() if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) runtime.LockOSThread() if err != nil { t.Fatal(err) } }() err = ep.Join("container2") if err == nil { t.Fatal("Expected to fail multiple joins for the same endpoint") } if _, ok := err.(libnetwork.ErrInvalidJoin); !ok { t.Fatalf("Failed for unexpected reason: %v", err) } }
func TestUnknownEndpoint(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } ip, subnet, err := net.ParseCIDR("192.168.100.1/24") if err != nil { t.Fatal(err) } subnet.IP = ip option := options.Generic{ "BridgeName": bridgeName, "AddressIPv4": subnet, "AllowNonDefaultBridge": true} network, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, option) if err != nil { t.Fatal(err) } _, err = network.CreateEndpoint("") if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if err != libnetwork.ErrInvalidName { t.Fatal("Expected to fail with ErrInvalidName error") } ep, err := network.CreateEndpoint("testep") if err != nil { t.Fatal(err) } err = ep.Delete() if err != nil { t.Fatal(err) } err = ep.Delete() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(*libnetwork.UnknownEndpointError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } // Done testing. Now cleanup if err := network.Delete(); err != nil { t.Fatal(err) } }
func TestValidRemoteDriver(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("Skipping test when not running inside a Container") } mux := http.NewServeMux() server := httptest.NewServer(mux) if server == nil { t.Fatal("Failed to start a HTTP Server") } defer server.Close() type pluginRequest struct { name string } mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") fmt.Fprintf(w, `{"Implements": ["%s"]}`, driverapi.NetworkPluginEndpointType) }) mux.HandleFunc(fmt.Sprintf("/%s.CreateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") fmt.Fprintf(w, "null") }) if err := os.MkdirAll("/usr/share/docker/plugins", 0755); err != nil { t.Fatal(err) } defer func() { if err := os.RemoveAll("/usr/share/docker/plugins"); err != nil { t.Fatal(err) } }() if err := ioutil.WriteFile("/usr/share/docker/plugins/valid-network-driver.spec", []byte(server.URL), 0644); err != nil { t.Fatal(err) } n, err := controller.NewNetwork("valid-network-driver", "dummy", libnetwork.NetworkOptionGeneric(getEmptyGenericOption())) if err != nil { // Only fail if we could not find the plugin driver if _, ok := err.(types.NotFoundError); ok { t.Fatal(err) } return } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() }
func TestEndpointUpdateParent(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork("bridge", "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } ep1, err := n.CreateEndpoint("ep1", nil) if err != nil { t.Fatal(err) } _, err = ep1.Join(containerID, libnetwork.JoinOptionHostname("test1"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) if err != nil { t.Fatal(err) } defer func() { err = ep1.Leave(containerID) if err != nil { t.Fatal(err) } }() ep2, err := n.CreateEndpoint("ep2", nil) if err != nil { t.Fatal(err) } _, err = ep2.Join("container2", libnetwork.JoinOptionHostname("test2"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionHostsPath("/var/lib/docker/test_network/container2/hosts"), libnetwork.JoinOptionParentUpdate(ep1.ID(), "web", "192.168.0.2")) if err != nil { t.Fatal(err) } defer func() { err = ep2.Leave("container2") if err != nil { t.Fatal(err) } }() }
func TestUnknownDriver(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } _, err := createTestNetwork("unknowndriver", "testnetwork", options.Generic{}) if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(types.NotFoundError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestNetworkID(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } if n.ID() == "" { t.Fatal("Expected non-empty network id") } }
func TestNetworkType(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } if n.Type() != bridgeNetType { t.Fatalf("Expected network type %s, got %s", bridgeNetType, n.Type()) } }
func createGlobalInstance(t *testing.T) { var err error defer close(start) origns, err = netns.Get() if err != nil { t.Fatal(err) } if netutils.IsRunningInContainer() { testns = origns } else { testns, err = netns.New() if err != nil { t.Fatal(err) } } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "network", "AllowNonDefaultBridge": true, }, } net1, err := controller.NetworkByName("testhost") if err != nil { t.Fatal(err) } net2, err := createTestNetwork("bridge", "network2", netOption) if err != nil { t.Fatal(err) } _, err = net1.CreateEndpoint("pep1") if err != nil { t.Fatal(err) } _, err = net2.CreateEndpoint("pep2") if err != nil { t.Fatal(err) } _, err = net2.CreateEndpoint("pep3") if err != nil { t.Fatal(err) } }
func TestDuplicateEndpoint(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } netOption := options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, } n, err := createTestNetwork(bridgeNetType, "testnetwork", netOption) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } defer func() { if err := ep.Delete(); err != nil { t.Fatal(err) } }() ep2, err := n.CreateEndpoint("ep1") defer func() { // Cleanup ep2 as well, else network cleanup might fail for failure cases if ep2 != nil { if err := ep2.Delete(); err != nil { t.Fatal(err) } } }() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(types.ForbiddenError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestInvalidRemoteDriver(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("Skipping test when not running inside a Container") } mux := http.NewServeMux() server := httptest.NewServer(mux) if server == nil { t.Fatal("Failed to start a HTTP Server") } defer server.Close() type pluginRequest struct { name string } mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") fmt.Fprintln(w, `{"Implements": ["InvalidDriver"]}`) }) if err := os.MkdirAll("/usr/share/docker/plugins", 0755); err != nil { t.Fatal(err) } defer func() { if err := os.RemoveAll("/usr/share/docker/plugins"); err != nil { t.Fatal(err) } }() if err := ioutil.WriteFile("/usr/share/docker/plugins/invalid-network-driver.spec", []byte(server.URL), 0644); err != nil { t.Fatal(err) } controller, err := libnetwork.New() if err != nil { t.Fatal(err) } _, err = controller.NewNetwork("invalid-network-driver", "dummy", libnetwork.NetworkOptionGeneric(getEmptyGenericOption())) if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if err != plugins.ErrNotImplements { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestDnetDaemonInvalidParams(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("This test must run inside a container ") } args := []string{dnetCommandName, "-d=false", "-H=tcp:/127.0.0.1:8080"} executeDnetCommand(t, args, false) args = []string{dnetCommandName, "-d=false", "-H=unix://var/run/dnet.sock"} executeDnetCommand(t, args, false) args = []string{dnetCommandName, "-d=false", "-H=", "-l=invalid"} executeDnetCommand(t, args, false) args = []string{dnetCommandName, "-d=false", "-H=", "-l=error", "invalid"} executeDnetCommand(t, args, false) }
func TestDnetMain(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("This test must run inside a container ") } customPort := 4568 doneChan := make(chan bool) go func() { args := []string{dnetCommandName, "-d=true", "-h=false", fmt.Sprintf("-H=:%d", customPort)} os.Args = args main() doneChan <- true }() select { case <-doneChan: t.Fatal("dnet Daemon is not supposed to exit") case <-time.After(2 * time.Second): } }
func TestEndpointDeleteWithActiveContainer(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } _, err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) if err != nil { t.Fatal(err) } err = ep.Delete() if err != nil { t.Fatal(err) } }() err = ep.Delete() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(*libnetwork.ActiveContainerError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestDuplicateNetwork(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } // Creating a default bridge name network (can't be removed) _, err := controller.NewNetwork(bridgeNetType, "testdup") if err != nil { t.Fatal(err) } _, err = controller.NewNetwork(bridgeNetType, "testdup") if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(libnetwork.NetworkNameError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } }
func TestDnetDaemonInvalidCustom(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("This test must run inside a container ") } customPort := 4668 doneChan := make(chan bool) go func() { args := []string{dnetCommandName, "-d=true", fmt.Sprintf("-H=:%d", customPort)} executeDnetCommand(t, args, true) doneChan <- true }() select { case <-doneChan: t.Fatal("dnet Daemon is not supposed to exit") case <-time.After(3 * time.Second): args := []string{dnetCommandName, "-d=false", "-H=:6669", "-D", "network", "ls"} executeDnetCommand(t, args, false) } }
func TestDeleteNetworkWithActiveEndpoints(t *testing.T) { if !netutils.IsRunningInContainer() { defer osl.SetupTestOSContext(t)() } netOption := options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true} option := options.Generic{ netlabel.GenericData: netOption, } network, err := createTestNetwork(bridgeNetType, "testnetwork", option) if err != nil { t.Fatal(err) } ep, err := network.CreateEndpoint("testep") if err != nil { t.Fatal(err) } err = network.Delete() if err == nil { t.Fatal("Expected to fail. But instead succeeded") } if _, ok := err.(*libnetwork.ActiveEndpointsError); !ok { t.Fatalf("Did not fail with expected error. Actual error: %v", err) } // Done testing. Now cleanup. if err := ep.Delete(); err != nil { t.Fatal(err) } if err := network.Delete(); err != nil { t.Fatal(err) } }
func TestEndpointJoinInvalidContainerId(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{ netlabel.GenericData: options.Generic{ "BridgeName": "testnetwork", "AllowNonDefaultBridge": true, }, }) if err != nil { t.Fatal(err) } defer func() { if err := n.Delete(); err != nil { t.Fatal(err) } }() ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } defer func() { if err := ep.Delete(); err != nil { t.Fatal(err) } }() err = ep.Join("") if err == nil { t.Fatal("Expected to fail join with empty container id string") } if _, ok := err.(libnetwork.InvalidContainerIDError); !ok { t.Fatalf("Failed for unexpected reason: %v", err) } }
func TestEndpointMultipleJoins(t *testing.T) { if !netutils.IsRunningInContainer() { defer netutils.SetupTestNetNS(t)() } n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{}) if err != nil { t.Fatal(err) } ep, err := n.CreateEndpoint("ep1") if err != nil { t.Fatal(err) } _, err = ep.Join(containerID, libnetwork.JoinOptionHostname("test"), libnetwork.JoinOptionDomainname("docker.io"), libnetwork.JoinOptionExtraHost("web", "192.168.0.1")) if err != nil { t.Fatal(err) } defer func() { err = ep.Leave(containerID) if err != nil { t.Fatal(err) } }() _, err = ep.Join("container2") if err == nil { t.Fatal("Expected to fail multiple joins for the same endpoint") } if err != libnetwork.ErrInvalidJoin { t.Fatalf("Failed for unexpected reason: %v", err) } }
func TestDnetDefaultsWithFlags(t *testing.T) { if !netutils.IsRunningInContainer() { t.Skip("This test must run inside a container ") } doneChan := make(chan bool) go func() { args := []string{dnetCommandName, "-d=true", "-H=", "-l=error"} executeDnetCommand(t, args, true) doneChan <- true }() select { case <-doneChan: t.Fatal("dnet Daemon is not supposed to exit") case <-time.After(3 * time.Second): args := []string{dnetCommandName, "-d=false", "network", "create", "-d=null", "test"} executeDnetCommand(t, args, true) args = []string{dnetCommandName, "-d=false", "-D", "network", "ls"} executeDnetCommand(t, args, true) } }
func createGlobalInstance(t *testing.T) { var err error defer close(start) origns, err = netns.Get() if err != nil { t.Fatal(err) } if netutils.IsRunningInContainer() { testns = origns } else { testns, err = netns.New() if err != nil { t.Fatal(err) } } ctrlr, err = libnetwork.New() if err != nil { t.Fatal(err) } err = ctrlr.ConfigureNetworkDriver(bridgeNetType, getEmptyGenericOption()) if err != nil { t.Fatal("configure driver") } net, err := ctrlr.NewNetwork(bridgeNetType, "network1") if err != nil { t.Fatal("new network") } _, err = net.CreateEndpoint("ep1") if err != nil { t.Fatal("createendpoint") } }