1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

refactor delete network integration tests to use network package

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
Arash Deshmeh 2018-06-09 06:39:22 -04:00
parent 5e11f66cb6
commit 991d512159

View file

@ -6,15 +6,16 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration/internal/network"
"github.com/docker/docker/internal/test/request"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
)
func containsNetwork(nws []types.NetworkResource, nw types.NetworkCreateResponse) bool {
func containsNetwork(nws []types.NetworkResource, networkID string) bool {
for _, n := range nws {
if n.ID == nw.ID {
if n.ID == networkID {
return true
}
}
@ -26,16 +27,13 @@ func containsNetwork(nws []types.NetworkResource, nw types.NetworkCreateResponse
// first network's ID as name.
//
// After successful creation, properties of all three networks is returned
func createAmbiguousNetworks(t *testing.T) (types.NetworkCreateResponse, types.NetworkCreateResponse, types.NetworkCreateResponse) {
func createAmbiguousNetworks(t *testing.T) (string, string, string) {
client := request.NewAPIClient(t)
ctx := context.Background()
testNet, err := client.NetworkCreate(ctx, "testNet", types.NetworkCreate{})
assert.NilError(t, err)
idPrefixNet, err := client.NetworkCreate(ctx, testNet.ID[:12], types.NetworkCreate{})
assert.NilError(t, err)
fullIDNet, err := client.NetworkCreate(ctx, testNet.ID, types.NetworkCreate{})
assert.NilError(t, err)
testNet := network.CreateNoError(t, ctx, client, "testNet")
idPrefixNet := network.CreateNoError(t, ctx, client, testNet[:12])
fullIDNet := network.CreateNoError(t, ctx, client, testNet)
nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
assert.NilError(t, err)
@ -58,12 +56,12 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
// Delete the network using a prefix of the first network's ID as name.
// This should the network name with the id-prefix, not the original network.
err := client.NetworkRemove(ctx, testNet.ID[:12])
err := client.NetworkRemove(ctx, testNet[:12])
assert.NilError(t, err)
// Delete the network using networkID. This should remove the original
// network, not the network with the name equal to the networkID
err = client.NetworkRemove(ctx, testNet.ID)
err = client.NetworkRemove(ctx, testNet)
assert.NilError(t, err)
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist