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

Function testGoldenFile

cmd/errtrace/main_test.go:62–96  ·  view source on GitHub ↗
(t *testing.T, file string)

Source from the content-addressed store, hash-verified

60}
61
62func testGoldenFile(t *testing.T, file string) {
63 giveSrc, err := os.ReadFile(file)
64 if err != nil {
65 t.Fatal(err)
66 }
67
68 wantSrc, err := os.ReadFile(file + ".golden")
69 if err != nil {
70 t.Fatal("Bad test: missing .golden file:", err)
71 }
72
73 type runTests struct {
74 noOptions bool
75 optNoWrapN bool
76 }
77 run := runTests{true, true} // by default, run all tests.
78 if strings.Contains(string(giveSrc), "@runIf options=<empty>") {
79 run = runTests{noOptions: true}
80 }
81 if strings.Contains(string(giveSrc), "@runIf options=no-wrapn") {
82 run = runTests{optNoWrapN: true}
83 }
84
85 if run.noOptions {
86 t.Run("no options", func(t *testing.T) {
87 testGoldenContents(t, nil /* additionalFlags */, file, giveSrc, wantSrc)
88 })
89 }
90
91 if run.optNoWrapN {
92 t.Run("option no-wrapn", func(t *testing.T) {
93 testGoldenContents(t, []string{"-no-wrapn"}, file, giveSrc, wantSrc)
94 })
95 }
96}
97
98func testGoldenContents(t *testing.T, additionalFlags []string, file string, giveSrc, wantSrc []byte) {
99 wantLogs, err := extractLogs(giveSrc)

Callers 1

TestGoldenFunction · 0.85

Calls 2

testGoldenContentsFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected