github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/network/helpers_windows.go (about) 1 package network 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/client" 10 "gotest.tools/v3/assert/cmp" 11 ) 12 13 // IsNetworkAvailable provides a comparison to check if a docker network is available 14 func IsNetworkAvailable(c client.NetworkAPIClient, name string) cmp.Comparison { 15 return func() cmp.Result { 16 networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{}) 17 if err != nil { 18 return cmp.ResultFromError(err) 19 } 20 for _, network := range networks { 21 if network.Name == name { 22 return cmp.ResultSuccess 23 } 24 } 25 return cmp.ResultFailure(fmt.Sprintf("could not find network %s", name)) 26 } 27 } 28 29 // IsNetworkNotAvailable provides a comparison to check if a docker network is not available 30 func IsNetworkNotAvailable(c client.NetworkAPIClient, name string) cmp.Comparison { 31 return func() cmp.Result { 32 networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{}) 33 if err != nil { 34 return cmp.ResultFromError(err) 35 } 36 for _, network := range networks { 37 if network.Name == name { 38 return cmp.ResultFailure(fmt.Sprintf("network %s is still present", name)) 39 } 40 } 41 return cmp.ResultSuccess 42 } 43 } 44 45 // IsUserNamespace returns whether the user namespace remapping is enabled 46 func IsUserNamespace() bool { 47 root := os.Getenv("DOCKER_REMAP_ROOT") 48 return root != "" 49 }