Documentation
¶
Index ¶
- func Check(t *testing.T, update bool, testdata, name string, data any, opts ...cmp.Option) string
- func Diff(t *testing.T, testdata, name string, data any) string
- func DiffWithOpts(t *testing.T, testdata, name string, data any, opts ...cmp.Option) string
- func DirInit(t *testing.T, root, txtarStr string)
- func RemoveAll(t *testing.T, testdata string)
- func Txtar(t *testing.T, dir string) string
- func TxtarJoin(t TestingT, txtars ...string) string
- func TxtarWith(t *testing.T, nameAndData ...string) string
- func Update(t *testing.T, testdata, name string, data any)
- type Checker
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶ added in v0.3.0
Check updates a golden file when update is true otherwise compares data with the exsiting golden file by DiffWithOpts. If update is true Check does not compare and just return "".
var flagUpdate bool
func init() {
flag.BoolVar(&flagUpdate, "update", false, "update golden files")
}
func Test(t *testing.T) {
got := doSomething()
if diff := golden.Check(t, flagUpdate, "testdata", t.Name(), got); diff != "" {
t.Error(diff)
}
}
func Diff ¶
Diff compares between the given data and a golden file which is stored in testdata as name+".golden". Diff returns difference of them. Diff uses go-cmp to compare.
func DiffWithOpts ¶ added in v0.3.0
DiffWithOpts compares between the given data and a golden file which is stored in testdata as name+".golden". DiffWithOpts returns difference of them. DiffWithOpts uses go-cmp to compare.