From 9440b4f816a33eb2baf14aec1317521fdea5e92b Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Sun, 15 Feb 2026 12:46:17 -0500 Subject: [PATCH] test: remove redundant tests Remove integration tests in config_extended_test.go that duplicate unit tests in config_test.go for findLocalCheatpath. Remove redundant fuzz functions (FuzzFindLocalCheatpathNearestWins, FuzzTagsStress), a duplicate parse test (TestParseInvalidYAML), and a permanently-skipped interactive test (TestPromptIntegration). Co-Authored-By: Claude Opus 4.6 --- internal/config/config_extended_test.go | 236 ------------------------ internal/config/config_fuzz_test.go | 55 ------ internal/installer/prompt_test.go | 21 --- internal/sheet/parse_extended_test.go | 19 -- internal/sheets/tags_fuzz_test.go | 61 ------ 5 files changed, 392 deletions(-) diff --git a/internal/config/config_extended_test.go b/internal/config/config_extended_test.go index 7060f40..4c0a3fd 100644 --- a/internal/config/config_extended_test.go +++ b/internal/config/config_extended_test.go @@ -30,242 +30,6 @@ func TestConfigYAMLErrors(t *testing.T) { } } -// TestConfigLocalCheatpath tests local .cheat directory detection -func TestConfigLocalCheatpath(t *testing.T) { - // Create a temporary directory to act as working directory - tempDir, err := os.MkdirTemp("", "cheat-config-test-*") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) - - // Resolve symlinks in temp dir path (macOS /var -> /private/var) - tempDir, err = filepath.EvalSymlinks(tempDir) - if err != nil { - t.Fatalf("failed to resolve temp dir symlinks: %v", err) - } - - // Save current working directory - oldCwd, err := os.Getwd() - if err != nil { - t.Fatalf("failed to get cwd: %v", err) - } - defer os.Chdir(oldCwd) - - // Change to temp directory - err = os.Chdir(tempDir) - if err != nil { - t.Fatalf("failed to change dir: %v", err) - } - - // Create .cheat directory - localCheat := filepath.Join(tempDir, ".cheat") - err = os.Mkdir(localCheat, 0755) - if err != nil { - t.Fatalf("failed to create .cheat dir: %v", err) - } - - // Load config - conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false) - if err != nil { - t.Errorf("failed to load config: %v", err) - } - - // Check that local cheatpath was added - found := false - for _, cp := range conf.Cheatpaths { - if cp.Name == "cwd" && cp.Path == localCheat { - found = true - break - } - } - - if !found { - t.Error("local .cheat directory was not added to cheatpaths") - } -} - -// TestConfigLocalCheatpathInParent tests that .cheat in a parent directory is found -func TestConfigLocalCheatpathInParent(t *testing.T) { - tempDir, err := os.MkdirTemp("", "cheat-config-test-*") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) - - // Resolve symlinks in temp dir path (macOS /var -> /private/var) - tempDir, err = filepath.EvalSymlinks(tempDir) - if err != nil { - t.Fatalf("failed to resolve temp dir symlinks: %v", err) - } - - oldCwd, err := os.Getwd() - if err != nil { - t.Fatalf("failed to get cwd: %v", err) - } - defer os.Chdir(oldCwd) - - // Create .cheat in the root of the temp dir - localCheat := filepath.Join(tempDir, ".cheat") - if err := os.Mkdir(localCheat, 0755); err != nil { - t.Fatalf("failed to create .cheat dir: %v", err) - } - - // Create a subdirectory and cd into it - subDir := filepath.Join(tempDir, "sub") - if err := os.Mkdir(subDir, 0755); err != nil { - t.Fatalf("failed to create sub dir: %v", err) - } - if err := os.Chdir(subDir); err != nil { - t.Fatalf("failed to chdir: %v", err) - } - - conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false) - if err != nil { - t.Errorf("failed to load config: %v", err) - } - - found := false - for _, cp := range conf.Cheatpaths { - if cp.Name == "cwd" && cp.Path == localCheat { - found = true - break - } - } - if !found { - t.Error("parent .cheat directory was not added to cheatpaths") - } -} - -// TestConfigLocalCheatpathNearestWins tests that the nearest .cheat wins -func TestConfigLocalCheatpathNearestWins(t *testing.T) { - tempDir, err := os.MkdirTemp("", "cheat-config-test-*") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) - - // Resolve symlinks in temp dir path (macOS /var -> /private/var) - tempDir, err = filepath.EvalSymlinks(tempDir) - if err != nil { - t.Fatalf("failed to resolve temp dir symlinks: %v", err) - } - - oldCwd, err := os.Getwd() - if err != nil { - t.Fatalf("failed to get cwd: %v", err) - } - defer os.Chdir(oldCwd) - - // Create .cheat at root - if err := os.Mkdir(filepath.Join(tempDir, ".cheat"), 0755); err != nil { - t.Fatalf("failed to create root .cheat dir: %v", err) - } - - // Create sub/.cheat (the nearer one) - subDir := filepath.Join(tempDir, "sub") - if err := os.Mkdir(subDir, 0755); err != nil { - t.Fatalf("failed to create sub dir: %v", err) - } - nearCheat := filepath.Join(subDir, ".cheat") - if err := os.Mkdir(nearCheat, 0755); err != nil { - t.Fatalf("failed to create near .cheat dir: %v", err) - } - - // cd into sub/deep/ - deepDir := filepath.Join(subDir, "deep") - if err := os.Mkdir(deepDir, 0755); err != nil { - t.Fatalf("failed to create deep dir: %v", err) - } - if err := os.Chdir(deepDir); err != nil { - t.Fatalf("failed to chdir: %v", err) - } - - conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false) - if err != nil { - t.Errorf("failed to load config: %v", err) - } - - found := false - for _, cp := range conf.Cheatpaths { - if cp.Name == "cwd" { - if cp.Path != nearCheat { - t.Errorf("expected nearest .cheat %s, got %s", nearCheat, cp.Path) - } - found = true - break - } - } - if !found { - t.Error("no cwd cheatpath found") - } -} - -// TestConfigNoLocalCheatpath tests that no cwd cheatpath is added when no .cheat exists -func TestConfigNoLocalCheatpath(t *testing.T) { - tempDir, err := os.MkdirTemp("", "cheat-config-test-*") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) - - oldCwd, err := os.Getwd() - if err != nil { - t.Fatalf("failed to get cwd: %v", err) - } - defer os.Chdir(oldCwd) - - if err := os.Chdir(tempDir); err != nil { - t.Fatalf("failed to chdir: %v", err) - } - - conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false) - if err != nil { - t.Errorf("failed to load config: %v", err) - } - - for _, cp := range conf.Cheatpaths { - if cp.Name == "cwd" { - t.Error("cwd cheatpath should not be added when no .cheat exists") - } - } -} - -// TestConfigLocalCheatpathFileSkipped tests that a .cheat file (not dir) is skipped -func TestConfigLocalCheatpathFileSkipped(t *testing.T) { - tempDir, err := os.MkdirTemp("", "cheat-config-test-*") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.RemoveAll(tempDir) - - oldCwd, err := os.Getwd() - if err != nil { - t.Fatalf("failed to get cwd: %v", err) - } - defer os.Chdir(oldCwd) - - // Create .cheat as a file, not a directory - if err := os.WriteFile(filepath.Join(tempDir, ".cheat"), []byte("not a dir"), 0644); err != nil { - t.Fatalf("failed to create .cheat file: %v", err) - } - - if err := os.Chdir(tempDir); err != nil { - t.Fatalf("failed to chdir: %v", err) - } - - conf, err := New(map[string]interface{}{}, mock.Path("conf/empty.yml"), false) - if err != nil { - t.Errorf("failed to load config: %v", err) - } - - for _, cp := range conf.Cheatpaths { - if cp.Name == "cwd" { - t.Error("cwd cheatpath should not be added for a .cheat file") - } - } -} - // TestConfigDefaults tests default values func TestConfigDefaults(t *testing.T) { // Load empty config diff --git a/internal/config/config_fuzz_test.go b/internal/config/config_fuzz_test.go index 801795d..c7b2c84 100644 --- a/internal/config/config_fuzz_test.go +++ b/internal/config/config_fuzz_test.go @@ -65,58 +65,3 @@ func FuzzFindLocalCheatpath(f *testing.F) { } }) } - -// FuzzFindLocalCheatpathNearestWins verifies that when two .cheat directories -// exist at different levels of the ancestor chain, the nearest one is returned. -func FuzzFindLocalCheatpathNearestWins(f *testing.F) { - f.Add(uint8(5), uint8(1), uint8(3)) - f.Add(uint8(8), uint8(0), uint8(7)) - f.Add(uint8(3), uint8(0), uint8(2)) - f.Add(uint8(10), uint8(2), uint8(8)) - - f.Fuzz(func(t *testing.T, totalDepth, shallowRaw, deepRaw uint8) { - depth := int(totalDepth%12) + 2 // 2..13 (need room for two placements) - s := int(shallowRaw) % depth - d := int(deepRaw) % depth - - // Need two distinct levels - if s == d { - d = (d + 1) % depth - } - // Ensure s < d (shallow is higher in tree, deep is closer to search dir) - if s > d { - s, d = d, s - } - - tempDir := t.TempDir() - - // Build chain - dirs := make([]string, 0, depth+1) - dirs = append(dirs, tempDir) - current := tempDir - for i := 0; i < depth; i++ { - current = filepath.Join(current, fmt.Sprintf("d%d", i)) - if err := os.Mkdir(current, 0755); err != nil { - t.Fatalf("mkdir: %v", err) - } - dirs = append(dirs, current) - } - - // Place .cheat at both levels - shallowCheat := filepath.Join(dirs[s], ".cheat") - deepCheat := filepath.Join(dirs[d], ".cheat") - if err := os.Mkdir(shallowCheat, 0755); err != nil { - t.Fatalf("mkdir shallow .cheat: %v", err) - } - if err := os.Mkdir(deepCheat, 0755); err != nil { - t.Fatalf("mkdir deep .cheat: %v", err) - } - - // Search from the deepest directory — should find the deeper (nearer) .cheat - result := findLocalCheatpath(current) - if result != deepCheat { - t.Errorf("depth=%d shallow=%d deep=%d: expected nearest %s, got %s", - depth, s, d, deepCheat, result) - } - }) -} diff --git a/internal/installer/prompt_test.go b/internal/installer/prompt_test.go index faf28b6..a96597e 100644 --- a/internal/installer/prompt_test.go +++ b/internal/installer/prompt_test.go @@ -2,7 +2,6 @@ package installer import ( "bytes" - "fmt" "io" "os" "strings" @@ -158,23 +157,3 @@ func TestPromptError(t *testing.T) { t.Errorf("expected 'failed to prompt' error, got: %v", err) } } - -// TestPromptIntegration provides a simple integration test -func TestPromptIntegration(t *testing.T) { - // This demonstrates how the prompt would be used in practice - // It's skipped by default since it requires actual user input - if os.Getenv("TEST_INTERACTIVE") != "1" { - t.Skip("Skipping interactive test - set TEST_INTERACTIVE=1 to run") - } - - fmt.Println("\n=== Interactive Prompt Test ===") - fmt.Println("You will be prompted to answer a question.") - fmt.Println("Try different inputs: y, n, Y, N, empty (just press Enter)") - - result, err := Prompt("Would you like to continue? [Y/n]", true) - if err != nil { - t.Fatalf("Prompt failed: %v", err) - } - - fmt.Printf("You answered: %v\n", result) -} diff --git a/internal/sheet/parse_extended_test.go b/internal/sheet/parse_extended_test.go index e0962ab..60b019e 100644 --- a/internal/sheet/parse_extended_test.go +++ b/internal/sheet/parse_extended_test.go @@ -27,22 +27,3 @@ func TestParseWindowsLineEndings(t *testing.T) { t.Errorf("failed to parse syntax: want: %s, got: %s", want, fm.Syntax) } } - -// TestParseInvalidYAML tests parsing with invalid YAML in frontmatter -func TestParseInvalidYAML(t *testing.T) { - // stub our cheatsheet content with invalid YAML - markdown := `--- -syntax: go -tags: [ test - unclosed bracket ---- -To foo the bar: baz` - - // parse the frontmatter - _, _, err := parse(markdown) - - // assert that an error was returned for invalid YAML - if err == nil { - t.Error("expected error for invalid YAML, got nil") - } -} diff --git a/internal/sheets/tags_fuzz_test.go b/internal/sheets/tags_fuzz_test.go index 62a40a1..69a001f 100644 --- a/internal/sheets/tags_fuzz_test.go +++ b/internal/sheets/tags_fuzz_test.go @@ -127,64 +127,3 @@ func FuzzTags(f *testing.F) { }() }) } - -// FuzzTagsStress tests Tags function with large numbers of tags -func FuzzTagsStress(f *testing.F) { - // Seed: number of unique tags, number of sheets, tags per sheet - f.Add(10, 10, 5) - f.Add(100, 50, 10) - f.Add(1000, 100, 20) - - f.Fuzz(func(t *testing.T, numUniqueTags int, numSheets int, tagsPerSheet int) { - // Limit to reasonable values - if numUniqueTags > 1000 || numUniqueTags < 0 || - numSheets > 1000 || numSheets < 0 || - tagsPerSheet > 100 || tagsPerSheet < 0 { - t.Skip("Skipping unreasonable test case") - } - - // Generate unique tags - uniqueTags := make([]string, numUniqueTags) - for i := 0; i < numUniqueTags; i++ { - uniqueTags[i] = "tag" + string(rune(i)) - } - - // Create sheets with random tags - cheatpaths := []map[string]sheet.Sheet{ - make(map[string]sheet.Sheet), - } - - for i := 0; i < numSheets; i++ { - // Select random tags for this sheet - sheetTags := make([]string, 0, tagsPerSheet) - for j := 0; j < tagsPerSheet && j < numUniqueTags; j++ { - // Distribute tags across sheets - tagIndex := (i*tagsPerSheet + j) % numUniqueTags - sheetTags = append(sheetTags, uniqueTags[tagIndex]) - } - - cheatpaths[0]["sheet"+string(rune(i))] = sheet.Sheet{ - Title: "sheet" + string(rune(i)), - Tags: sheetTags, - } - } - - // Should handle large numbers efficiently - func() { - defer func() { - if r := recover(); r != nil { - t.Errorf("Tags panicked with %d unique tags, %d sheets, %d tags/sheet: %v", - numUniqueTags, numSheets, tagsPerSheet, r) - } - }() - - result := Tags(cheatpaths) - - // Should have at most numUniqueTags in result - if len(result) > numUniqueTags { - t.Errorf("More tags in result (%d) than unique tags created (%d)", - len(result), numUniqueTags) - } - }() - }) -}