mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 08:14:02 +01:00
Add assertion that requires that all goldens are used
This commit is contained in:
parent
8e9c654611
commit
7f9263f931
2
Makefile
2
Makefile
@ -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
|
||||
|
@ -53,6 +53,9 @@ func TestMain(m *testing.M) {
|
||||
|
||||
// Start the tests
|
||||
m.Run()
|
||||
|
||||
// Teardown
|
||||
testutils.AssertAllGoldensUsed()
|
||||
}
|
||||
|
||||
var shellTesters []shellTester = []shellTester{bashTester{}, zshTester{}}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user