-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathos_darwin_test.go
165 lines (138 loc) · 2.96 KB
/
os_darwin_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//go:build darwin
// +build darwin
package kgo
import (
"fmt"
"github.com/stretchr/testify/assert"
"io"
"net"
"testing"
"time"
)
func TestOS_Darwin_IsMac(t *testing.T) {
res := KOS.IsMac()
assert.True(t, res)
}
func BenchmarkOS_Darwin_IsMac(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.IsMac()
}
}
func TestOS_Darwin_MemoryUsage(t *testing.T) {
var used, free, total uint64
used, free, total = KOS.MemoryUsage(true)
assert.Greater(t, int(used), 1)
assert.Greater(t, int(free), 1)
assert.Greater(t, int(total), 1)
}
func BenchmarkOS_Darwin_MemoryUsage(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.MemoryUsage(true)
}
}
func TestOS_Darwin_DiskUsage(t *testing.T) {
var used, free, total uint64
used, free, total = KOS.DiskUsage("/")
assert.Greater(t, int(used), 1)
assert.Greater(t, int(free), 1)
assert.Greater(t, int(total), 1)
}
func BenchmarkOS_Darwin_DiskUsage(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = KOS.DiskUsage("/")
}
}
func TestOS_Darwin_Uptime(t *testing.T) {
res, err := KOS.Uptime()
assert.Greater(t, int(res), 1)
assert.Nil(t, err)
}
func BenchmarkOS_Darwin_Uptime(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = KOS.Uptime()
}
}
func TestOS_Darwin_GetBiosInfo(t *testing.T) {
res := KOS.GetBiosInfo()
assert.Empty(t, res.Version)
}
func BenchmarkOS_Darwin_GetBiosInfo(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.GetBiosInfo()
}
}
func TestOS_Darwin_GetBoardInfo(t *testing.T) {
res := KOS.GetBoardInfo()
assert.NotNil(t, res)
assert.NotEmpty(t, res.Name)
assert.NotEmpty(t, res.Version)
assert.NotEmpty(t, res.Serial)
}
func BenchmarkOS_Darwin_GetBoardInfo(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.GetBoardInfo()
}
}
func TestOS_Darwin_GetCpuInfo(t *testing.T) {
res := KOS.GetCpuInfo()
KDbug.DumpPrint(res)
assert.NotNil(t, res)
assert.NotEmpty(t, res.Model)
assert.NotEmpty(t, res.Threads)
}
func BenchmarkOS_Darwin_GetCpuInfo(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.GetCpuInfo()
}
}
func TestOS_Darwin_GetPidByPort(t *testing.T) {
time.AfterFunc(time.Millisecond*250, func() {
res := KOS.GetPidByPort(8899)
assert.Greater(t, res, 1)
KOS.GetPidByPort(80)
})
//发送消息
time.AfterFunc(time.Millisecond*500, func() {
conn, err := net.Dial("tcp", ":8899")
assert.Nil(t, err)
defer func() {
_ = conn.Close()
}()
_, err = fmt.Fprintf(conn, helloEng)
assert.Nil(t, err)
})
//开启监听端口
l, err := net.Listen("tcp", ":8899")
assert.Nil(t, err)
defer func() {
_ = l.Close()
}()
for {
conn, err := l.Accept()
if err != nil {
return
}
defer func() {
_ = conn.Close()
}()
//接收
buf, err := io.ReadAll(conn)
assert.Nil(t, err)
msg := string(buf[:])
assert.Equal(t, msg, helloEng)
return
}
}
func BenchmarkOS_Darwin_GetPidByPort(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
KOS.GetPidByPort(8899)
}
}