moby/integration/network/helpers_windows.go
Brian Goff e8dc902781 Wire up tests to support otel tracing
Integration tests will now configure clients to propagate traces as well
as create spans for all tests.

Some extra changes were needed (or desired for trace propagation) in the
test helpers to pass through tracing spans via context.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-09-07 18:38:22 +00:00

42 lines
1.2 KiB
Go

package network
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"gotest.tools/v3/assert/cmp"
)
// 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, types.NetworkListOptions{})
if err != nil {
return cmp.ResultFromError(err)
}
for _, network := range networks {
if network.Name == name {
return cmp.ResultSuccess
}
}
return cmp.ResultFailure(fmt.Sprintf("could not find network %s", name))
}
}
// 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, types.NetworkListOptions{})
if err != nil {
return cmp.ResultFromError(err)
}
for _, network := range networks {
if network.Name == name {
return cmp.ResultFailure(fmt.Sprintf("network %s is still present", name))
}
}
return cmp.ResultSuccess
}
}