MCPcopy
hub / github.com/cheat/cheat / TestFindLocalCheatpathSymlinkInAncestor

Function TestFindLocalCheatpathSymlinkInAncestor

internal/config/config_test.go:179–210  ·  view source on GitHub ↗

TestFindLocalCheatpathSymlinkInAncestor tests discovery through a symlinked ancestor directory. When the cwd is reached via a symlink, filepath.Dir walks the symlinked path (not the real path), so .cheat must be findable through that chain.

(t *testing.T)

Source from the content-addressed store, hash-verified

177// walks the symlinked path (not the real path), so .cheat must be findable
178// through that chain.
179func TestFindLocalCheatpathSymlinkInAncestor(t *testing.T) {
180 tempDir := t.TempDir()
181
182 // Create real/project/.cheat
183 realProject := filepath.Join(tempDir, "real", "project")
184 if err := os.MkdirAll(realProject, 0755); err != nil {
185 t.Fatalf("failed to create real project dir: %v", err)
186 }
187 if err := os.Mkdir(filepath.Join(realProject, ".cheat"), 0755); err != nil {
188 t.Fatalf("failed to create .cheat dir: %v", err)
189 }
190
191 // Create symlink: linked -> real/project
192 linkedProject := filepath.Join(tempDir, "linked")
193 if err := os.Symlink(realProject, linkedProject); err != nil {
194 t.Fatalf("failed to create symlink: %v", err)
195 }
196
197 // Create sub inside the symlinked path
198 subDir := filepath.Join(linkedProject, "sub")
199 if err := os.Mkdir(subDir, 0755); err != nil {
200 t.Fatalf("failed to create sub dir: %v", err)
201 }
202
203 // Search from linked/sub — should find linked/.cheat
204 // (os.Stat follows symlinks, so linked/.cheat resolves to real/project/.cheat)
205 result := findLocalCheatpath(subDir)
206 expected := filepath.Join(linkedProject, ".cheat")
207 if result != expected {
208 t.Errorf("expected %s, got %s", expected, result)
209 }
210}
211
212// TestFindLocalCheatpathPermissionDenied tests that unreadable ancestor
213// directories are skipped and the walk continues upward.

Callers

nothing calls this directly

Calls 1

findLocalCheatpathFunction · 0.85

Tested by

no test coverage detected