-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunchctl_test.go
96 lines (77 loc) · 1.85 KB
/
launchctl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package launchctlutil
import (
"errors"
"strconv"
"testing"
)
func TestCurrentStatus(t *testing.T) {
details, err := CurrentStatus("com.apple.Finder")
if err != nil {
t.Fatal(err.Error())
}
if details.Status != Running {
t.Fatalf("status should be running - got %s", details.Status)
}
if details.Pid == 0 {
t.Fatal("PID should be greater than 0")
}
}
func TestCurrentStatusNotRunning(t *testing.T) {
details, err := CurrentStatus("com.apple.DiagnosticReportCleanup.plist")
if err != nil {
t.Fatal(err.Error())
}
if details.Status == Running {
t.Fatalf("status should be not running - got %s", details.Status)
}
if details.Pid > 0 {
t.Fatal("PID should not be greater than 0")
}
}
func TestGetLastExitStatus(t *testing.T) {
exp := 15
l := `"LastExitStatus" = ` + strconv.Itoa(exp) + ";"
exit, err := getLastExitStatus(l)
if err != nil {
t.Fatal(err.Error())
}
if exit != exp {
t.Fatalf("exit status should be %d - got %d", exp, exit)
}
}
func TestGetPid(t *testing.T) {
exp := 33385
l := `"PID" = ` + strconv.Itoa(exp) + ";"
pid, err := getPid(l)
if err != nil {
t.Fatal(err.Error())
}
if pid != exp {
t.Fatalf("PID should be %d - got %d", exp, pid)
}
}
func TestCurrentStatusNotInstalled(t *testing.T) {
details, err := CurrentStatus("com.apple.nevergoingtoexisttrash")
if err != nil {
t.Fatal(err.Error())
}
if details.Status != NotInstalled {
t.Fatalf("status should be running - got %s", details.Status)
}
}
func TestStatusDetails_GotLastExitStatus(t *testing.T) {
details := StatusDetails{
LastExitStatusErr: errors.New("broke"),
}
if details.GotLastExitStatus() {
t.Fatal("got last exit status when there was an error")
}
}
func TestStatusDetails_GotPid(t *testing.T) {
details := StatusDetails{
PidErr: errors.New("broke"),
}
if details.GotPid() {
t.Fatal("got a PID when there was an error")
}
}