MCPcopy
hub / github.com/cheat/cheat / TestFindLocalCheatpathNearestWins

Function TestFindLocalCheatpathNearestWins

internal/config/config_test.go:85–117  ·  view source on GitHub ↗

TestFindLocalCheatpathNearestWins tests that the closest .cheat is returned

(t *testing.T)

Source from the content-addressed store, hash-verified

83
84// TestFindLocalCheatpathNearestWins tests that the closest .cheat is returned
85func 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
120func TestFindLocalCheatpathNotFound(t *testing.T) {

Callers

nothing calls this directly

Calls 1

findLocalCheatpathFunction · 0.85

Tested by

no test coverage detected