MCPcopy
hub / github.com/ddworken/hishtory / CompareGoldens

Function CompareGoldens

shared/testutils/testutils.go:381–406  ·  view source on GitHub ↗
(t testing.TB, out, goldenName string)

Source from the content-addressed store, hash-verified

379}
380
381func CompareGoldens(t testing.TB, out, goldenName string) {
382 recordUsingGolden(t, goldenName)
383 out = normalizeHostnames(out)
384 goldenPath := path.Join(initialWd, "client/testdata/", goldenName)
385 expected, err := os.ReadFile(goldenPath)
386 expected = []byte(normalizeHostnames(string(expected)))
387 if err != nil {
388 if os.IsNotExist(err) {
389 expected = []byte("ERR_FILE_NOT_FOUND:" + goldenPath)
390 } else {
391 require.NoError(t, err)
392 }
393 }
394 if diff := cmp.Diff(string(expected), out); diff != "" {
395 if err := os.Mkdir("/tmp/test-goldens", os.ModePerm); err != nil && !os.IsExist(err) {
396 log.Fatal(err)
397 }
398 require.NoError(t, os.WriteFile(path.Join("/tmp/test-goldens", goldenName), []byte(out), 0o644))
399 if os.Getenv("HISHTORY_UPDATE_GOLDENS") == "" {
400 _, filename, line, _ := runtime.Caller(1)
401 t.Fatalf("hishtory golden mismatch for %s at %s:%d (-expected +got):\n%s\nactual=\n%s", goldenName, filename, line, diff, out)
402 } else {
403 require.NoError(t, os.WriteFile(goldenPath, []byte(out), 0o644))
404 }
405 }
406}
407
408func normalizeHostnames(data string) string {
409 hostnames := []string{"Davids-MacBook-Air", "Davids-MacBook-Air.local", "ghaction-runner-hostname", "Davids-Air"}

Callers 15

testDisplayTableFunction · 0.92
TestFishFunction · 0.92
testTui_resizeFunction · 0.92
testTui_scrollFunction · 0.92
testTui_escapingFunction · 0.92
testTui_fullscreenFunction · 0.92
testTui_defaultFilterFunction · 0.92
testTui_colorFunction · 0.92
testTui_deleteFunction · 0.92
testTui_searchFunction · 0.92
testTui_generalFunction · 0.92

Calls 2

recordUsingGoldenFunction · 0.85
normalizeHostnamesFunction · 0.85

Tested by 15

testDisplayTableFunction · 0.74
TestFishFunction · 0.74
testTui_resizeFunction · 0.74
testTui_scrollFunction · 0.74
testTui_escapingFunction · 0.74
testTui_fullscreenFunction · 0.74
testTui_defaultFilterFunction · 0.74
testTui_colorFunction · 0.74
testTui_deleteFunction · 0.74
testTui_searchFunction · 0.74
testTui_generalFunction · 0.74