Documentation
¶
Overview ¶
Package approvals allows for easy testing of larger objects that can be saved to a file (images, sounds, csv, etc...)
Index ¶
- Constants
- func CreateGuidScrubber() scrubber
- func CreateMultiScrubber(scrubbers ...scrubber) scrubber
- func CreateNoopScrubber() scrubber
- func CreateRegexScrubber(regex *regexp.Regexp, replacer string) scrubber
- func CreateRegexScrubberWithLabeler(regex *regexp.Regexp, replacer func(int) string) scrubber
- func CreateTemplatedCustomNamerCreator(template string) core.ApprovalNamerCreator
- func GetDateScrubberFor(formattedExample string) (scrubber, error)
- func GetSupportedFormatsRegex() []string
- func NewDateScrubber(pattern string) scrubber
- func NewTemplatedCustomNamer(t core.Failable, template string) *templatedCustomNamer
- func NewVerifyOptions(fields map[string]interface{}, key string, value interface{}) verifyOptions
- func Options() verifyOptions
- func UseFolder(f string)
- func UseFrontLoadedReporter(reporter reporters.Reporter) io.Closer
- func UseReporter(reporter reporters.Reporter) io.Closer
- func Verify(t core.Failable, reader io.Reader, opts ...verifyOptions)
- func VerifyAll(t core.Failable, header string, collection interface{}, ...)
- func VerifyAllCombinationsFor1(t core.Failable, header string, transform func(interface{}) string, ...)
- func VerifyAllCombinationsFor2(t core.Failable, header string, transform func(p1, p2 interface{}) string, ...)
- func VerifyAllCombinationsFor3(t core.Failable, header string, transform func(p1, p2, p3 interface{}) string, ...)
- func VerifyAllCombinationsFor4(t core.Failable, header string, ...)
- func VerifyAllCombinationsFor5(t core.Failable, header string, ...)
- func VerifyAllCombinationsFor6(t core.Failable, header string, ...)
- func VerifyAllCombinationsFor7(t core.Failable, header string, ...)
- func VerifyAllCombinationsFor8(t core.Failable, header string, ...)
- func VerifyAllCombinationsFor9(t core.Failable, header string, ...)
- func VerifyArray(t core.Failable, array interface{}, opts ...verifyOptions)
- func VerifyJSONBytes(t core.Failable, bs []byte, opts ...verifyOptions)
- func VerifyJSONStruct(t core.Failable, obj interface{}, opts ...verifyOptions)
- func VerifyMap(t core.Failable, m interface{}, opts ...verifyOptions)
- func VerifyString(t core.Failable, s string, opts ...verifyOptions)
- func VerifyWithExtension(t core.Failable, reader io.Reader, extWithDot string, opts ...verifyOptions)deprecated
- func VerifyXMLBytes(t core.Failable, bs []byte, opts ...verifyOptions)
- func VerifyXMLStruct(t core.Failable, obj interface{}, opts ...verifyOptions)
- type DateScrubber
- type SupportedFormat
Examples ¶
Constants ¶
const SkipThisCombination = "♬ SKIP THIS COMBINATION ♬"
SkipThisCombination should be returned if you do not want to process a particular combination.
Variables ¶
This section is empty.
Functions ¶
func CreateGuidScrubber ¶
func CreateGuidScrubber() scrubber
func CreateMultiScrubber ¶
func CreateMultiScrubber(scrubbers ...scrubber) scrubber
CreateMultiScrubber allows you to chain multiple scrubbers together
func CreateNoopScrubber ¶
func CreateNoopScrubber() scrubber
NoopScrubber is a scrubber that does nothing
func CreateRegexScrubber ¶
CreateRegexScrubber allows you to create a scrubber that uses a regular expression to scrub data
func CreateRegexScrubberWithLabeler ¶
CreateRegexScrubberWithLabeler allows you to create a scrubber that uses a regular expression to scrub data
func CreateTemplatedCustomNamerCreator ¶ added in v1.2.0
func CreateTemplatedCustomNamerCreator(template string) core.ApprovalNamerCreator
func GetDateScrubberFor ¶
public static DateScrubber getScrubberFor(String formattedExample)
{ for (SupportedFormat pattern : getSupportedFormats()) { DateScrubber scrubber = new DateScrubber(pattern.getRegex()); if ("[Date1]".equals(scrubber.scrub(formattedExample))) { return scrubber; } } throw new FormattedException( "No match found for %s.\n Feel free to add your date at https://github.com/approvals/ApprovalTests.Java/issues/112 \n Current supported formats are: %s", formattedExample, Query.select(getSupportedFormats(), SupportedFormat::getRegex)); }
func GetSupportedFormatsRegex ¶
func GetSupportedFormatsRegex() []string
func NewDateScrubber ¶
func NewDateScrubber(pattern string) scrubber
func NewTemplatedCustomNamer ¶ added in v1.2.0
func NewVerifyOptions ¶
func Options ¶
func Options() verifyOptions
Options enables providing individual Verify functions with customisations such as scrubbers
func UseFolder ¶
func UseFolder(f string)
UseFolder configures which folder to use to store approval files. By default, the approval files will be stored at the same level as the code.
The following examples shows how to use the idiomatic 'testdata' folder for all of your test cases in a package directory.
func TestMain(m *testing.M) { approvals.UseFolder("testdata") os.Exit(m.Run()) }
func UseFrontLoadedReporter ¶
UseFrontLoadedReporter configures reporters ahead of all other reporters to handle situations like CI. These reporters usually prevent reporting in scenarios that are headless.
func UseReporter ¶
UseReporter configures which reporter to use on failure. Add at the test or method level to configure your reporter.
The following examples shows how to use a reporter for all of your test cases in a package directory through go's setup feature.
func TestMain(m *testing.M) { r := approvals.UseReporter(reporters.NewBeyondCompareReporter()) defer r.Close() os.Exit(m.Run()) }
func VerifyAll ¶
func VerifyAll(t core.Failable, header string, collection interface{}, transform func(interface{}) string, opts ...verifyOptions)
VerifyAll Example:
VerifyAll(t, "uppercase", []string("dog", "cat"}, func(x interface{}) string { return strings.ToUpper(x.(string)) })
func VerifyAllCombinationsFor1 ¶
func VerifyAllCombinationsFor1(t core.Failable, header string, transform func(interface{}) string, collection1 interface{})
VerifyAllCombinationsFor1 Example:
VerifyAllCombinationsFor1(t, "uppercase", func(x interface{}) string { return strings.ToUpper(x.(string)) }, []string("dog", "cat"})
func VerifyAllCombinationsFor2 ¶
func VerifyAllCombinationsFor2( t core.Failable, header string, transform func(p1, p2 interface{}) string, collection1, collection2 interface{})
VerifyAllCombinationsFor2 calls the transform function with all combinations from collection 1 and collection 2. The resulting received file contains all inputs and the resulting outputs. The received file is then compared to the approved version. If the transform function returns SkipThisCombination the output of this combination won't be displayed inside the received file.
Example ¶
t = makeExamplesRunLikeTests("ExampleVerifyAllCombinationsFor2") letters := []string{"aaaaa", "bbbbb", "ccccc"} numbers := []int{2, 3} functionToTest := func(text interface{}, length interface{}) string { return text.(string)[:length.(int)] } approvals.VerifyAllCombinationsFor2(t, "substring", functionToTest, letters, numbers) printFileContent("examples_test.ExampleVerifyAllCombinationsFor2.received.txt")
Output: This produced the file examples_test.ExampleVerifyAllCombinationsFor2.received.txt It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2.approved.txt file and contains the text: substring [aaaaa,2] => aa [aaaaa,3] => aaa [bbbbb,2] => bb [bbbbb,3] => bbb [ccccc,2] => cc [ccccc,3] => ccc
Example (WithSkip) ¶
t = makeExamplesRunLikeTests("ExampleVerifyAllCombinationsFor2_withSkip") words := []string{"stack", "fold"} otherWords := []string{"overflow", "trickle"} functionToTest := func(firstWord interface{}, secondWord interface{}) string { first := firstWord.(string) second := secondWord.(string) if first+second == "stackoverflow" { return approvals.SkipThisCombination } return first + second } approvals.VerifyAllCombinationsFor2(t, "combineWords", functionToTest, words, otherWords) printFileContent("examples_test.ExampleVerifyAllCombinationsFor2_withSkip.received.txt")
Output: This produced the file examples_test.ExampleVerifyAllCombinationsFor2_withSkip.received.txt It will be compared against the examples_test.ExampleVerifyAllCombinationsFor2_withSkip.approved.txt file and contains the text: combineWords [stack,trickle] => stacktrickle [fold,overflow] => foldoverflow [fold,trickle] => foldtrickle
func VerifyAllCombinationsFor3 ¶
func VerifyAllCombinationsFor3( t core.Failable, header string, transform func(p1, p2, p3 interface{}) string, collection1, collection2, collection3 interface{})
VerifyAllCombinationsFor3 is for combinations of 3.
func VerifyAllCombinationsFor4 ¶
func VerifyAllCombinationsFor4( t core.Failable, header string, transform func(p1, p2, p3, p4 interface{}) string, collection1, collection2, collection3, collection4 interface{})
VerifyAllCombinationsFor4 is for combinations of 4.
func VerifyAllCombinationsFor5 ¶
func VerifyAllCombinationsFor5( t core.Failable, header string, transform func(p1, p2, p3, p4, p5 interface{}) string, collection1, collection2, collection3, collection4, collection5 interface{})
VerifyAllCombinationsFor5 is for combinations of 5.
func VerifyAllCombinationsFor6 ¶
func VerifyAllCombinationsFor6( t core.Failable, header string, transform func(p1, p2, p3, p4, p5, p6 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6 interface{})
VerifyAllCombinationsFor6 is for combinations of 6.
func VerifyAllCombinationsFor7 ¶
func VerifyAllCombinationsFor7( t core.Failable, header string, transform func(p1, p2, p3, p4, p5, p6, p7 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6, collection7 interface{})
VerifyAllCombinationsFor7 is for combinations of 7.
func VerifyAllCombinationsFor8 ¶
func VerifyAllCombinationsFor8( t core.Failable, header string, transform func(p1, p2, p3, p4, p5, p6, p7, p8 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8 interface{})
VerifyAllCombinationsFor8 is for combinations of 8.
func VerifyAllCombinationsFor9 ¶
func VerifyAllCombinationsFor9( t core.Failable, header string, transform func(a, b, c, d, e, f, g, h, i interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8, collection9 interface{})
VerifyAllCombinationsFor9 is for combinations of 9.
func VerifyJSONBytes ¶
VerifyJSONBytes Example:
VerifyJSONBytes(t, []byte("{ \"Greeting\": \"Hello\" }"))
func VerifyString ¶
VerifyString stores the passed string into the received file and confirms that it matches the approved local file. On failure, it will launch a reporter.
Example ¶
t = makeExamplesRunLikeTests("ExampleVerifyString") approvals.VerifyString(t, "Hello World!") printFileContent("examples_test.ExampleVerifyString.received.txt")
Output: This produced the file examples_test.ExampleVerifyString.received.txt It will be compared against the examples_test.ExampleVerifyString.approved.txt file and contains the text: Hello World!
Types ¶
type DateScrubber ¶
type DateScrubber struct {
// contains filtered or unexported fields
}
type SupportedFormat ¶
func GetSupportedFormats ¶
func GetSupportedFormats() []SupportedFormat
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
Package reporters provides types to report comparison results.
|
Package reporters provides types to report comparison results. |
Package utils contains functions supporting approval testing.
|
Package utils contains functions supporting approval testing. |