Skip to content

Commit

Permalink
Remove code that enforces that all goldens are used, since it is inco…
Browse files Browse the repository at this point in the history
…mpatible with how tests are currently split into chunks
  • Loading branch information
ddworken committed Feb 10, 2024
1 parent ea7c714 commit 06cc3ee
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions client/posttest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
package main

import (
"bufio"
"fmt"
"log"
"os"
"path"
"runtime"
"slices"
"strings"

"github.com/DataDog/datadog-go/statsd"
"gotest.tools/gotestsum/testjson"
Expand All @@ -19,77 +15,8 @@ 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() {
Expand Down

0 comments on commit 06cc3ee

Please sign in to comment.