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

Function TestConfigSymlinkResolution

internal/config/config_extended_test.go:52–107  ·  view source on GitHub ↗

TestConfigSymlinkResolution tests symlink resolution

(t *testing.T)

Source from the content-addressed store, hash-verified

50
51// TestConfigSymlinkResolution tests symlink resolution
52func TestConfigSymlinkResolution(t *testing.T) {
53 // Create temp directory structure
54 tempDir, err := os.MkdirTemp("", "cheat-config-test-*")
55 if err != nil {
56 t.Fatalf("failed to create temp dir: %v", err)
57 }
58 defer os.RemoveAll(tempDir)
59
60 // Resolve symlinks in temp dir path (macOS /var -> /private/var)
61 tempDir, err = filepath.EvalSymlinks(tempDir)
62 if err != nil {
63 t.Fatalf("failed to resolve temp dir symlinks: %v", err)
64 }
65
66 // Create target directory
67 targetDir := filepath.Join(tempDir, "target")
68 err = os.Mkdir(targetDir, 0755)
69 if err != nil {
70 t.Fatalf("failed to create target dir: %v", err)
71 }
72
73 // Create symlink
74 linkPath := filepath.Join(tempDir, "link")
75 err = os.Symlink(targetDir, linkPath)
76 if err != nil {
77 t.Fatalf("failed to create symlink: %v", err)
78 }
79
80 // Create config with symlink path
81 configContent := `---
82editor: vim
83cheatpaths:
84 - name: test
85 path: ` + linkPath + `
86 readonly: true
87`
88 configFile := filepath.Join(tempDir, "config.yml")
89 err = os.WriteFile(configFile, []byte(configContent), 0644)
90 if err != nil {
91 t.Fatalf("failed to write config: %v", err)
92 }
93
94 // Load config with symlink resolution
95 conf, err := New(configFile, true)
96 if err != nil {
97 t.Errorf("failed to load config: %v", err)
98 }
99
100 // Verify symlink was resolved
101 if len(conf.Cheatpaths) == 0 {
102 t.Fatal("expected at least one cheatpath, got none")
103 }
104 if conf.Cheatpaths[0].Path != targetDir {
105 t.Errorf("expected symlink to be resolved to %s, got %s", targetDir, conf.Cheatpaths[0].Path)
106 }
107}
108
109// TestConfigBrokenSymlink tests broken symlink handling

Callers

nothing calls this directly

Calls 1

NewFunction · 0.70

Tested by

no test coverage detected