mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-25 01:33:28 +01:00
Remove code that enforces that all goldens are used, since it is incompatible with how tests are currently split into chunks
This commit is contained in:
parent
ea7c714873
commit
06cc3eedbc
@ -2,14 +2,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/DataDog/datadog-go/statsd"
|
"github.com/DataDog/datadog-go/statsd"
|
||||||
"gotest.tools/gotestsum/testjson"
|
"gotest.tools/gotestsum/testjson"
|
||||||
@ -19,77 +15,8 @@ var GLOBAL_STATSD *statsd.Client = nil
|
|||||||
|
|
||||||
var NUM_TEST_RETRIES map[string]int
|
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() {
|
func main() {
|
||||||
exportMetrics()
|
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() {
|
func exportMetrics() {
|
||||||
|
Loading…
Reference in New Issue
Block a user