MCPcopy Create free account
hub / github.com/google/go-github / updateGoldenDir

Function updateGoldenDir

tools/metadata/main_test.go:139–175  ·  view source on GitHub ↗
(t *testing.T, origDir, resultDir, goldenDir string)

Source from the content-addressed store, hash-verified

137}
138
139func updateGoldenDir(t *testing.T, origDir, resultDir, goldenDir string) {
140 t.Helper()
141 if os.Getenv("UPDATE_GOLDEN") == "" {
142 return
143 }
144 assertNilError(t, os.RemoveAll(goldenDir))
145 assertNilError(t, filepath.WalkDir(resultDir, func(path string, d fs.DirEntry, err error) error {
146 if err != nil || d.IsDir() {
147 return err
148 }
149 relName := mustRel(t, resultDir, path)
150 origName := filepath.Join(origDir, relName)
151 _, err = os.Stat(origName)
152 if err != nil {
153 if os.IsNotExist(err) {
154 err = os.MkdirAll(filepath.Dir(filepath.Join(goldenDir, relName)), d.Type())
155 if err != nil {
156 return err
157 }
158 return copyFile(path, filepath.Join(goldenDir, relName))
159 }
160 return err
161 }
162 resContent, err := os.ReadFile(path)
163 if err != nil {
164 return err
165 }
166 origContent, err := os.ReadFile(origName)
167 if err != nil {
168 return err
169 }
170 if bytes.Equal(resContent, origContent) {
171 return nil
172 }
173 return copyFile(path, filepath.Join(goldenDir, relName))
174 }))
175}
176
177func checkGoldenDir(t *testing.T, origDir, resultDir, goldenDir string) {
178 t.Helper()

Callers 1

checkGoldenDirFunction · 0.85

Calls 4

mustRelFunction · 0.85
copyFileFunction · 0.85
EqualMethod · 0.80
assertNilErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…