mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: NetworkList: wrap result
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -31,12 +31,12 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, apiClient client
|
||||
idPrefixNet := network.CreateNoError(ctx, t, apiClient, testNet[:12])
|
||||
fullIDNet := network.CreateNoError(ctx, t, apiClient, testNet)
|
||||
|
||||
nws, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, idPrefixNet)), "failed to create network idPrefixNet")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "failed to create network fullIDNet")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(res.Items, testNet)), "failed to create network testNet")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(res.Items, idPrefixNet)), "failed to create network idPrefixNet")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(res.Items, fullIDNet)), "failed to create network fullIDNet")
|
||||
return testNet, idPrefixNet, fullIDNet
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
|
||||
nws, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "Network fullIDNet not found")
|
||||
assert.Check(t, is.Equal(false, containsNetwork(res.Items, testNet)), "Network testNet not removed")
|
||||
assert.Check(t, is.Equal(false, containsNetwork(res.Items, idPrefixNet)), "Network idPrefixNet not removed")
|
||||
assert.Check(t, is.Equal(true, containsNetwork(res.Items, fullIDNet)), "Network fullIDNet not found")
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ func LinkDoesntExist(ctx context.Context, t *testing.T, master string) {
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
for _, network := range networks {
|
||||
if network.Name == name {
|
||||
for _, nw := range res.Items {
|
||||
if nw.Name == name {
|
||||
return is.ResultSuccess
|
||||
}
|
||||
}
|
||||
@@ -69,12 +69,12 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
for _, network := range networks {
|
||||
if network.Name == name {
|
||||
for _, nw := range res.Items {
|
||||
if nw.Name == name {
|
||||
return is.ResultFailure(fmt.Sprintf("network %s is still present", name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
for _, network := range networks {
|
||||
if network.Name == name {
|
||||
for _, nw := range res.Items {
|
||||
if nw.Name == name {
|
||||
return cmp.ResultSuccess
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,12 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
res, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
for _, network := range networks {
|
||||
if network.Name == name {
|
||||
for _, nw := range res.Items {
|
||||
if nw.Name == name {
|
||||
return cmp.ResultFailure(fmt.Sprintf("network %s is still present", name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,15 +130,15 @@ func TestAPINetworkFilter(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
|
||||
res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
|
||||
Filters: make(client.Filters).Add("name", networkName),
|
||||
})
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
found := false
|
||||
for _, network := range networks {
|
||||
if network.Name == networkName {
|
||||
for _, nw := range res.Items {
|
||||
if nw.Name == networkName {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user