返回 DeepSeek-Reasonix
executable_path_windows_test.go
根目录 / internal / desktoplauncher / executable_path_windows_test.go
1 //go:build windows
2
3 package desktoplauncher
4
5 import (
6 "os"
7 "os/exec"
8 "path/filepath"
9 "testing"
10 )
11
12 func TestResolveInstallRootThroughDirectoryJunction(t *testing.T) {
13 root := t.TempDir()
14 launcher := filepath.Join(root, "reasonix-launcher.exe")
15 if err := os.WriteFile(launcher, []byte("launcher"), 0o755); err != nil {
16 t.Fatal(err)
17 }
18
19 junction := filepath.Join(t.TempDir(), "current")
20 output, err := exec.Command("cmd", "/c", "mklink", "/J", junction, root).CombinedOutput()
21 if err != nil {
22 t.Fatalf("create directory junction: %v: %s", err, output)
23 }
24
25 got, err := resolveInstallRoot(filepath.Join(junction, "reasonix-launcher.exe"))
26 if err != nil {
27 t.Fatal(err)
28 }
29 gotInfo, err := os.Stat(got)
30 if err != nil {
31 t.Fatal(err)
32 }
33 wantInfo, err := os.Stat(root)
34 if err != nil {
35 t.Fatal(err)
36 }
37 if !os.SameFile(gotInfo, wantInfo) {
38 t.Fatalf("resolveInstallRoot() = %q, want %q", got, root)
39 }
40 }
41
42 func TestNormalizeFinalWindowsPath(t *testing.T) {
43 tests := []struct {
44 name string
45 path string
46 want string
47 }{
48 {name: "drive", path: `\\?\C:\Apps\Reasonix`, want: `C:\Apps\Reasonix`},
49 {name: "UNC", path: `\\?\UNC\server\share\Reasonix`, want: `\\server\share\Reasonix`},
50 {name: "volume GUID", path: `\\?\Volume{abc}\Reasonix`, want: `\\?\Volume{abc}\Reasonix`},
51 {name: "ordinary", path: `C:\Apps\Reasonix`, want: `C:\Apps\Reasonix`},
52 }
53 for _, test := range tests {
54 t.Run(test.name, func(t *testing.T) {
55 if got := normalizeFinalWindowsPath(test.path); got != test.want {
56 t.Fatalf("normalizeFinalWindowsPath(%q) = %q, want %q", test.path, got, test.want)
57 }
58 })
59 }
60 }
61
61 lines GO