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.
func RemoveAll ¶
RemoveAll removes all golden files which has .golden extention and is under testdata.
func TxtarJoin ¶ added in v0.4.0
TxtarJoin appends a txtar format values. Its file list are sorted by the file path.
Types ¶
type Checker ¶ added in v0.3.0
type Checker struct { JSONIdent bool // contains filtered or unexported fields }
Checker can do golden file testing for multiple data. Checker holds *testing.T, update flag, testdata directory, test name and options for go-cmp.
func (*Checker) Check ¶ added in v0.3.0
Check do a golden file test for a single data. Check calls Check function with test name which combiend with suffix.
var flagUpdate bool func init() { flag.BoolVar(&flagUpdate, "update", false, "update golden files") } func Test(t *testing.T) { got := doSomething() c := golden.New(t, flagUpdate, "testdata", t.Name()) if diff := c.Check("_someting", got); diff != "" { t.Error(diff) } }