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

Function TestFirstRunIntegration

test/integration/first_run_integration_test.go:15–180  ·  view source on GitHub ↗

TestFirstRunIntegration exercises the end-to-end first-run experience: no config exists, the binary creates one, and subsequent runs succeed. This is the regression test for issues #721, #771, and #730.

(t *testing.T)

Source from the content-addressed store, hash-verified

13// no config exists, the binary creates one, and subsequent runs succeed.
14// This is the regression test for issues #721, #771, and #730.
15func TestFirstRunIntegration(t *testing.T) {
16 // Build the cheat binary
17 binName := "cheat_test"
18 if runtime.GOOS == "windows" {
19 binName += ".exe"
20 }
21 binPath := filepath.Join(t.TempDir(), binName)
22 build := exec.Command("go", "build", "-o", binPath, "./cmd/cheat")
23 build.Dir = repoRoot(t)
24 if output, err := build.CombinedOutput(); err != nil {
25 t.Fatalf("failed to build cheat: %v\nOutput: %s", err, output)
26 }
27
28 t.Run("init comments out community", func(t *testing.T) {
29 testHome := t.TempDir()
30 env := firstRunEnv(testHome)
31
32 cmd := exec.Command(binPath, "--init")
33 cmd.Env = env
34 output, err := cmd.CombinedOutput()
35 if err != nil {
36 t.Fatalf("--init failed: %v\nOutput: %s", err, output)
37 }
38 outStr := string(output)
39
40 // No placeholder strings should survive (regression for #721)
41 assertNoPlaceholders(t, outStr)
42
43 // Community cheatpath should be commented out
44 assertCommunityCommentedOut(t, outStr)
45
46 // Personal and work cheatpaths should be active (uncommented)
47 assertCheatpathActive(t, outStr, "personal")
48 assertCheatpathActive(t, outStr, "work")
49
50 // Should include clone instructions
51 if !strings.Contains(outStr, "git clone") {
52 t.Error("expected git clone instructions in --init output")
53 }
54
55 // Save the config and verify it loads without errors.
56 // --init only outputs config, it doesn't create directories,
57 // so we need to create the cheatpath dirs the config references.
58 confpath := filepath.Join(testHome, "conf.yml")
59 if err := os.WriteFile(confpath, output, 0644); err != nil {
60 t.Fatalf("failed to write config: %v", err)
61 }
62
63 // Determine the confdir that --init used (same logic as cmd_init.go)
64 initConfpaths := firstRunConfpaths(testHome)
65 initConfdir := filepath.Dir(initConfpaths[0])
66 for _, name := range []string{"personal", "work"} {
67 dir := filepath.Join(initConfdir, "cheatsheets", name)
68 if err := os.MkdirAll(dir, 0755); err != nil {
69 t.Fatalf("failed to create %s dir: %v", name, err)
70 }
71 }
72

Callers

nothing calls this directly

Calls 8

repoRootFunction · 0.85
firstRunEnvFunction · 0.85
assertNoPlaceholdersFunction · 0.85
assertCheatpathActiveFunction · 0.85
firstRunConfpathsFunction · 0.85
firstRunConfigExistsFunction · 0.85
parseCreatedConfPathFunction · 0.85

Tested by

no test coverage detected