Documentation ¶
Index ¶
- Variables
- func UseFrontLoadedReporter(reporter reporters.Reporter) io.Closer
- func UseReporter(reporter reporters.Reporter) io.Closer
- func Verify(t Failable, reader io.Reader) error
- func VerifyAll(t Failable, header string, collection interface{}, ...) error
- func VerifyAllCombinationsFor1(t Failable, header string, transform func(interface{}) string, ...) error
- func VerifyAllCombinationsFor2(t Failable, header string, transform func(interface{}, interface{}) string, ...) error
- func VerifyAllCombinationsFor3(t Failable, header string, transform func(p1, p2, p3 interface{}) string, ...) error
- func VerifyAllCombinationsFor4(t Failable, header string, transform func(p1, p2, p3, p4 interface{}) string, ...) error
- func VerifyAllCombinationsFor5(t Failable, header string, ...) error
- func VerifyAllCombinationsFor6(t Failable, header string, ...) error
- func VerifyAllCombinationsFor7(t Failable, header string, ...) error
- func VerifyAllCombinationsFor8(t Failable, header string, ...) error
- func VerifyAllCombinationsFor9(t Failable, header string, ...) error
- func VerifyArray(t Failable, array interface{}) error
- func VerifyJSONBytes(t Failable, bs []byte) error
- func VerifyJSONStruct(t Failable, obj interface{}) error
- func VerifyMap(t Failable, m interface{}) error
- func VerifyString(t Failable, s string) error
- func VerifyWithExtension(t Failable, reader io.Reader, extWithDot string) error
- func VerifyXMLBytes(t Failable, bs []byte) error
- func VerifyXMLStruct(t Failable, obj interface{}) error
- type Failable
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
// SkipThisCombination should be returned if you do not want to process a particular combination
SkipThisCombination = "♬ SKIP THIS COMBINATION ♬"
)
Functions ¶
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 := UseReporter(reporters.NewBeyondCompareReporter()) defer r.Close() os.Exit(m.Run()) }
func VerifyAll ¶
func VerifyAll(t Failable, header string, collection interface{}, transform func(interface{}) string) error
VerifyAll Example:
VerifyAll(t, "uppercase", []string("dog", "cat"}, func(x interface{}) string { return strings.ToUpper(x.(string)) })
func VerifyAllCombinationsFor1 ¶
func VerifyAllCombinationsFor1(t Failable, header string, transform func(interface{}) string, collection1 interface{}) error
VerifyAllCombinationsFor1 Example:
VerifyAllCombinationsFor1(t, "uppercase", func(x interface{}) string { return strings.ToUpper(x.(string)) }, []string("dog", "cat"})
func VerifyAllCombinationsFor2 ¶
func VerifyAllCombinationsFor2(t Failable, header string, transform func(interface{}, interface{}) string, collection1 interface{}, collection2 interface{}) error
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 ¶
letters := []string{"aaaaa", "bbbbb", "ccccc"} numbers := []int{2, 3} functionToTest := func(text interface{}, length interface{}) string { return text.(string)[:length.(int)] } approvaltests.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
func VerifyAllCombinationsFor3 ¶
func VerifyAllCombinationsFor3( t Failable, header string, transform func(p1, p2, p3 interface{}) string, collection1, collection2, collection3 interface{}) error
VerifyAllCombinationsFor3 is for combinations of 3.
func VerifyAllCombinationsFor4 ¶
func VerifyAllCombinationsFor4( t Failable, header string, transform func(p1, p2, p3, p4 interface{}) string, collection1, collection2, collection3, collection4 interface{}) error
VerifyAllCombinationsFor4 is for combinations of 4.
func VerifyAllCombinationsFor5 ¶
func VerifyAllCombinationsFor5( t Failable, header string, transform func(p1, p2, p3, p4, p5 interface{}) string, collection1, collection2, collection3, collection4, collection5 interface{}) error
VerifyAllCombinationsFor5 is for combinations of 5.
func VerifyAllCombinationsFor6 ¶
func VerifyAllCombinationsFor6( t Failable, header string, transform func(p1, p2, p3, p4, p5, p6 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6 interface{}) error
VerifyAllCombinationsFor6 is for combinations of 6.
func VerifyAllCombinationsFor7 ¶
func VerifyAllCombinationsFor7( t Failable, header string, transform func(p1, p2, p3, p4, p5, p6, p7 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6, collection7 interface{}) error
VerifyAllCombinationsFor7 is for combinations of 7.
func VerifyAllCombinationsFor8 ¶
func VerifyAllCombinationsFor8( t Failable, header string, transform func(p1, p2, p3, p4, p5, p6, p7, p8 interface{}) string, collection1, collection2, collection3, collection4, collection5, collection6, collection7, collection8 interface{}) error
VerifyAllCombinationsFor8 is for combinations of 8.
func VerifyAllCombinationsFor9 ¶
func VerifyAllCombinationsFor9( t 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{}) error
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 ¶
approvaltests.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!
func VerifyWithExtension ¶
VerifyWithExtension Example:
VerifyWithExtension(t, strings.NewReader("Hello"), ".txt")