This fix removes code duplication and consolidates networkIsRemoved
into one place.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+package network |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/docker/docker/api/types" |
|
| 6 |
+ "github.com/docker/docker/client" |
|
| 7 |
+ "gotest.tools/poll" |
|
| 8 |
+) |
|
| 9 |
+ |
|
| 10 |
+// IsRemoved verifies the network is removed. |
|
| 11 |
+func IsRemoved(ctx context.Context, client client.NetworkAPIClient, networkID string) func(log poll.LogT) poll.Result {
|
|
| 12 |
+ return func(log poll.LogT) poll.Result {
|
|
| 13 |
+ _, err := client.NetworkInspect(ctx, networkID, types.NetworkInspectOptions{})
|
|
| 14 |
+ if err == nil {
|
|
| 15 |
+ return poll.Continue("waiting for network %s to be removed", networkID)
|
|
| 16 |
+ } |
|
| 17 |
+ return poll.Success() |
|
| 18 |
+ } |
|
| 19 |
+} |
| ... | ... |
@@ -91,7 +91,7 @@ func TestInspectNetwork(t *testing.T) {
|
| 91 | 91 |
err = client.NetworkRemove(context.Background(), overlayID) |
| 92 | 92 |
assert.NilError(t, err) |
| 93 | 93 |
|
| 94 |
- poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 94 |
+ poll.WaitOn(t, network.IsRemoved(context.Background(), client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {
|
| ... | ... |
@@ -117,16 +117,6 @@ func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, |
| 117 | 117 |
} |
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 |
-func networkIsRemoved(client client.NetworkAPIClient, networkID string) func(log poll.LogT) poll.Result {
|
|
| 121 |
- return func(log poll.LogT) poll.Result {
|
|
| 122 |
- _, err := client.NetworkInspect(context.Background(), networkID, types.NetworkInspectOptions{})
|
|
| 123 |
- if err == nil {
|
|
| 124 |
- return poll.Continue("waiting for network %s to be removed", networkID)
|
|
| 125 |
- } |
|
| 126 |
- return poll.Success() |
|
| 127 |
- } |
|
| 128 |
-} |
|
| 129 |
- |
|
| 130 | 120 |
func serviceIsRemoved(client client.ServiceAPIClient, serviceID string) func(log poll.LogT) poll.Result {
|
| 131 | 121 |
return func(log poll.LogT) poll.Result {
|
| 132 | 122 |
filter := filters.NewArgs() |
| ... | ... |
@@ -122,7 +122,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
| 122 | 122 |
err = client.NetworkRemove(context.Background(), overlayID) |
| 123 | 123 |
assert.NilError(t, err) |
| 124 | 124 |
|
| 125 |
- poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 125 |
+ poll.WaitOn(t, network.IsRemoved(context.Background(), client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 | 128 |
func TestCreateServiceConflict(t *testing.T) {
|
| ... | ... |
@@ -228,9 +228,9 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
| 228 | 228 |
assert.NilError(t, err) |
| 229 | 229 |
|
| 230 | 230 |
// Make sure networks have been destroyed. |
| 231 |
- poll.WaitOn(t, networkIsRemoved(client, n3), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 232 |
- poll.WaitOn(t, networkIsRemoved(client, n2), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 233 |
- poll.WaitOn(t, networkIsRemoved(client, n1), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 231 |
+ poll.WaitOn(t, network.IsRemoved(context.Background(), client, n3), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 232 |
+ poll.WaitOn(t, network.IsRemoved(context.Background(), client, n2), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 233 |
+ poll.WaitOn(t, network.IsRemoved(context.Background(), client, n1), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) |
|
| 234 | 234 |
} |
| 235 | 235 |
|
| 236 | 236 |
func TestCreateServiceSecretFileMode(t *testing.T) {
|
| ... | ... |
@@ -513,13 +513,3 @@ func serviceIsRemoved(client client.ServiceAPIClient, serviceID string) func(log |
| 513 | 513 |
return poll.Success() |
| 514 | 514 |
} |
| 515 | 515 |
} |
| 516 |
- |
|
| 517 |
-func networkIsRemoved(client client.NetworkAPIClient, networkID string) func(log poll.LogT) poll.Result {
|
|
| 518 |
- return func(log poll.LogT) poll.Result {
|
|
| 519 |
- _, err := client.NetworkInspect(context.Background(), networkID, types.NetworkInspectOptions{})
|
|
| 520 |
- if err == nil {
|
|
| 521 |
- return poll.Continue("waiting for network %s to be removed", networkID)
|
|
| 522 |
- } |
|
| 523 |
- return poll.Success() |
|
| 524 |
- } |
|
| 525 |
-} |