TestFindLocalCheatpathNearestWins tests that the closest .cheat is returned
(t *testing.T)
| 83 | |
| 84 | // TestFindLocalCheatpathNearestWins tests that the closest .cheat is returned |
| 85 | func TestFindLocalCheatpathNearestWins(t *testing.T) { |
| 86 | tempDir, err := os.MkdirTemp("", "cheat-test-*") |
| 87 | if err != nil { |
| 88 | t.Fatalf("failed to create temp dir: %v", err) |
| 89 | } |
| 90 | defer os.RemoveAll(tempDir) |
| 91 | |
| 92 | // Create .cheat at root level |
| 93 | if err := os.Mkdir(filepath.Join(tempDir, ".cheat"), 0755); err != nil { |
| 94 | t.Fatalf("failed to create root .cheat dir: %v", err) |
| 95 | } |
| 96 | |
| 97 | // Create sub/.cheat (the nearer one) |
| 98 | subDir := filepath.Join(tempDir, "sub") |
| 99 | if err := os.Mkdir(subDir, 0755); err != nil { |
| 100 | t.Fatalf("failed to create sub dir: %v", err) |
| 101 | } |
| 102 | nearCheatDir := filepath.Join(subDir, ".cheat") |
| 103 | if err := os.Mkdir(nearCheatDir, 0755); err != nil { |
| 104 | t.Fatalf("failed to create sub .cheat dir: %v", err) |
| 105 | } |
| 106 | |
| 107 | // Search from sub/deep/ |
| 108 | deepDir := filepath.Join(subDir, "deep") |
| 109 | if err := os.Mkdir(deepDir, 0755); err != nil { |
| 110 | t.Fatalf("failed to create deep dir: %v", err) |
| 111 | } |
| 112 | |
| 113 | result := findLocalCheatpath(deepDir) |
| 114 | if result != nearCheatDir { |
| 115 | t.Errorf("expected nearest %s, got %s", nearCheatDir, result) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // TestFindLocalCheatpathNotFound tests that empty string is returned when no .cheat exists |
| 120 | func TestFindLocalCheatpathNotFound(t *testing.T) { |
nothing calls this directly
no test coverage detected