Add assertion that requires that all goldens are used

This commit is contained in:
David Dworken 2023-12-20 14:31:08 -08:00
parent 8e9c654611
commit 7f9263f931
No known key found for this signature in database
3 changed files with 24 additions and 2 deletions

View File

@ -7,7 +7,7 @@ test:
ftest:
go clean -testcache
TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 gotestsum --packages ./... --rerun-fails=0 --format testname -- -p 1 -run "$(FILTER)" -timeout 60m
HISHTORY_FILTERED_TEST=1 TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 gotestsum --packages ./... --rerun-fails=0 --format testname -- -p 1 -run "$(FILTER)" -timeout 60m
acttest:
act push -j test -e .github/push_event.json --reuse --container-architecture linux/amd64

View File

@ -53,6 +53,9 @@ func TestMain(m *testing.M) {
// Start the tests
m.Run()
// Teardown
testutils.AssertAllGoldensUsed()
}
var shellTesters []shellTester = []shellTester{bashTester{}, zshTester{}}

View File

@ -27,6 +27,7 @@ const (
)
var initialWd string
var usedGoldens map[string]bool
func init() {
initialWd = getInitialWd()
@ -358,9 +359,27 @@ func persistLog() {
checkError(err)
}
func AssertAllGoldensUsed() {
if os.Getenv("HISHTORY_FILTERED_TEST") != "" {
return
}
goldensDir := path.Join(initialWd, "client/testdata/")
files, err := os.ReadDir(goldensDir)
if err != nil {
panic(fmt.Errorf("failed to list files in %s: %w", goldensDir, err))
}
for _, f := range files {
_, present := usedGoldens[path.Base(f.Name())]
if !present && !strings.Contains(f.Name(), "unittestTable-truncatedTable") {
panic(fmt.Errorf("golden file %v was never used", path.Base(f.Name())))
}
}
}
func CompareGoldens(t testing.TB, out, goldenName string) {
usedGoldens[goldenName] = true
out = normalizeHostnames(out)
goldenPath := path.Join(initialWd, "client/lib/goldens/", goldenName)
goldenPath := path.Join(initialWd, "client/testdata/", goldenName)
expected, err := os.ReadFile(goldenPath)
expected = []byte(normalizeHostnames(string(expected)))
if err != nil {