2018-02-05 16:05:59 -05:00
|
|
|
package service // import "github.com/docker/docker/integration/service"
|
2018-01-20 18:06:14 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/network"
|
2018-02-10 18:01:37 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-02-09 13:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/swarm"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-01-20 18:06:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDockerNetworkConnectAlias(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2018-02-02 17:36:59 -05:00
|
|
|
d := swarm.NewSwarm(t, testEnv)
|
2018-01-20 18:06:14 -05:00
|
|
|
defer d.Stop(t)
|
2018-04-13 11:02:56 -04:00
|
|
|
client := d.NewClientT(t)
|
|
|
|
defer client.Close()
|
2018-01-20 18:06:14 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
name := t.Name() + "test-alias"
|
2018-04-13 11:02:56 -04:00
|
|
|
_, err := client.NetworkCreate(ctx, name, types.NetworkCreate{
|
2018-01-20 18:06:14 -05:00
|
|
|
Driver: "overlay",
|
|
|
|
Attachable: true,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-10 18:01:37 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
cID1 := container.Create(t, ctx, client, func(c *container.TestContainerConfig) {
|
2018-02-10 18:01:37 -05:00
|
|
|
c.NetworkingConfig = &network.NetworkingConfig{
|
2018-05-17 10:29:52 -04:00
|
|
|
EndpointsConfig: map[string]*network.EndpointSettings{
|
2018-01-20 18:06:14 -05:00
|
|
|
name: {},
|
|
|
|
},
|
2018-02-10 18:01:37 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
err = client.NetworkConnect(ctx, name, cID1, &network.EndpointSettings{
|
2018-01-20 18:06:14 -05:00
|
|
|
Aliases: []string{
|
|
|
|
"aaa",
|
|
|
|
},
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-20 18:06:14 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
err = client.ContainerStart(ctx, cID1, types.ContainerStartOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-20 18:06:14 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
ng1, err := client.ContainerInspect(ctx, cID1)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(ng1.NetworkSettings.Networks[name].Aliases), 2))
|
|
|
|
assert.Check(t, is.Equal(ng1.NetworkSettings.Networks[name].Aliases[0], "aaa"))
|
2018-01-20 18:06:14 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
cID2 := container.Create(t, ctx, client, func(c *container.TestContainerConfig) {
|
2018-02-10 18:01:37 -05:00
|
|
|
c.NetworkingConfig = &network.NetworkingConfig{
|
2018-05-17 10:29:52 -04:00
|
|
|
EndpointsConfig: map[string]*network.EndpointSettings{
|
2018-01-20 18:06:14 -05:00
|
|
|
name: {},
|
|
|
|
},
|
2018-02-10 18:01:37 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
err = client.NetworkConnect(ctx, name, cID2, &network.EndpointSettings{
|
2018-01-20 18:06:14 -05:00
|
|
|
Aliases: []string{
|
|
|
|
"bbb",
|
|
|
|
},
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-20 18:06:14 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
err = client.ContainerStart(ctx, cID2, types.ContainerStartOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-20 18:06:14 -05:00
|
|
|
|
2018-05-11 16:04:34 -04:00
|
|
|
ng2, err := client.ContainerInspect(ctx, cID2)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(ng2.NetworkSettings.Networks[name].Aliases), 2))
|
|
|
|
assert.Check(t, is.Equal(ng2.NetworkSettings.Networks[name].Aliases[0], "bbb"))
|
2018-01-20 18:06:14 -05:00
|
|
|
}
|