fftest

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fftest provides unit test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(t *testing.T, want, have *Vars)

Compare one set of vars with another and t.Error on any difference.

func NestedDefaultVars added in v3.4.0

func NestedDefaultVars(delimiter string) func(fs *flag.FlagSet) *Vars

NestedDefaultVars is similar to DefaultVars, but uses nested flag names.

func TempFile

func TempFile(t *testing.T, content string) string

TempFile returns the filename of a temporary file that has been created with the provided content. The file is created in t.TempDir(), which is automatically removed when the test finishes.

Types

type StringSlice

type StringSlice []string

StringSlice is a flag.Value that collects each Set string into a slice, allowing for repeated flags.

func (*StringSlice) Set

func (ss *StringSlice) Set(s string) error

Set implements flag.Value and appends the string to the slice.

func (*StringSlice) String

func (ss *StringSlice) String() string

String implements flag.Value and returns the list of strings, or "..." if no strings have been added.

type Vars

type Vars struct {
	S string
	I int
	F float64
	B bool
	D time.Duration
	X StringSlice

	// ParseError should be assigned as the result of Parse in tests.
	ParseError error

	// If a test case expects an input to generate a parse error,
	// it can specify that error here. The Compare helper will
	// look for it using errors.Is.
	WantParseErrorIs error

	// If a test case expects an input to generate a parse error,
	// it can specify part of that error string here. The Compare
	// helper will look for it using strings.Contains.
	WantParseErrorString string
}

Vars are a common set of variables used for testing.

func DefaultVars added in v3.1.0

func DefaultVars(fs *flag.FlagSet) *Vars

DefaultVars registers a predefined set of variables to the flag set. Tests can call parse on the flag set with a variety of flags, config files, and env vars, and check the resulting effect on the vars.

func NonzeroDefaultVars added in v3.1.0

func NonzeroDefaultVars(fs *flag.FlagSet) *Vars

NonzeroDefaultVars is like DefaultVars, but provides each primitive flag with a nonzero default value. This is useful for tests that explicitly provide a zero value for the type.

func Pair

func Pair() (*flag.FlagSet, *Vars)

Pair defines and returns an empty flag set and vars assigned to it.

Jump to

Keyboard shortcuts

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