reset

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: Apache-2.0 Imports: 6 Imported by: 30

Documentation

Overview

reset package manage resettable operations useful for unit testing. Call reset.setEnabled(true) at begin of the test, call reset.setEnabled(false) at the end test.

All initialization code should register a reset function by reset.Add(), they will execute on .setEnabled(false). reset.Add() has no effect if reset module not enabled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(action func())

Add a reset operation, not add if not enabled.

func ClearInternal

func ClearInternal()

ClearInternal used by reset package unit tests only, never call ClearInternal outside reset package

func Disable

func Disable()

Disable reset manager. If disabled Add function has no effect.

func Enable

func Enable()

Enable reset manager.

func Enabled

func Enabled() bool

Return enabled state. Consider reset.Enabled() as test mode, if it is true, caller can sure she is running inside a unit test.

func Register

func Register(fReset func(), fRecover func())

Register() register two function to cooperate testing reset/recover process. Unlike reset.Add(), which register a reset function to undo things for current call, after current test function finished. Register() normally register at package init() function to be part of testing cycle. Most reset.Add() can be replaced by Register().

Register() is better than Add():

  1. Better performance, when application runs in non-test mode, do not need over and over calling reset.Add().
  2. Add() not work well with static inited items, such as ert tree. Ert tree need reset itself to give a clean environment for next test. But unit test also depends on some pre-registered items in the ert tree, simply reset the whole ert tree can not work, fine control which ert entry need reset is too complex. Use Register() each package can re-register static ert items in the recover function.

fReset function called in ginkgo AfterEach() stage (actually in reset.Disable()), fReset function called in reversed register order. After all fReset() function called, fRecover() functions called by register order.

Both fReset and fRecover can be nil.

fRecover function run immediately on Register to do init job.

func TestMode

func TestMode() bool

TestMode returns true if run as unit test

Types

This section is empty.

Jump to

Keyboard shortcuts

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