Browse code

create service integration tests use network package

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

Arash Deshmeh authored on 2018/06/14 01:10:02
Showing 2 changed files
... ...
@@ -19,6 +19,13 @@ func WithIPv6() func(*types.NetworkCreate) {
19 19
 	}
20 20
 }
21 21
 
22
+// WithCheckDuplicate enables CheckDuplicate on the create network request
23
+func WithCheckDuplicate() func(*types.NetworkCreate) {
24
+	return func(n *types.NetworkCreate) {
25
+		n.CheckDuplicate = true
26
+	}
27
+}
28
+
22 29
 // WithMacvlan sets the network as macvlan with the specified parent
23 30
 func WithMacvlan(parent string) func(*types.NetworkCreate) {
24 31
 	return func(n *types.NetworkCreate) {
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/filters"
12 12
 	swarmtypes "github.com/docker/docker/api/types/swarm"
13 13
 	"github.com/docker/docker/client"
14
+	"github.com/docker/docker/integration/internal/network"
14 15
 	"github.com/docker/docker/integration/internal/swarm"
15 16
 	"github.com/docker/docker/internal/test/daemon"
16 17
 	"gotest.tools/assert"
... ...
@@ -78,14 +79,10 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
78 78
 	defer client.Close()
79 79
 
80 80
 	overlayName := "overlay1_" + t.Name()
81
-	networkCreate := types.NetworkCreate{
82
-		CheckDuplicate: true,
83
-		Driver:         "overlay",
84
-	}
85
-
86
-	netResp, err := client.NetworkCreate(context.Background(), overlayName, networkCreate)
87
-	assert.NilError(t, err)
88
-	overlayID := netResp.ID
81
+	overlayID := network.CreateNoError(t, context.Background(), client, overlayName,
82
+		network.WithCheckDuplicate(),
83
+		network.WithDriver("overlay"),
84
+	)
89 85
 
90 86
 	var instances uint64 = 4
91 87
 
... ...
@@ -99,7 +96,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
99 99
 	serviceID := swarm.CreateService(t, d, serviceSpec...)
100 100
 	poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), swarm.ServicePoll)
101 101
 
102
-	_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
102
+	_, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
103 103
 	assert.NilError(t, err)
104 104
 
105 105
 	err = client.ServiceRemove(context.Background(), serviceID)
... ...
@@ -131,21 +128,17 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
131 131
 	defer client.Close()
132 132
 
133 133
 	name := "foo_" + t.Name()
134
-	networkCreate := types.NetworkCreate{
135
-		CheckDuplicate: false,
136
-		Driver:         "bridge",
137
-	}
138
-
139
-	n1, err := client.NetworkCreate(context.Background(), name, networkCreate)
140
-	assert.NilError(t, err)
141
-
142
-	n2, err := client.NetworkCreate(context.Background(), name, networkCreate)
143
-	assert.NilError(t, err)
134
+	n1 := network.CreateNoError(t, context.Background(), client, name,
135
+		network.WithDriver("bridge"),
136
+	)
137
+	n2 := network.CreateNoError(t, context.Background(), client, name,
138
+		network.WithDriver("bridge"),
139
+	)
144 140
 
145 141
 	// Dupliates with name but with different driver
146
-	networkCreate.Driver = "overlay"
147
-	n3, err := client.NetworkCreate(context.Background(), name, networkCreate)
148
-	assert.NilError(t, err)
142
+	n3 := network.CreateNoError(t, context.Background(), client, name,
143
+		network.WithDriver("overlay"),
144
+	)
149 145
 
150 146
 	// Create Service with the same name
151 147
 	var instances uint64 = 1
... ...
@@ -161,7 +154,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
161 161
 
162 162
 	resp, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
163 163
 	assert.NilError(t, err)
164
-	assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target))
164
+	assert.Check(t, is.Equal(n3, resp.Spec.TaskTemplate.Networks[0].Target))
165 165
 
166 166
 	// Remove Service
167 167
 	err = client.ServiceRemove(context.Background(), serviceID)
... ...
@@ -171,19 +164,19 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
171 171
 	poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll)
172 172
 
173 173
 	// Remove networks
174
-	err = client.NetworkRemove(context.Background(), n3.ID)
174
+	err = client.NetworkRemove(context.Background(), n3)
175 175
 	assert.NilError(t, err)
176 176
 
177
-	err = client.NetworkRemove(context.Background(), n2.ID)
177
+	err = client.NetworkRemove(context.Background(), n2)
178 178
 	assert.NilError(t, err)
179 179
 
180
-	err = client.NetworkRemove(context.Background(), n1.ID)
180
+	err = client.NetworkRemove(context.Background(), n1)
181 181
 	assert.NilError(t, err)
182 182
 
183 183
 	// Make sure networks have been destroyed.
184
-	poll.WaitOn(t, networkIsRemoved(client, n3.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
185
-	poll.WaitOn(t, networkIsRemoved(client, n2.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
186
-	poll.WaitOn(t, networkIsRemoved(client, n1.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
184
+	poll.WaitOn(t, networkIsRemoved(client, n3), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
185
+	poll.WaitOn(t, networkIsRemoved(client, n2), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
186
+	poll.WaitOn(t, networkIsRemoved(client, n1), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second))
187 187
 }
188 188
 
189 189
 func TestCreateServiceSecretFileMode(t *testing.T) {