Documentation ¶
Overview ¶
Package frameworktestutil contains utilities for testing functions written using the framework.
Index ¶
Constants ¶
const ( DefaultTestDataDirectory = "testdata" DefaultConfigInputFilename = "config.yaml" DefaultInputFilename = "input.yaml" DefaultInputFilenameGlob = "input*.yaml" DefaultOutputFilename = "expected.yaml" DefaultErrorFilename = "errors.txt" )
Variables ¶
This section is empty.
Functions ¶
func RequireEachLineMatches ¶ added in v0.10.21
RequireEachLineMatches is an AssertionFunc that treats each line of expected string as a regex that must match the actual string.
func RequireStrippedStringsEqual ¶ added in v0.10.21
RequireStrippedStringsEqual is an AssertionFunc that does a simple string comparison of expected and actual after normalizing whitespace.
Types ¶
type AssertionFunc ¶ added in v0.10.21
type CommandResultsChecker ¶ added in v0.10.14
type CommandResultsChecker struct { // TestDataDirectory is the directory containing the testdata subdirectories. // CommandResultsChecker will recurse into each test directory and run the Command // if the directory contains at least one of ExpectedOutputFilename or ExpectedErrorFilename. // Defaults to "testdata" TestDataDirectory string // ExpectedOutputFilename is the file with the expected output of the function // Defaults to "expected.yaml". Directories containing neither this file // nor ExpectedErrorFilename will be skipped. ExpectedOutputFilename string // ExpectedErrorFilename is the file containing elements of an expected error message. // Each line of the file will be treated as a regex that must match the actual error. // Defaults to "errors.txt". Directories containing neither this file // nor ExpectedOutputFilename will be skipped. ExpectedErrorFilename string // UpdateExpectedFromActual if set to true will write the actual results to the // expected testdata files. This is useful for updating test data. UpdateExpectedFromActual bool // OutputAssertionFunc allows you to swap out the logic used to compare the expected output // from the fixture file to the actual output. // By default, it performs a string comparison after normalizing whitespace. OutputAssertionFunc AssertionFunc // ErrorAssertionFunc allows you to swap out the logic used to compare the expected error // message from the fixture file to the actual error message. // By default, it interprets each line of the fixture as a regex that the actual error must match. ErrorAssertionFunc AssertionFunc // ConfigInputFilename is the name of the config file provided as the first // argument to the function. Directories without this file will be skipped. // Defaults to "config.yaml" ConfigInputFilename string // InputFilenameGlob matches function inputs // Defaults to "input*.yaml" InputFilenameGlob string // Command provides the function to run. Command func() *cobra.Command // contains filtered or unexported fields }
CommandResultsChecker tests a command-wrapped function by running it with predefined inputs and comparing the outputs to expected results.
func (*CommandResultsChecker) Assert ¶ added in v0.10.14
func (rc *CommandResultsChecker) Assert(t *testing.T) bool
Assert runs the command with the input provided in each valid test directory and verifies that the actual output and error match the fixtures in the directory.
func (CommandResultsChecker) TestCasesRun ¶ added in v0.11.1
func (rc CommandResultsChecker) TestCasesRun() []string
type ProcessorResultsChecker ¶ added in v0.10.14
type ProcessorResultsChecker struct { // TestDataDirectory is the directory containing the testdata subdirectories. // ProcessorResultsChecker will recurse into each test directory and run the Command // if the directory contains at least one of ExpectedOutputFilename or ExpectedErrorFilename. // Defaults to "testdata" TestDataDirectory string // ExpectedOutputFilename is the file with the expected output of the function // Defaults to "expected.yaml". Directories containing neither this file // nor ExpectedErrorFilename will be skipped. ExpectedOutputFilename string // ExpectedErrorFilename is the file containing elements of an expected error message. // Each line of the file will be treated as a regex that must match the actual error. // Defaults to "errors.txt". Directories containing neither this file // nor ExpectedOutputFilename will be skipped. ExpectedErrorFilename string // UpdateExpectedFromActual if set to true will write the actual results to the // expected testdata files. This is useful for updating test data. UpdateExpectedFromActual bool // InputFilename is the name of the file containing the ResourceList input. // Directories without this file will be skipped. // Defaults to "input.yaml" InputFilename string // OutputAssertionFunc allows you to swap out the logic used to compare the expected output // from the fixture file to the actual output. // By default, it performs a string comparison after normalizing whitespace. OutputAssertionFunc AssertionFunc // ErrorAssertionFunc allows you to swap out the logic used to compare the expected error // message from the fixture file to the actual error message. // By default, it interprets each line of the fixture as a regex that the actual error must match. ErrorAssertionFunc AssertionFunc // Processor returns a ResourceListProcessor to run. Processor func() framework.ResourceListProcessor // contains filtered or unexported fields }
ProcessorResultsChecker tests a processor function by running it with predefined inputs and comparing the outputs to expected results.
func (*ProcessorResultsChecker) Assert ¶ added in v0.10.14
func (rc *ProcessorResultsChecker) Assert(t *testing.T) bool
Assert runs the processor with the input provided in each valid test directory and verifies that the actual output and error match the fixtures in the directory.
func (ProcessorResultsChecker) TestCasesRun ¶ added in v0.11.1
func (rc ProcessorResultsChecker) TestCasesRun() []string