Memoize the glob statement
Because we were doing the same work many times :(
This commit is contained in:
@@ -705,6 +705,58 @@ func TestLoadCommandsFromCookFilesNoYamlFiles(t *testing.T) {
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestExpandGlobsMemoization(t *testing.T) {
|
||||
tmpDir, err := os.MkdirTemp("", "expand-globs-memo-test")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
err = os.WriteFile(filepath.Join(tmpDir, "test1.go"), []byte("test"), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
err = os.WriteFile(filepath.Join(tmpDir, "test2.go"), []byte("test"), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
|
||||
origDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(origDir)
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
resolvedCwd := ResolvePath(cwd)
|
||||
pattern1 := resolvedCwd + "/*.go"
|
||||
patterns := map[string]struct{}{pattern1: {}}
|
||||
|
||||
globMemoTable = make(map[string][]string)
|
||||
|
||||
files1, err := ExpandGlobs(patterns)
|
||||
if err != nil {
|
||||
t.Fatalf("ExpandGlobs failed: %v", err)
|
||||
}
|
||||
if len(files1) != 2 {
|
||||
t.Fatalf("Expected 2 files, got %d", len(files1))
|
||||
}
|
||||
|
||||
if len(globMemoTable) != 1 {
|
||||
t.Fatalf("Expected 1 entry in memo table, got %d", len(globMemoTable))
|
||||
}
|
||||
|
||||
files2, err := ExpandGlobs(patterns)
|
||||
if err != nil {
|
||||
t.Fatalf("ExpandGlobs failed: %v", err)
|
||||
}
|
||||
if len(files2) != 2 {
|
||||
t.Fatalf("Expected 2 files, got %d", len(files2))
|
||||
}
|
||||
|
||||
if len(globMemoTable) != 1 {
|
||||
t.Fatalf("Expected memo table to still have 1 entry, got %d", len(globMemoTable))
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCommandsFromCookFile returns an error for a malformed YAML file
|
||||
// func TestLoadCommandsFromCookFilesMalformedYAML(t *testing.T) {
|
||||
// // Setup test directory with mock YAML files
|
||||
|
||||
Reference in New Issue
Block a user