package fftest
import "github.com/peterbourgon/ff/v3/fftest"
Package fftest provides unit test helpers.
Index ¶
- func Compare(t *testing.T, want, have *Vars)
- func NestedDefaultVars(delimiter string) func(fs *flag.FlagSet) *Vars
- func TempFile(t *testing.T, content string) string
- type StringSlice
- type Vars
Functions ¶
func Compare ¶
Compare one set of vars with another and t.Error on any difference.
func NestedDefaultVars ¶
NestedDefaultVars is similar to DefaultVars, but uses nested flag names.
func TempFile ¶
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 ¶
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 ¶
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 ¶
Pair defines and returns an empty flag set and vars assigned to it.
Source Files ¶
- Version
- v3.4.0 (latest)
- Published
- Jul 20, 2023
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 1 week ago –
Tools for package owners.