mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-02 16:35:51 +02: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:
|
ftest:
|
||||||
go clean -testcache
|
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:
|
acttest:
|
||||||
act push -j test -e .github/push_event.json --reuse --container-architecture linux/amd64
|
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
|
// Start the tests
|
||||||
m.Run()
|
m.Run()
|
||||||
|
|
||||||
|
// Teardown
|
||||||
|
testutils.AssertAllGoldensUsed()
|
||||||
}
|
}
|
||||||
|
|
||||||
var shellTesters []shellTester = []shellTester{bashTester{}, zshTester{}}
|
var shellTesters []shellTester = []shellTester{bashTester{}, zshTester{}}
|
||||||
|
@ -27,6 +27,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var initialWd string
|
var initialWd string
|
||||||
|
var usedGoldens map[string]bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initialWd = getInitialWd()
|
initialWd = getInitialWd()
|
||||||
@ -358,9 +359,27 @@ func persistLog() {
|
|||||||
checkError(err)
|
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) {
|
func CompareGoldens(t testing.TB, out, goldenName string) {
|
||||||
|
usedGoldens[goldenName] = true
|
||||||
out = normalizeHostnames(out)
|
out = normalizeHostnames(out)
|
||||||
goldenPath := path.Join(initialWd, "client/lib/goldens/", goldenName)
|
goldenPath := path.Join(initialWd, "client/testdata/", goldenName)
|
||||||
expected, err := os.ReadFile(goldenPath)
|
expected, err := os.ReadFile(goldenPath)
|
||||||
expected = []byte(normalizeHostnames(string(expected)))
|
expected = []byte(normalizeHostnames(string(expected)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user