瀏覽代碼

refactored remaining macvlan integration tests to use network package for creating networks

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
Arash Deshmeh 7 年之前
父節點
當前提交
1c923b28b8
共有 2 個文件被更改,包括 18 次插入19 次删除
  1. 1 1
      integration/internal/network/ops.go
  2. 17 18
      integration/network/macvlan/macvlan_test.go

+ 1 - 1
integration/internal/network/ops.go

@@ -26,7 +26,7 @@ func WithCheckDuplicate() func(*types.NetworkCreate) {
 	}
 	}
 }
 }
 
 
-// WithInternal sets the Internal flag on the network
+// WithInternal enables Internal flag on the create network request
 func WithInternal() func(*types.NetworkCreate) {
 func WithInternal() func(*types.NetworkCreate) {
 	return func(n *types.NetworkCreate) {
 	return func(n *types.NetworkCreate) {
 		n.Internal = true
 		n.Internal = true

+ 17 - 18
integration/network/macvlan/macvlan_test.go

@@ -6,7 +6,6 @@ import (
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
-	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/client"
 	"github.com/docker/docker/client"
 	"github.com/docker/docker/integration/internal/container"
 	"github.com/docker/docker/integration/internal/container"
 	net "github.com/docker/docker/integration/internal/network"
 	net "github.com/docker/docker/integration/internal/network"
@@ -138,17 +137,17 @@ func testMacvlanSubinterface(client client.APIClient) func(*testing.T) {
 func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
 func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
 	return func(t *testing.T) {
 	return func(t *testing.T) {
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
-		_, err := client.NetworkCreate(context.Background(), "dm-nil-parent", types.NetworkCreate{
-			Driver: "macvlan",
-		})
-		assert.NilError(t, err)
-		assert.Check(t, n.IsNetworkAvailable(client, "dm-nil-parent"))
+		netName := "dm-nil-parent"
+		net.CreateNoError(t, context.Background(), client, netName,
+			net.WithMacvlan(""),
+		)
+		assert.Check(t, n.IsNetworkAvailable(client, netName))
 
 
 		ctx := context.Background()
 		ctx := context.Background()
-		id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
-		id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
+		id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
+		id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
 
 
-		_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
+		_, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
 		assert.Check(t, err == nil)
 		assert.Check(t, err == nil)
 	}
 	}
 }
 }
@@ -156,20 +155,20 @@ func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
 func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
 func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
 	return func(t *testing.T) {
 	return func(t *testing.T) {
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
-		_, err := client.NetworkCreate(context.Background(), "dm-internal", types.NetworkCreate{
-			Driver:   "macvlan",
-			Internal: true,
-		})
-		assert.NilError(t, err)
-		assert.Check(t, n.IsNetworkAvailable(client, "dm-internal"))
+		netName := "dm-internal"
+		net.CreateNoError(t, context.Background(), client, netName,
+			net.WithMacvlan(""),
+			net.WithInternal(),
+		)
+		assert.Check(t, n.IsNetworkAvailable(client, netName))
 
 
 		ctx := context.Background()
 		ctx := context.Background()
-		id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
-		id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
+		id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
+		id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
 
 
 		timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
 		timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
 		defer cancel()
 		defer cancel()
-		_, err = container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
+		_, err := container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
 		// FIXME(vdemeester) check the time of error ?
 		// FIXME(vdemeester) check the time of error ?
 		assert.Check(t, err != nil)
 		assert.Check(t, err != nil)
 		assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded)
 		assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded)