flagsaver

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package flagsaver provides a simple way to save and restore flag values. TODO(RJPercival): Move this to its own GitHub project.

Example:

func TestFoo(t *testing.T) {
  defer flagsaver.Save().Restore()
  // Test code that changes flags
} // flags are reset to their original values here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stash

type Stash struct {
	// contains filtered or unexported fields
}

Stash holds flag values so that they can be restored at the end of a test.

func Save

func Save() *Stash

Save returns a Stash that captures the current value of all non-hidden flags.

func (*Stash) MustRestore

func (s *Stash) MustRestore()

MustRestore calls Restore and exits on failure. It can be used in a defer for tests. If Restore fails then the flags may be in an arbitrary state that could cause subsequent tests to misbehave.

func (*Stash) Restore

func (s *Stash) Restore() error

Restore sets all non-hidden flags to the values they had when the Stash was created.

Jump to

Keyboard shortcuts

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