Documentation
¶
Index ¶
- func CompareOutToGolden(outfilepath, goldenfilepath string) error
- func FatalIfError(t *testing.T, err error, label string)
- func RunOne(r MultiRunner) error
- func RunTest(r Runner) error
- type MultiRunner
- type Runner
- type Tester
- func (r *Tester) Act() error
- func (r *Tester) Arrange() error
- func (r *Tester) Assert() error
- func (r *Tester) Close() error
- func (r *Tester) GetFilePath(fpath, basename, extension string) string
- func (r *Tester) GoldenFilePath() string
- func (r *Tester) Init() error
- func (r *Tester) OutFilePath() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareOutToGolden ¶
CompareOutToGolden reads the outfile and the goldenfile and compares them. It returns an error if they are not the same.
func FatalIfError ¶
FatalIfError calls testing.T.Fatal if there is an error. This is typically used to wrap calls to the various Runner steps, for example:
base.FatalIfError(t, r.Arrange(), "Arrange")
func RunOne ¶
func RunOne(r MultiRunner) error
RunOne runs one test on the MultiRunner by executing Init, then running RunTest, then Close.
Types ¶
type MultiRunner ¶
type MultiRunner interface { Runner // Init does one-time initialization of this Runner before running tests. Init() error // Close cleans everything up. Nothing else can be called after Close. Close() error }
MultiRunner defines the methods used when running multiple tests that include common init and close steps. Typical use for a MultiRunner is to call m.Init(), then do some test-specific setup work and call RunTest, repeat that for all tests, and finish by calling m.Close().
type Runner ¶
type Runner interface { // Arrange sets up for one test, to be performed by Act(). Arrange() error // Act runs the code under test. Act() error // Assert checks the output against the golden file. Assert() error }
Runner defines the methods used when running one of our unit tests.
type Tester ¶
type Tester struct { // Base name for all files in the test, if not overridden; defaults to "test". BaseName string // Base directory; if not set, uses "testdata". BaseDir string // Base name for the test output file; if not set, uses BaseName. OutBaseName string // Path to the test output file; if not set, uses OutBaseName. OutPath string // Base name for the golden file; if not set, uses BaseName. GoldenBaseName string // Path to the golden file; if not set, uses GoldenBaseName. GoldenPath string // Function to run the test. Test func(*Tester) error // The output file. OutF *os.File // A Writer that can be used to write to the output file. OutW *bufio.Writer }
Tester allows for configuring and running the different steps of the test.
func (*Tester) Arrange ¶
Arrange creates the output files for the test to write to and sets OutF and OutW in the Tester.
func (*Tester) GetFilePath ¶
GetFilePath calculates and returns the complete path to a file. If fpath is set, it returns it, else it uses basename, with default "test", and the Tester's BaseDir, with default "testdata", plus the given extension to generate the path to return.
func (*Tester) GoldenFilePath ¶
GoldenFilePath returns the complete path to the golden file.
func (*Tester) OutFilePath ¶
OutFilePath returns the complete path to the output file.