mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
89d39e5e77
full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.0.3...v3.1.0 noteworthy changes: - ci: add go1.16 - ci: add go1.17, remove go1.13 - golden: only create dir if update flag is set - icmd: replace all usages of os/exec with golang.org/x/sys/execabs - assert: ErrorIs - fs: add DirFromPath - Stop creating directory outside of testdata - fs: Fix comparing symlink permissions Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package poll
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
// Check is a function which will be used as check for the WaitOn method.
|
|
type Check func(t LogT) Result
|
|
|
|
// FileExists looks on filesystem and check that path exists.
|
|
func FileExists(path string) Check {
|
|
return func(t LogT) Result {
|
|
if h, ok := t.(helperT); ok {
|
|
h.Helper()
|
|
}
|
|
|
|
_, err := os.Stat(path)
|
|
switch {
|
|
case os.IsNotExist(err):
|
|
t.Logf("waiting on file %s to exist", path)
|
|
return Continue("file %s does not exist", path)
|
|
case err != nil:
|
|
return Error(err)
|
|
default:
|
|
return Success()
|
|
}
|
|
}
|
|
}
|
|
|
|
// Connection try to open a connection to the address on the
|
|
// named network. See net.Dial for a description of the network and
|
|
// address parameters.
|
|
func Connection(network, address string) Check {
|
|
return func(t LogT) Result {
|
|
if h, ok := t.(helperT); ok {
|
|
h.Helper()
|
|
}
|
|
|
|
_, err := net.Dial(network, address)
|
|
if err != nil {
|
|
t.Logf("waiting on socket %s://%s to be available...", network, address)
|
|
return Continue("socket %s://%s not available", network, address)
|
|
}
|
|
return Success()
|
|
}
|
|
}
|