返回 DeepSeek-Reasonix
process_disappearance_windows_test.go
根目录 / internal / desktopinstance / process_disappearance_windows_test.go
1 //go:build windows
2
3 package desktopinstance
4
5 import (
6 "errors"
7 "testing"
8 "time"
9
10 "golang.org/x/sys/windows"
11 )
12
13 func TestAccessDeniedCandidateRequiresFreshProcessEvidence(t *testing.T) {
14 for _, tc := range []struct {
15 name string
16 entries []windows.ProcessEntry32
17 err error
18 blocked bool
19 }{
20 {"exited since snapshot", nil, nil, false},
21 {"still present", []windows.ProcessEntry32{{ProcessID: 42}}, nil, true},
22 {"cannot refresh snapshot", nil, errors.New("snapshot denied"), true},
23 } {
24 t.Run(tc.name, func(t *testing.T) {
25 err := deniedCandidate(42, func() ([]windows.ProcessEntry32, error) { return tc.entries, tc.err })
26 if (err != nil) != tc.blocked {
27 t.Fatalf("blocked=%t, error=%v", tc.blocked, err)
28 }
29 })
30 }
31 }
32
33 func TestStartupInspectionWaitsForCompleteSnapshotWithinDeadline(t *testing.T) {
34 for _, tc := range []struct {
35 name string
36 code Code
37 clears bool
38 wantCalls int
39 }{
40 {"transient owner", UnknownOwner, true, 2},
41 {"persistent owner", UnknownOwner, false, 3},
42 {"other installation", OtherInstallation, false, 1},
43 } {
44 t.Run(tc.name, func(t *testing.T) {
45 calls := 0
46 left := 400 * time.Millisecond
47 _, err := waitForInspectable(func() ([]*process, error) {
48 calls++
49 if tc.clears && calls > 1 {
50 return nil, nil
51 }
52 return nil, outcome(tc.code, "unverified")
53 }, func() time.Duration { return left }, func(d time.Duration) { left -= d })
54 if calls != tc.wantCalls || (err == nil) != tc.clears {
55 t.Fatalf("calls=%d, error=%v", calls, err)
56 }
57 })
58 }
59 }
60
60 lines GO