返回 DeepSeek-Reasonix
path_access_windows_test.go
根目录 / internal / config / path_access_windows_test.go
1 //go:build windows
2
3 package config
4
5 import (
6 "os"
7 "os/exec"
8 "path/filepath"
9 "testing"
10 )
11
12 func TestConfigJunctionAccessAndLockNames(t *testing.T) {
13 root := t.TempDir()
14 target, alias := filepath.Join(root, "target"), filepath.Join(root, "alias")
15 if err := os.Mkdir(target, 0o700); err != nil {
16 t.Fatal(err)
17 }
18 if out, err := exec.Command("cmd", "/c", "mklink", "/J", alias, target).CombinedOutput(); err != nil {
19 t.Fatalf("create junction: %v: %s", err, out)
20 }
21 for _, name := range []string{"config.toml", ".env", "reasonix.toml"} {
22 for _, existing := range []bool{false, true} {
23 physical := filepath.Join(target, name)
24 if existing {
25 if err := os.WriteFile(physical, []byte("# keep\n"), 0o600); err != nil {
26 t.Fatal(err)
27 }
28 }
29 for _, userConfig := range []bool{false, true} {
30 left, err := resolveConfigAccessPathUnpinned(filepath.Join(alias, name), userConfig)
31 right, rightErr := resolveConfigAccessPathUnpinned(physical, userConfig)
32 if err != nil || rightErr != nil || left != right {
33 t.Fatalf("config alias resolution: %q / %q, %v / %v", left, right, err, rightErr)
34 }
35 // Deriving registry names must not create or acquire real user locks.
36 leftLock, err := configFileEditLockPathResolved(left)
37 rightLock, rightErr := configFileEditLockPathResolved(right)
38 if err != nil || rightErr != nil || leftLock != rightLock {
39 t.Fatalf("config alias lock names diverge: %v / %v", err, rightErr)
40 }
41 }
42 }
43 }
44 }
45
45 lines GO