ztesting

package
v0.0.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual[T any](t *testing.T, msg string, want, got T)

AssertEqual checks if the given two values are the same. AssertEqual compares want and got using reflect.DeepEqual. See https://go.dev/wiki/TestComments

func AssertEqualErr

func AssertEqualErr(t *testing.T, errReason string, want, got error)

AssertEqualErr checks if the given two errors are the same. Errors are checked by following order and considered the same when one of them returned true.

  • Compare pointer: want == got
  • Compare error: errors.Is(got, want)
  • Compare message: want.Error() == got.Error()

See https://go.dev/wiki/TestComments

func ReplaceRandReader

func ReplaceRandReader(r io.Reader) (done func())

ReplaceRandReader replaces rand.Reader with r. Do not run test parallel when using this. Call done after the test finished to set original rand.Reader.

done := ztesting.ReplaceRandReader(YourReader)
defer done()

func ReplaceStderr

func ReplaceStderr() (r *os.File, done func())

ReplaceStderr replaces os.Stderr and return reader. Do not run test parallel when using this. Call done after the test finished to set original Stderr.

r, done := ztesting.ReplaceStderr()
defer done()

func ReplaceStdin

func ReplaceStdin() (w *os.File, done func())

ReplaceStdin replaces os.Stdin and return writer. Do not run test parallel when using this. Call done after the test finished to set original Stdin.

w, done := ztesting.ReplaceStdin()
defer done()

func ReplaceStdout

func ReplaceStdout() (r *os.File, done func())

ReplaceStdout replaces os.Stdout and return reader. Do not run test parallel when using this. Call done after the test finished to set original Stdout.

r, done := ztesting.ReplaceStdout()
defer done()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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