Documentation
¶
Index ¶
- Variables
- func AssignPrivateField[T any, V any](src *T, field string, value V) error
- func CaptureChan[T any](channel <-chan T, dest *T) func()
- func CreateSTDCapture(t *testing.T) (writer *os.File, capture func() string, err error)
- func ReadPrivateField[T any, V any](src *T, field string) (V, error)
- func RequireChan[T any](tb testing.TB, channel <-chan T, ...)
- func RequireChanC[T any](tb testing.TB, channel <-chan T, ...)
- func RequireGRPCCodesEqual(t *testing.T, err error, code codes.Code)
- func RunCMD(t *testing.T, config *CMDConfig)
- func SendChan[T any](channel chan<- T, value T)
- func WaitConn(t *testing.T, conn *grpc.ClientConn)
- type CMDConfig
- type CMDResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrFieldNotFound = errors.New("field not found") ErrNonStructPtr = errors.New("the first parameter must be a pointer to a struct") )
var ErrDummy = errors.New("uwups")
ErrDummy is used as a placeholder error for tests.
Functions ¶
func AssignPrivateField ¶
AssignPrivateField allows to access and modify private struct fields. Because sometimes just fuck everything.
func CaptureChan ¶
func CaptureChan[T any](channel <-chan T, dest *T) func()
CaptureChan captures the output of a channel and stores it in a pointer.
func CreateSTDCapture ¶
CreateSTDCapture creates a new os.File writer that can be used in place of default system values (such as os.Stdout). The content written into the file can then be retrieved using the returned capture function.
Calling the capture function closes the original writer, so make sure you captured everything you need before calling it.
func ReadPrivateField ¶
ReadPrivateField reads the value of a private, inaccessible field.
func RequireChan ¶
func RequireChanC ¶
func RequireGRPCCodesEqual ¶
RequireGRPCCodesEqual checks if an error is nil or if it is a gRPC error with the expected code.
If the code is codes.OK, it will instead check if the error is nil.
func RunCMD ¶
RunCMD setups a pattern to run test in controlled environments. https://stackoverflow.com/a/33404435/9021186
IMPORTANT: this must be run only once per test.
Types ¶
type CMDConfig ¶
type CMDConfig struct {
// CmdFn is the function that will be executed under the separate process. Its result will then be passed to
// MainFn.
CmdFn func(t *testing.T)
// MainFn is a controller function, that oversees the result of CmdFn. It is used as the actual test result.
MainFn func(t *testing.T, res *CMDResult)
// Env is a replacement env that will be available to the CmdFn.
//
// It is populated with os.Environ first. If present, the variable `JUST_CHECKING` will be filtered out.
Env []string
}
CMDConfig is used to run a command in a controlled environment.
type CMDResult ¶
type CMDResult struct {
// Err is the error returned by exec.Command Run.
Err error
// Success is true if the process exited with a zero status.
Success bool
// STDOut is the captured standard output.
STDOut string
// STDErr is the captured standard error.
STDErr string
}
CMDResult is the result of a command execution by RunCMD.