MCPcopy Create free account
hub / github.com/bracesdev/errtrace / TestGolden

Function TestGolden

cmd/errtrace/main_test.go:48–60  ·  view source on GitHub ↗

TestGolden runs errtrace on all .go files inside testdata/golden, and compares the output to the corresponding .golden file. Files must match exactly. If log messages are expected associated with specific lines, they can be included in the source and the .golden file in the format: foo() // want:

(t *testing.T)

Source from the content-addressed store, hash-verified

46// The log message will be matched against the output of errtrace on stderr.
47// The string must be a valid Go string literal.
48func TestGolden(t *testing.T) {
49 files, err := filepath.Glob("testdata/golden/*.go")
50 if err != nil {
51 t.Fatal(err)
52 }
53
54 for _, file := range files {
55 name := strings.TrimSuffix(filepath.Base(file), ".go")
56 t.Run(name, func(t *testing.T) {
57 testGoldenFile(t, file)
58 })
59 }
60}
61
62func testGoldenFile(t *testing.T, file string) {
63 giveSrc, err := os.ReadFile(file)

Callers

nothing calls this directly

Calls 2

testGoldenFileFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected