MCPcopy
hub / github.com/cheat/cheat / TestNewEmptyEditorFallback

Function TestNewEmptyEditorFallback

internal/config/new_test.go:59–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestNewEmptyEditorFallback(t *testing.T) {
60 // Skip if required environment variables would interfere
61 oldVisual := os.Getenv("VISUAL")
62 oldEditor := os.Getenv("EDITOR")
63 os.Unsetenv("VISUAL")
64 os.Unsetenv("EDITOR")
65 defer func() {
66 os.Setenv("VISUAL", oldVisual)
67 os.Setenv("EDITOR", oldEditor)
68 }()
69
70 // Create a config with whitespace-only editor
71 tmpDir := t.TempDir()
72 configPath := filepath.Join(tmpDir, "config.yml")
73
74 configContent := `---
75editor: " "
76pager: less
77style: monokai
78formatter: terminal
79cheatpaths:
80 - name: personal
81 path: ~/cheat
82 tags: []
83 readonly: false
84`
85
86 if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
87 t.Fatalf("failed to write test config: %v", err)
88 }
89
90 // Load the config
91 conf, err := New(configPath, false)
92 if err != nil {
93 // It's OK if this fails due to no editor being found
94 // The important thing is it doesn't panic
95 return
96 }
97
98 // If it succeeded, editor should not be empty (fallback was used)
99 if conf.Editor == "" {
100 t.Error("editor should not be empty after fallback")
101 }
102}
103
104func TestNewWhitespaceOnlyPager(t *testing.T) {
105 // Create a config with whitespace-only pager

Callers

nothing calls this directly

Calls 1

NewFunction · 0.70

Tested by

no test coverage detected