...

Source file src/gotest.tools/v3/poll/check.go

Documentation: gotest.tools/v3/poll

     1  package poll
     2  
     3  import (
     4  	"net"
     5  	"os"
     6  )
     7  
     8  // Check is a function which will be used as check for the [WaitOn] method.
     9  type Check func(t LogT) Result
    10  
    11  // FileExists looks on filesystem and check that path exists.
    12  func FileExists(path string) Check {
    13  	return func(t LogT) Result {
    14  		if h, ok := t.(helperT); ok {
    15  			h.Helper()
    16  		}
    17  
    18  		_, err := os.Stat(path)
    19  		switch {
    20  		case os.IsNotExist(err):
    21  			t.Logf("waiting on file %s to exist", path)
    22  			return Continue("file %s does not exist", path)
    23  		case err != nil:
    24  			return Error(err)
    25  		default:
    26  			return Success()
    27  		}
    28  	}
    29  }
    30  
    31  // Connection try to open a connection to the address on the
    32  // named network. See [net.Dial] for a description of the network and
    33  // address parameters.
    34  func Connection(network, address string) Check {
    35  	return func(t LogT) Result {
    36  		if h, ok := t.(helperT); ok {
    37  			h.Helper()
    38  		}
    39  
    40  		_, err := net.Dial(network, address)
    41  		if err != nil {
    42  			t.Logf("waiting on socket %s://%s to be available...", network, address)
    43  			return Continue("socket %s://%s not available", network, address)
    44  		}
    45  		return Success()
    46  	}
    47  }
    48  

View as plain text