...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package procfs
15
16 import (
17 "reflect"
18 "testing"
19 )
20
21 func TestParseCgroupSummaryString(t *testing.T) {
22 tests := []struct {
23 name string
24 s string
25 shouldErr bool
26 CgroupSummary *CgroupSummary
27 }{
28 {
29 name: "cpuset simple line",
30 s: "cpuset 7 148 1",
31 shouldErr: false,
32 CgroupSummary: &CgroupSummary{
33 SubsysName: "cpuset",
34 Hierarchy: 7,
35 Cgroups: 148,
36 Enabled: 1,
37 },
38 },
39 {
40 name: "memory cgroup number mis format",
41 s: "memory 9 ## 1",
42 shouldErr: true,
43 CgroupSummary: nil,
44 },
45 }
46
47 for i, test := range tests {
48 t.Logf("[%02d] test %q", i, test.name)
49
50 CgroupSummary, err := parseCgroupSummaryString(test.s)
51
52 if test.shouldErr && err == nil {
53 t.Errorf("%s: expected an error, but none occurred", test.name)
54 }
55 if !test.shouldErr && err != nil {
56 t.Errorf("%s: unexpected error: %v", test.name, err)
57 }
58
59 if want, have := test.CgroupSummary, CgroupSummary; !reflect.DeepEqual(want, have) {
60 t.Errorf("cgroup:\nwant:\n%+v\nhave:\n%+v", want, have)
61 }
62 }
63
64 }
65
View as plain text