github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/network/helpers_windows.go (about)

     1  package network
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/client"
     9  	"gotest.tools/v3/assert/cmp"
    10  )
    11  
    12  // IsNetworkAvailable provides a comparison to check if a docker network is available
    13  func IsNetworkAvailable(c client.NetworkAPIClient, name string) cmp.Comparison {
    14  	return func() cmp.Result {
    15  		networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{})
    16  		if err != nil {
    17  			return cmp.ResultFromError(err)
    18  		}
    19  		for _, network := range networks {
    20  			if network.Name == name {
    21  				return cmp.ResultSuccess
    22  			}
    23  		}
    24  		return cmp.ResultFailure(fmt.Sprintf("could not find network %s", name))
    25  	}
    26  }
    27  
    28  // IsNetworkNotAvailable provides a comparison to check if a docker network is not available
    29  func IsNetworkNotAvailable(c client.NetworkAPIClient, name string) cmp.Comparison {
    30  	return func() cmp.Result {
    31  		networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{})
    32  		if err != nil {
    33  			return cmp.ResultFromError(err)
    34  		}
    35  		for _, network := range networks {
    36  			if network.Name == name {
    37  				return cmp.ResultFailure(fmt.Sprintf("network %s is still present", name))
    38  			}
    39  		}
    40  		return cmp.ResultSuccess
    41  	}
    42  }