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

Function TestRun

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

Source from the content-addressed store, hash-verified

10)
11
12func TestRun(t *testing.T) {
13 // Create a temporary directory for testing
14 tempDir, err := os.MkdirTemp("", "cheat-installer-test-*")
15 if err != nil {
16 t.Fatalf("failed to create temp dir: %v", err)
17 }
18 defer os.RemoveAll(tempDir)
19
20 // Save original stdin/stdout
21 oldStdin := os.Stdin
22 oldStdout := os.Stdout
23 defer func() {
24 os.Stdin = oldStdin
25 os.Stdout = oldStdout
26 }()
27
28 tests := []struct {
29 name string
30 configs string
31 confpath string
32 userInput string
33 wantErr bool
34 wantInErr string
35 checkFiles []string
36 dontWantFiles []string
37 }{
38 {
39 name: "user declines community cheatsheets",
40 configs: `---
41editor: EDITOR_PATH
42pager: PAGER_PATH
43cheatpaths:
44 - name: community
45 path: COMMUNITY_PATH
46 tags: [ community ]
47 readonly: true
48 - name: personal
49 path: PERSONAL_PATH
50 tags: [ personal ]
51 readonly: false
52`,
53 confpath: filepath.Join(tempDir, "conf1", "conf.yml"),
54 userInput: "n\n",
55 wantErr: false,
56 checkFiles: []string{"conf1/conf.yml", "conf1/cheatsheets/personal", "conf1/cheatsheets/work"},
57 dontWantFiles: []string{"conf1/cheatsheets/community"},
58 },
59 {
60 name: "user accepts but clone fails",
61 configs: `---
62cheatpaths:
63 - name: community
64 path: COMMUNITY_PATH
65`,
66 confpath: filepath.Join(tempDir, "conf2", "conf.yml"),
67 userInput: "y\n",
68 wantErr: true,
69 wantInErr: "failed to clone cheatsheets",

Callers

nothing calls this directly

Calls 1

RunFunction · 0.85

Tested by

no test coverage detected