testhooks

package
v1.36.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MatchingDisableSyncMatch                 = newKey[bool, namespace.ID]()
	MatchingLBForceReadPartition             = newKey[int, namespace.ID]()
	MatchingLBForceWritePartition            = newKey[int, namespace.ID]()
	UpdateWithStartInBetweenLockAndStart     = newKey[func(), namespace.ID]()
	UpdateWithStartOnClosingWorkflowRetry    = newKey[func(), namespace.ID]()
	TaskQueuesInDeploymentSyncBatchSize      = newKey[int, global]()
	MatchingIgnoreRoutingConfigRevisionCheck = newKey[bool, namespace.ID]()
	MatchingDeploymentRegisterErrorBackoff   = newKey[time.Duration, namespace.ID]()
	MatchingForwardTaskDelay                 = newKey[time.Duration, namespace.ID]()
)

Test hook keys with their return type and scope. Try to avoid global scope as it requires a dedicated test cluster.

View Source
var GlobalScope = global{}

GlobalScope is the singleton value for global hooks.

Functions

func Call

func Call[S any](_ TestHooks, _ Key[func(), S], _ S)

Call calls a func() hook if present.

TestHooks should be used very sparingly, see comment on TestHooks.

func Get

func Get[T any, S any](_ TestHooks, _ Key[T, S], _ S) (T, bool)

Get gets the value of a test hook. In production mode it always returns the zero value and false, which hopefully the compiler will inline and remove the hook as dead code.

TestHooks should be used very sparingly, see comment on TestHooks.

func Set

func Set[T any, S any](_ TestHooks, _ Key[T, S], _ T, _ any) func()

Set is only to be used by test code together with the test_dep build tag.

Types

type Hook

type Hook struct{}

Hook is an empty stub in production mode. NewHook and its methods are only available with -tags=test_dep.

func NewHook

func NewHook[T any, S any](_ Key[T, S], _ T) Hook

func (Hook) Apply

func (h Hook) Apply(_ TestHooks, _ any) func()

func (Hook) Scope

func (h Hook) Scope() ScopeType

type Key

type Key[T any, S any] struct {
	// contains filtered or unexported fields
}

type ScopeType

type ScopeType int

ScopeType indicates the scope of a hook at runtime.

const (
	ScopeNamespace ScopeType = iota
	ScopeGlobal
)

type TestHooks

type TestHooks struct{}

TestHooks (in production mode) is an empty struct just so the build works. See TestHooks in test_impl.go.

TestHooks are an inherently unclean way of writing tests. They require mixing test-only concerns into production code. In general you should prefer other ways of writing tests wherever possible, and only use TestHooks sparingly, as a last resort.

func NewTestHooks

func NewTestHooks() TestHooks

Jump to

Keyboard shortcuts

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