返回 DeepSeek-Reasonix
marker_test.go
根目录 / internal / winaclresidue / marker_test.go
1 package winaclresidue
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 func TestMarkerOwnerPIDParsesRetiredBackendNames(t *testing.T) {
10 for name, want := range map[string]string{
11 "1234.txt": "1234",
12 "1234-deadbeef.txt": "1234",
13 "1234-1700000000-2.txt": "1234",
14 "1234": "",
15 "-abc.txt": "",
16 "notapid-1.txt": "",
17 "99999999999.txt": "",
18 } {
19 got, ok := markerOwnerPID(name)
20 if (want == "") == ok || got != want {
21 t.Fatalf("markerOwnerPID(%q) = %q,%v want %q", name, got, ok, want)
22 }
23 }
24 }
25
26 func TestReadResidueMarkerSkipsCorruptLines(t *testing.T) {
27 marker := filepath.Join(t.TempDir(), "42.txt")
28 body := "deny\tC:\\Users\\me\\.env\r\n" +
29 "grant\tC:\\Tools\\with space\\bin\n" +
30 "deny C:\\no-tab\n" +
31 "unknown\tC:\\kind\n" +
32 "deny\t\n" +
33 "\n"
34 if err := os.WriteFile(marker, []byte(body), 0o600); err != nil {
35 t.Fatal(err)
36 }
37 got := readResidueMarker(marker)
38 if len(got) != 2 || got[0] != (residueEntry{residueDeny, `C:\Users\me\.env`}) || got[1] != (residueEntry{residueGrant, `C:\Tools\with space\bin`}) {
39 t.Fatalf("readResidueMarker = %+v", got)
40 }
41 if got := readResidueMarker(filepath.Join(t.TempDir(), "missing.txt")); got != nil {
42 t.Fatalf("missing marker parsed as %+v", got)
43 }
44 }
45
46 func TestIsWindowsSystemRootUsesEnvironmentRoots(t *testing.T) {
47 t.Setenv("SystemRoot", `C:\Windows`)
48 t.Setenv("ProgramFiles", `C:\Program Files`)
49 for path, want := range map[string]bool{
50 `C:\Windows\System32`: true,
51 `c:\windows`: true,
52 `C:\Program Files\Git\bin`: true,
53 `C:\WindowsOld\System32`: false,
54 `C:\Users\me\project`: false,
55 `C:\Program FilesX\tool`: false,
56 } {
57 if got := isWindowsSystemRoot(path); got != want {
58 t.Fatalf("isWindowsSystemRoot(%q) = %v, want %v", path, got, want)
59 }
60 }
61 }
62
63 func TestDedupeSIDStringsDropsEmptyAndRepeats(t *testing.T) {
64 got := dedupeSIDStrings([]string{"S-1-15-2-1", "", "S-1-15-2-2", "S-1-15-2-1", "S-1-5-21-1"})
65 if len(got) != 3 || got[0] != "S-1-15-2-1" || got[1] != "S-1-15-2-2" || got[2] != "S-1-5-21-1" {
66 t.Fatalf("dedupeSIDStrings = %v", got)
67 }
68 }
69
69 lines GO