Browse code

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

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>

Arash Deshmeh authored on 2018/06/15 05:16:03
Showing 2 changed files
... ...
@@ -26,7 +26,7 @@ func WithCheckDuplicate() func(*types.NetworkCreate) {
26 26
 	}
27 27
 }
28 28
 
29
-// WithInternal sets the Internal flag on the network
29
+// WithInternal enables Internal flag on the create network request
30 30
 func WithInternal() func(*types.NetworkCreate) {
31 31
 	return func(n *types.NetworkCreate) {
32 32
 		n.Internal = true
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"testing"
7 7
 	"time"
8 8
 
9
-	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/client"
11 10
 	"github.com/docker/docker/integration/internal/container"
12 11
 	net "github.com/docker/docker/integration/internal/network"
... ...
@@ -138,17 +137,17 @@ func testMacvlanSubinterface(client client.APIClient) func(*testing.T) {
138 138
 func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
139 139
 	return func(t *testing.T) {
140 140
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
141
-		_, err := client.NetworkCreate(context.Background(), "dm-nil-parent", types.NetworkCreate{
142
-			Driver: "macvlan",
143
-		})
144
-		assert.NilError(t, err)
145
-		assert.Check(t, n.IsNetworkAvailable(client, "dm-nil-parent"))
141
+		netName := "dm-nil-parent"
142
+		net.CreateNoError(t, context.Background(), client, netName,
143
+			net.WithMacvlan(""),
144
+		)
145
+		assert.Check(t, n.IsNetworkAvailable(client, netName))
146 146
 
147 147
 		ctx := context.Background()
148
-		id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
149
-		id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-nil-parent"))
148
+		id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
149
+		id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
150 150
 
151
-		_, err = container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
151
+		_, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1})
152 152
 		assert.Check(t, err == nil)
153 153
 	}
154 154
 }
... ...
@@ -156,20 +155,20 @@ func testMacvlanNilParent(client client.APIClient) func(*testing.T) {
156 156
 func testMacvlanInternalMode(client client.APIClient) func(*testing.T) {
157 157
 	return func(t *testing.T) {
158 158
 		// macvlan bridge mode - dummy parent interface is provisioned dynamically
159
-		_, err := client.NetworkCreate(context.Background(), "dm-internal", types.NetworkCreate{
160
-			Driver:   "macvlan",
161
-			Internal: true,
162
-		})
163
-		assert.NilError(t, err)
164
-		assert.Check(t, n.IsNetworkAvailable(client, "dm-internal"))
159
+		netName := "dm-internal"
160
+		net.CreateNoError(t, context.Background(), client, netName,
161
+			net.WithMacvlan(""),
162
+			net.WithInternal(),
163
+		)
164
+		assert.Check(t, n.IsNetworkAvailable(client, netName))
165 165
 
166 166
 		ctx := context.Background()
167
-		id1 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
168
-		id2 := container.Run(t, ctx, client, container.WithNetworkMode("dm-internal"))
167
+		id1 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
168
+		id2 := container.Run(t, ctx, client, container.WithNetworkMode(netName))
169 169
 
170 170
 		timeoutCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
171 171
 		defer cancel()
172
-		_, err = container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
172
+		_, err := container.Exec(timeoutCtx, client, id1, []string{"ping", "-c", "1", "-w", "1", "8.8.8.8"})
173 173
 		// FIXME(vdemeester) check the time of error ?
174 174
 		assert.Check(t, err != nil)
175 175
 		assert.Check(t, timeoutCtx.Err() == context.DeadlineExceeded)