github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration/service/network_test.go (about) 1 package service // import "github.com/docker/docker/integration/service" 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/docker/docker/api/types" 8 "github.com/docker/docker/api/types/network" 9 "github.com/docker/docker/integration/internal/container" 10 net "github.com/docker/docker/integration/internal/network" 11 "github.com/docker/docker/integration/internal/swarm" 12 "gotest.tools/assert" 13 is "gotest.tools/assert/cmp" 14 "gotest.tools/skip" 15 ) 16 17 func TestDockerNetworkConnectAlias(t *testing.T) { 18 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 19 defer setupTest(t)() 20 d := swarm.NewSwarm(t, testEnv) 21 defer d.Stop(t) 22 client := d.NewClientT(t) 23 defer client.Close() 24 ctx := context.Background() 25 26 name := t.Name() + "test-alias" 27 net.CreateNoError(t, ctx, client, name, 28 net.WithDriver("overlay"), 29 net.WithAttachable(), 30 ) 31 32 cID1 := container.Create(t, ctx, client, func(c *container.TestContainerConfig) { 33 c.NetworkingConfig = &network.NetworkingConfig{ 34 EndpointsConfig: map[string]*network.EndpointSettings{ 35 name: {}, 36 }, 37 } 38 }) 39 40 err := client.NetworkConnect(ctx, name, cID1, &network.EndpointSettings{ 41 Aliases: []string{ 42 "aaa", 43 }, 44 }) 45 assert.NilError(t, err) 46 47 err = client.ContainerStart(ctx, cID1, types.ContainerStartOptions{}) 48 assert.NilError(t, err) 49 50 ng1, err := client.ContainerInspect(ctx, cID1) 51 assert.NilError(t, err) 52 assert.Check(t, is.Equal(len(ng1.NetworkSettings.Networks[name].Aliases), 2)) 53 assert.Check(t, is.Equal(ng1.NetworkSettings.Networks[name].Aliases[0], "aaa")) 54 55 cID2 := container.Create(t, ctx, client, func(c *container.TestContainerConfig) { 56 c.NetworkingConfig = &network.NetworkingConfig{ 57 EndpointsConfig: map[string]*network.EndpointSettings{ 58 name: {}, 59 }, 60 } 61 }) 62 63 err = client.NetworkConnect(ctx, name, cID2, &network.EndpointSettings{ 64 Aliases: []string{ 65 "bbb", 66 }, 67 }) 68 assert.NilError(t, err) 69 70 err = client.ContainerStart(ctx, cID2, types.ContainerStartOptions{}) 71 assert.NilError(t, err) 72 73 ng2, err := client.ContainerInspect(ctx, cID2) 74 assert.NilError(t, err) 75 assert.Check(t, is.Equal(len(ng2.NetworkSettings.Networks[name].Aliases), 2)) 76 assert.Check(t, is.Equal(ng2.NetworkSettings.Networks[name].Aliases[0], "bbb")) 77 }