-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_test.go
46 lines (42 loc) · 965 Bytes
/
cpu_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
package stats
import (
"context"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestReadCPUStats(t *testing.T) {
ctx := context.Background()
stat, err := ReadCPUStats(ctx, WithRootDir("testdata"))
if err != nil {
t.Fatal(err)
}
const (
userTime = (10 + 2380 + 0 + 390) * time.Millisecond
sysTime = (20 + 29690 + 0 + 310) * time.Millisecond
)
want := &CPUStats{
User: userTime,
Sys: sysTime,
Idle: (1412961713341830*2 - userTime - sysTime),
}
if !cmp.Equal(want, stat) {
t.Errorf("ReadCPUTime: %v", cmp.Diff(want, stat))
}
}
func TestReadTime(t *testing.T) {
ctx := context.Background()
stat, err := ReadTime(ctx, WithRootDir("testdata"))
if err != nil {
t.Fatal(err)
}
want := &Time{
Unix: 1633882064 * time.Second,
UnixNano: 1633882064926300833 * time.Nanosecond,
Ticks: 2825920097745864,
Freq: 1999997644,
}
if !cmp.Equal(want, stat) {
t.Errorf("ReadCPUTime: %v", cmp.Diff(want, stat))
}
}