MCPcopy Index your code
hub / github.com/cheat/cheat / TestRunStringReplacements

Function TestRunStringReplacements

internal/installer/run_test.go:173–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

171}
172
173func TestRunStringReplacements(t *testing.T) {
174 // Test that path replacements work correctly
175 configs := `---
176editor: EDITOR_PATH
177pager: PAGER_PATH
178cheatpaths:
179 - name: personal
180 path: PERSONAL_PATH
181 tags: [ personal ]
182 readonly: false
183 - name: work
184 path: WORK_PATH
185 tags: [ work ]
186 readonly: false
187 - name: community
188 path: COMMUNITY_PATH
189 tags: [ community ]
190 readonly: true
191`
192
193 // Create temp directory
194 tempDir, err := os.MkdirTemp("", "cheat-installer-replace-test-*")
195 if err != nil {
196 t.Fatalf("failed to create temp dir: %v", err)
197 }
198 defer os.RemoveAll(tempDir)
199
200 confpath := filepath.Join(tempDir, "conf.yml")
201 confdir := filepath.Dir(confpath)
202
203 // Expected paths
204 expectedPersonal := filepath.Join(confdir, "cheatsheets", "personal")
205
206 // Save original stdin/stdout
207 oldStdin := os.Stdin
208 oldStdout := os.Stdout
209 defer func() {
210 os.Stdin = oldStdin
211 os.Stdout = oldStdout
212 }()
213
214 // Create stdin pipe with "n" answer
215 r, w, _ := os.Pipe()
216 os.Stdin = r
217 go func() {
218 defer w.Close()
219 io.WriteString(w, "n\n")
220 }()
221
222 // Suppress stdout
223 _, wOut, _ := os.Pipe()
224 os.Stdout = wOut
225 defer wOut.Close()
226
227 // Run installer
228 err = Run(configs, confpath)
229 if err != nil {
230 t.Fatalf("Run() failed: %v", err)

Callers

nothing calls this directly

Calls 1

RunFunction · 0.85

Tested by

no test coverage detected