teardown

package
v0.151.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Teardown

type Teardown struct {
	CallerOffset int
	// contains filtered or unexported fields
}

func (*Teardown) Defer

func (td *Teardown) Defer(fn interface{}, args ...interface{})

Defer function defers the execution of a function until the current test case returns. Deferred functions are guaranteed to run, regardless of panics during the test case execution. Deferred function calls are pushed onto a testcase runtime stack. When an function passed to the Defer function, it will be executed as a deferred call in last-in-first-orderingOutput order.

It is advised to use this inside a testcase.Spec#Let memorization function when spec variable defined that has finalizer requirements. This allow the specification to ensure the object finalizer requirements to be met, without using an testcase.Spec#After where the memorized function would be executed always, regardless of its actual need.

In a practical example, this means that if you have common vars defined with testcase.Spec#Let memorization, which needs to be Closed for example, after the test case already run. Ensuring such objects Close call in an after block would cause an initialization of the memorized object list the time, even in tests where this is not needed.

e.g.:

  • mock initialization with mock controller, where the mock controller #Finish function must be executed after each testCase suite.
  • sql.DB / sql.Tx
  • basically anything that has the io.Closer interface

https://github.com/golang/go/issues/41891

func (*Teardown) Finish

func (td *Teardown) Finish()

Jump to

Keyboard shortcuts

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