MCPcopy Index your code
hub / github.com/jetify-com/devbox / cmpGoldenFile

Function cmpGoldenFile

internal/shellgen/generate_test.go:57–84  ·  view source on GitHub ↗
(t *testing.T, gotPath, wantGoldenPath string)

Source from the content-addressed store, hash-verified

55}
56
57func cmpGoldenFile(t *testing.T, gotPath, wantGoldenPath string) {
58 got, err := os.ReadFile(gotPath)
59 if err != nil {
60 t.Fatal("got error reading generated file:", err)
61 }
62 if *update {
63 err = os.WriteFile(wantGoldenPath, got, 0o666)
64 if err != nil {
65 t.Error("got error updating golden file:", err)
66 }
67 }
68 golden, err := os.ReadFile(wantGoldenPath)
69 if err != nil {
70 t.Fatal("got error reading golden file:", err)
71 }
72 diff := cmp.Diff(golden, got)
73 if diff != "" {
74 t.Errorf(strings.TrimSpace(`
75got wrong file contents (-%s +%s):
76
77%s
78If the new file is correct, you can update the golden file with:
79
80 go test -run "^%s$" -update`),
81 filepath.Base(wantGoldenPath), filepath.Base(gotPath),
82 diff, t.Name())
83 }
84}
85
86var (
87 locker = &lockmock{}

Callers 1

TestWriteFromTemplateFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected