-
Notifications
You must be signed in to change notification settings - Fork 58
/
os_unix_test.go
94 lines (77 loc) · 1.66 KB
/
os_unix_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
// +build linux darwin
package kgo
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestOS_Unix_NotWindows(t *testing.T) {
res := KOS.IsWindows()
assert.False(t, res)
}
func TestOS_Unix_HomeDir(t *testing.T) {
res, err := KOS.HomeDir()
assert.Nil(t, err)
assert.NotEmpty(t, res)
}
func BenchmarkOS_Unix_HomeDir(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = KOS.HomeDir()
}
}
func TestOS_Unix_Exec(t *testing.T) {
var ret int
var res []byte
var err []byte
ret, res, err = KOS.Exec(tesCommand01)
assert.Equal(t, ret, 0)
assert.NotEmpty(t, res)
assert.Empty(t, err)
//错误的命令
ret, res, err = KOS.Exec(tesCommand02)
assert.Equal(t, ret, 1)
assert.Empty(t, res)
assert.NotEmpty(t, err)
}
func BenchmarkOS_Unix_Exec(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = KOS.Exec(tesCommand01)
}
}
func TestOS_Unix_System(t *testing.T) {
var ret int
var res []byte
var err []byte
ret, res, err = KOS.System(tesCommand01)
assert.Equal(t, ret, 0)
assert.Empty(t, err)
assert.NotEmpty(t, res)
//错误的命令
ret, res, err = KOS.System(tesCommand02)
assert.Equal(t, ret, 1)
assert.NotEmpty(t, err)
assert.Empty(t, res)
}
func BenchmarkOS_Unix_System(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = KOS.System(tesCommand01)
}
}
func TestOS_Unix_IsProcessExists(t *testing.T) {
var res bool
pid := os.Getpid()
res = KOS.IsProcessExists(pid)
assert.True(t, res)
res = KOS.IsProcessExists(-1)
assert.False(t, res)
}
func BenchmarkOS_Unix_IsProcessExists(b *testing.B) {
b.ResetTimer()
pid := os.Getpid()
for i := 0; i < b.N; i++ {
KOS.IsProcessExists(pid)
}
}