mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 09:43:20 +01:00
Revert "Remove code that enforces that all goldens are used, since it is incompatible with how tests are currently split into chunks"
This reverts commit 06cc3eedbc
.
This commit is contained in:
parent
25ecebef64
commit
1deb3cffc6
@ -2,10 +2,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/DataDog/datadog-go/statsd"
|
||||
"gotest.tools/gotestsum/testjson"
|
||||
@ -15,8 +19,77 @@ var GLOBAL_STATSD *statsd.Client = nil
|
||||
|
||||
var NUM_TEST_RETRIES map[string]int
|
||||
|
||||
var UNUSED_GOLDENS []string = []string{"TestTui-Exit", "testControlR-ControlC-bash", "testControlR-ControlC-fish",
|
||||
"testControlR-ControlC-zsh", "testControlR-SelectMultiline-bash", "testControlR-SelectMultiline-fish",
|
||||
"testControlR-SelectMultiline-zsh", "testControlR-bash-Disabled", "testControlR-fish-Disabled",
|
||||
"testControlR-zsh-Disabled", "testCustomColumns-query-isAction=false", "testCustomColumns-tquery-bash",
|
||||
"testCustomColumns-tquery-zsh", "testUninstall-post-uninstall-bash",
|
||||
"testUninstall-post-uninstall-zsh", "TestTui-ColoredOutput",
|
||||
"TestTui-ColoredOutputWithCustomColorScheme", "TestTui-ColoredOutputWithSearch", "TestTui-ColoredOutputWithSearch-Highlight",
|
||||
"TestTui-DefaultColorScheme", "TestTui-ColoredOutputWithDefaultFilter"}
|
||||
|
||||
func main() {
|
||||
exportMetrics()
|
||||
checkGoldensUsed()
|
||||
}
|
||||
|
||||
func checkGoldensUsed() {
|
||||
if os.Getenv("HISHTORY_FILTERED_TEST") != "" {
|
||||
return
|
||||
}
|
||||
// Read the goldens that were used
|
||||
usedGoldens := make([]string, 0)
|
||||
usedGoldensFile, err := os.Open("/tmp/goldens-used.txt")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open /tmp/goldens-used.txt: %v", err)
|
||||
}
|
||||
defer usedGoldensFile.Close()
|
||||
scanner := bufio.NewScanner(usedGoldensFile)
|
||||
for scanner.Scan() {
|
||||
usedGoldens = append(usedGoldens, strings.TrimSpace(scanner.Text()))
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatalf("failed to read lines from /tmp/goldens-used.txt: %v", err)
|
||||
}
|
||||
|
||||
// List all the goldens that exist
|
||||
goldensDir := "client/testdata/"
|
||||
files, err := os.ReadDir(goldensDir)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to list files in %s: %w", goldensDir, err))
|
||||
}
|
||||
|
||||
// And check for mismatches
|
||||
var unusedGoldenErr error = nil
|
||||
for _, f := range files {
|
||||
goldenName := path.Base(f.Name())
|
||||
if !slices.Contains(usedGoldens, goldenName) {
|
||||
if slices.Contains(UNUSED_GOLDENS, goldenName) {
|
||||
// It is allowlisted to not be used
|
||||
continue
|
||||
}
|
||||
if (runtime.GOOS == "darwin" && strings.Contains(goldenName, "-linux")) ||
|
||||
(runtime.GOOS == "linux" && strings.Contains(goldenName, "-darwin")) {
|
||||
// It is for another OS
|
||||
continue
|
||||
}
|
||||
unusedGoldenErr = fmt.Errorf("golden file %v was never used", goldenName)
|
||||
fmt.Println(unusedGoldenErr)
|
||||
}
|
||||
}
|
||||
if unusedGoldenErr != nil {
|
||||
log.Fatalf("%v", unusedGoldenErr)
|
||||
}
|
||||
|
||||
// And print out anything that is in UNUSED_GOLDENS that was actually used, so we
|
||||
// can manually trim UNUSED_GOLDENS
|
||||
for _, g := range UNUSED_GOLDENS {
|
||||
if slices.Contains(usedGoldens, g) {
|
||||
fmt.Printf("Golden %s is in UNUSED_GOLDENS, but was actually used\n", g)
|
||||
}
|
||||
}
|
||||
fmt.Println("Validated that all goldens in testdata/ were referenced!")
|
||||
|
||||
}
|
||||
|
||||
func exportMetrics() {
|
||||
|
Loading…
Reference in New Issue
Block a user