testhandler

package
v0.0.0-...-7dff3de Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

func Ctx(useReqID bool, isCancel bool) context.Context

Ctx returns a context to be used in tests.

The difference to context.Background() is as follows: Two contexts produced with context.Background() will be equal, two context produced with this method will not be equal. Also, a context produced with this method will always be unequal to one produced with context.Background().

Problem this solves: A test should be able to detect if a context has been manipulated when it calls mock functions. Most times the context should just be propagated. If the code to be tested is called with a context.Background() and also the call to the mock function is accidentally done with a new context.Background(), the test will not be able to detect this. If using this function instead to generate the context to call the code to be tested, the test can appropriately fail when the contexts are checked for equality.

Types

This section is empty.

Jump to

Keyboard shortcuts

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