wait

package
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHealthy

func CheckHealthy(ctx context.Context, f Fetcher) (bool, error)

CheckHealthy is a CheckFunc. See Healthy.

Types

type CheckFunc

type CheckFunc func(ctx context.Context, f Fetcher) (bool, error)

func CheckCommandSucceeds added in v1.3.2

func CheckCommandSucceeds(cmd []string) CheckFunc

CheckCommandSucceeds creates CheckFunc. See CommandSucceeds.

func CheckLogOccurrence

func CheckLogOccurrence(message string, occurrence int) CheckFunc

CheckLogOccurrence creates CheckFunc. See LogContains.

type Fetcher

type Fetcher interface {
	ContainerID() string
	Status(ctx context.Context) (*types.ContainerState, error)
	Ports() nat.PortMap
	Log(ctx context.Context) (io.ReadCloser, error)
	Exec(ctx context.Context, cmd ...string) ([]byte, error)
}

Fetcher provides several ways to access the state of the container.

type Option

type Option interface {
	option.Interface
	// contains filtered or unexported methods
}

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the interval between container readiness checks.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the timeout for waiting for the container to be ready.

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

func CommandSucceeds added in v1.3.2

func CommandSucceeds(cmd []string, opts ...Option) *Waiter

CommandSucceeds waits for the success of given command.

func Healthy

func Healthy(opts ...Option) *Waiter

Healthy waits for the container's health status to be healthy.

func LogContains

func LogContains(message string, occurrence int, opts ...Option) *Waiter

LogContains waits for the given number of occurrences of the given message in the container log.

func New

func New(check CheckFunc, opts ...Option) *Waiter

New creates a Waiter that waits for the container to be ready. CheckFunc is the criteria for evaluating readiness. Use Fetcher to obtain the container status.

Waiter repeatedly checks the readiness until first success. We can set interval and timeout by WithInterval and WithTimeout. The default value for the interval is 500ms and for the timeout is 30sec.

func (*Waiter) Wait

func (w *Waiter) Wait(ctx context.Context, f Fetcher) error

Wait calls CheckFunc with given Fetcher repeatedly until the first success.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL