Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareWithGolden ¶
func CompareWithGolden(t *testing.T, goldenFile string, actualObj interface{}, opts CompareOptions)
CompareWithGolden compares the actual object against the one from a golden file and let's you specify the options to be used for comparison and golden file production by hand. If the -update flag is given, that golden file is overwritten with the current actual object. When adding new tests you first must run them with the -update flag in order to create an initial golden version.
func UnsetEnvVarAndRestore ¶
func UnsetEnvVarAndRestore(key string) func()
UnsetEnvVarAndRestore unsets the given environment variable with the key (if present). It returns a function to be called whenever you want to restore the original environment.
In a test you can use this to temporarily set an environment variable:
func TestFoo(t *testing.T) { restoreFunc := testutils.UnsetEnvVarAndRestore("foo") defer restoreFunc() os.Setenv(key, "bar") // continue as if foo=bar }
Types ¶
type CompareOptions ¶
type CompareOptions struct { // Whether or not to ignore UUIDs when comparing or writing the golden file // to disk. When this is on we replace UUIDs in both strings (the golden // file as well as in the actual object) before comparing the two strings. // This should make the comparison UUID agnostic without loosing the // locality comparison. In other words, that means we replace each UUID with // a more generic "00000000-0000-0000-0000-000000000001", // "00000000-0000-0000-0000-000000000002", ..., // "00000000-0000-0000-0000-00000000000N" value. UUIDAgnostic bool // Whether or not to ignore date/times when comparing or writing the golden // file to disk. We replace all RFC3339 time strings with // "0001-01-01T00:00:00Z". DateTimeAgnostic bool // Whether or not to call JSON marshall on the actual object before // comparing it against the content of the golden file or writing to the // golden file. If this is false, then we will treat the actual object as a // []byte or string. MarshalInputAsJSON bool }
CompareOptions define how the comparison and golden file generation will take place