testutil

package
v0.0.0-...-4409437 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const LocalIP = "127.0.0.1"

Variables

View Source
var DefaultClient = &http.Client{
	Transport: &http.Transport{MaxIdleConnsPerHost: 1},
	Timeout:   10 * time.Second,
}

Functions

func AssertReceiveChan

func AssertReceiveChan[T any](t *testing.T, ch <-chan T, timeout time.Duration) T

func AssertReceiveChanContext

func AssertReceiveChanContext[T any](t *testing.T, ctx context.Context, ch <-chan T) T

func Context

func Context(t *testing.T, opts ...ContextOption) context.Context

func Delete

func Delete(t *testing.T, url string)

func Get

func Get[R any](t *testing.T, url string) R

func GetFreeHostPort

func GetFreeHostPort(t *testing.T) string

func GetFreePort

func GetFreePort(t *testing.T) int

GetFreePort returns a TCP port that is available to listen on, for the local host 127.0.0.1.

Copied from: https://github.com/temporalio/cli/blob/main/temporalcli/devserver/freeport.go

This works by binding a new TCP socket on port 0, which requests the OS to allocate a free port. There is no strict guarantee that the port will remain available after this function returns, but it should be safe to assume that a given port will not be allocated again to any process on this machine within a few seconds.

On Unix-based systems, binding to the port returned by this function requires setting the `SO_REUSEADDR` socket option (Go already does that by default, but other languages may not); otherwise, the OS may fail with a message such as "address already in use". Windows default behavior is already appropriate in this regard; on that platform, `SO_REUSEADDR` has a different meaning and should not be set (setting it may have unpredictable consequences).

func GetText

func GetText(t *testing.T, url string) string

func Post

func Post[R any](t *testing.T, url string, req any) R

func Put

func Put[R any](t *testing.T, url string, req any) R

func RandName

func RandName() string

func RandString

func RandString(length int) string

Types

type ContextOption

type ContextOption func(opts *contextOptions)

func WithTimeout

func WithTimeout(timeout time.Duration) ContextOption

Jump to

Keyboard shortcuts

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