forked from ycrash/yc-360-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm3_test.go
More file actions
92 lines (80 loc) · 2.31 KB
/
m3_test.go
File metadata and controls
92 lines (80 loc) · 2.31 KB
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
package shell
import (
"fmt"
"strconv"
"testing"
"shell/config"
)
func TestGetProcessIds(t *testing.T) {
noGC, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass"})
if err != nil {
t.Fatal(err)
}
defer noGC.KillAndWait()
ids, err := GetProcessIds(config.ProcessTokens{"MyClass$appNameTest"}, nil)
if err != nil {
t.Fatal(err)
}
t.Log(ids)
if len(ids) < 1 {
t.Fatal("can not get pid of java process")
}
}
func TestParseJsonResp(t *testing.T) {
ids, tags, _, err := ParseJsonResp([]byte(`{"actions":[ "capture 12321", "capture 2341", "capture 45321"] }`))
if err != nil {
t.Fatal(err)
}
t.Log(ids, tags)
ids, tags, _, err = ParseJsonResp([]byte(`{"actions":["capture 2116"]}`))
if err != nil {
t.Fatal(err)
}
t.Log(ids, tags)
ids, tags, _, err = ParseJsonResp([]byte(`{ "actions": [] }`))
if err != nil {
t.Fatal(err)
}
t.Log(ids, tags)
}
func TestGetProcessIdsByPid(t *testing.T) {
noGC, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass"})
if err != nil {
t.Fatal(err)
}
defer noGC.KillAndWait()
fake, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass", "-wait", strconv.Itoa(noGC.GetPid())})
if err != nil {
t.Fatal(err)
}
defer fake.KillAndWait()
ids, err := GetProcessIds(config.ProcessTokens{config.ProcessToken(fmt.Sprintf("%d$appNameTest", noGC.GetPid()))}, nil)
if err != nil {
t.Fatal(err)
}
t.Log(ids)
if name, ok := ids[noGC.GetPid()]; !ok || name != "appNameTest" {
t.Fatal("can not get pid of java process")
}
}
func TestGetProcessIdsWithExclude(t *testing.T) {
noGC, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass"})
if err != nil {
t.Fatal(err)
}
defer noGC.KillAndWait()
fake, err := CommandStartInBackground(Command{"java", "-cp", "./capture/testdata/", "MyClass", "-wait", strconv.Itoa(noGC.GetPid())})
if err != nil {
t.Fatal(err)
}
defer fake.KillAndWait()
ids, err := GetProcessIds(config.ProcessTokens{"MyClass$appNameTest"}, config.ProcessTokens{"wait"})
//ids, err := GetProcessIds(config.ProcessTokens{"MyClass$appNameTest"}, nil)
if err != nil {
t.Fatal(err)
}
t.Log(ids, noGC.GetPid())
if name, ok := ids[noGC.GetPid()]; !ok || name != "appNameTest" {
t.Fatal("can not get pid of java process")
}
}