Skip to content

Commit

Permalink
refactor delete network integration tests to use network package
Browse files Browse the repository at this point in the history
Signed-off-by: Arash Deshmeh <[email protected]>
  • Loading branch information
adshmh committed Jun 9, 2018
1 parent 5e11f66 commit 991d512
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions integration/network/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 991d512

Please sign in to comment.