testutil

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNormalizedJSON

func GenerateNormalizedJSON(t *testing.T, jsonStr string) string

GenerateNormalizedJSON generates a normalized JSON from the string given to the function. Useful to compare JSON contents that may have differences due to formatting. It returns nil in case of invalid JSON.

func GetAvailableLocalAddress

func GetAvailableLocalAddress(t *testing.T) string

GetAvailableLocalAddress finds an available local port and returns an endpoint describing it. The port is available for opening when this function returns provided that there is no race by some other code to grab the same port immediately.

func GetAvailablePort

func GetAvailablePort(t *testing.T) uint16

GetAvailablePort finds an available local port and returns it. The port is available for opening when this function returns provided that there is no race by some other code to grab the same port immediately.

func HostPortFromAddr

func HostPortFromAddr(addr net.Addr) (host string, port int, err error)

HostPortFromAddr extracts host and port from a network address

func TempSocketName

func TempSocketName(t *testing.T) string

TempSocketName provides a temporary Unix socket name for testing.

func WaitFor

func WaitFor(t *testing.T, cond func() bool, errMsg ...interface{}) bool

WaitFor the specific condition for up to 10 seconds. Records a test error if condition does not become true.

func WaitForPort

func WaitForPort(t *testing.T, port uint16) error

WaitForPort repeatedly attempts to open a local port until it either succeeds or 5 seconds pass It is useful if you need to asynchronously start a service and wait for it to start

Types

type LimitedWriter added in v0.7.0

type LimitedWriter struct {
	bytes.Buffer
	MaxLen int
}

LimitedWriter is an io.Writer that will return an EOF error after MaxLen has been reached. If MaxLen is 0, Writes will always succeed.

func (*LimitedWriter) Close added in v0.7.0

func (lw *LimitedWriter) Close() error

Close closes the writer.

func (*LimitedWriter) Write added in v0.7.0

func (lw *LimitedWriter) Write(p []byte) (n int, err error)

Write writes bytes to the underlying buffer until reaching the maximum length.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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