2019-04-12 19:47:37 -04:00
|
|
|
package poll
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2023-07-29 15:01:34 -04:00
|
|
|
// Check is a function which will be used as check for the [WaitOn] method.
|
2019-04-12 19:47:37 -04:00
|
|
|
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 {
|
2022-03-01 10:51:15 -05:00
|
|
|
if h, ok := t.(helperT); ok {
|
|
|
|
h.Helper()
|
|
|
|
}
|
|
|
|
|
2019-04-12 19:47:37 -04:00
|
|
|
_, err := os.Stat(path)
|
2022-03-01 10:51:15 -05:00
|
|
|
switch {
|
|
|
|
case os.IsNotExist(err):
|
2019-04-12 19:47:37 -04:00
|
|
|
t.Logf("waiting on file %s to exist", path)
|
|
|
|
return Continue("file %s does not exist", path)
|
2022-03-01 10:51:15 -05:00
|
|
|
case err != nil:
|
2019-04-12 19:47:37 -04:00
|
|
|
return Error(err)
|
2022-03-01 10:51:15 -05:00
|
|
|
default:
|
|
|
|
return Success()
|
2019-04-12 19:47:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connection try to open a connection to the address on the
|
2023-07-29 15:01:34 -04:00
|
|
|
// named network. See [net.Dial] for a description of the network and
|
2019-04-12 19:47:37 -04:00
|
|
|
// address parameters.
|
|
|
|
func Connection(network, address string) Check {
|
|
|
|
return func(t LogT) Result {
|
2022-03-01 10:51:15 -05:00
|
|
|
if h, ok := t.(helperT); ok {
|
|
|
|
h.Helper()
|
|
|
|
}
|
|
|
|
|
2019-04-12 19:47:37 -04:00
|
|
|
_, 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()
|
|
|
|
}
|
|
|
|
}
|