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
1 changed files with 9 additions and 11 deletions

View File

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