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

Function checkGoldenDir

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

Source from the content-addressed store, hash-verified

175}
176
177func checkGoldenDir(t *testing.T, origDir, resultDir, goldenDir string) {
178 t.Helper()
179 golden := true
180 t.Cleanup(func() {
181 t.Helper()
182 if !golden {
183 t.Log("To regenerate golden files run `UPDATE_GOLDEN=1 script/test.sh`")
184 }
185 })
186 updateGoldenDir(t, origDir, resultDir, goldenDir)
187 checked := map[string]bool{}
188 _, err := os.Stat(goldenDir)
189 if err == nil {
190 assertNilError(t, filepath.Walk(goldenDir, func(wantPath string, info fs.FileInfo, err error) error {
191 relPath := mustRel(t, goldenDir, wantPath)
192 if err != nil || info.IsDir() {
193 return err
194 }
195 if !assertEqualFiles(t, wantPath, filepath.Join(resultDir, relPath)) {
196 golden = false
197 }
198 checked[relPath] = true
199 return nil
200 }))
201 }
202 assertNilError(t, filepath.Walk(origDir, func(wantPath string, info fs.FileInfo, err error) error {
203 relPath := mustRel(t, origDir, wantPath)
204 if err != nil || info.IsDir() || checked[relPath] {
205 return err
206 }
207 if !assertEqualFiles(t, wantPath, filepath.Join(resultDir, relPath)) {
208 golden = false
209 }
210 checked[relPath] = true
211 return nil
212 }))
213 assertNilError(t, filepath.Walk(resultDir, func(resultPath string, info fs.FileInfo, err error) error {
214 relPath := mustRel(t, resultDir, resultPath)
215 if err != nil || info.IsDir() || checked[relPath] {
216 return err
217 }
218 golden = false
219 return fmt.Errorf("found unexpected file:\n%v", relPath)
220 }))
221}
222
223func mustRel(t *testing.T, base, target string) string {
224 t.Helper()

Callers 1

checkGoldenMethod · 0.85

Calls 4

updateGoldenDirFunction · 0.85
mustRelFunction · 0.85
assertEqualFilesFunction · 0.85
assertNilErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…