@@ -79,20 +79,70 @@ func TestStatter(t *testing.T) {
79
79
80
80
t .Run ("CGroupV1" , func (t * testing.T ) {
81
81
t .Parallel ()
82
- t .Skip ("not implemented" )
83
82
84
83
t .Run ("Limit" , func (t * testing.T ) {
85
84
t .Parallel ()
85
+ fs := initFS (t , fsContainerCgroupV1 )
86
+ s , err := New (WithFS (fs ))
87
+ require .NoError (t , err )
88
+
89
+ t .Run ("ContainerCPU" , func (t * testing.T ) {
90
+ t .Parallel ()
91
+ cpu , err := s .ContainerCPU ()
92
+ require .NoError (t , err )
93
+ require .NotNil (t , cpu )
94
+ // This value does not change in between tests so it is zero.
95
+ assert .Zero (t , cpu .Used )
96
+ require .NotNil (t , cpu .Total )
97
+ assert .Equal (t , 2.5 , * cpu .Total )
98
+ assert .Equal (t , "cores" , cpu .Unit )
99
+ })
100
+
101
+ t .Run ("ContainerMemory" , func (t * testing.T ) {
102
+ t .Parallel ()
103
+ mem , err := s .ContainerMemory ()
104
+ require .NoError (t , err )
105
+ require .NotNil (t , mem )
106
+ assert .NotZero (t , mem .Used )
107
+ assert .NotZero (t , mem .Total )
108
+ assert .Equal (t , "GB" , mem .Unit )
109
+ })
86
110
})
87
111
88
112
t .Run ("NoLimit" , func (t * testing.T ) {
89
113
t .Parallel ()
114
+ fs := initFS (t , fsContainerCgroupV1NoLimit )
115
+ s , err := New (WithFS (fs ))
116
+ require .NoError (t , err )
117
+
118
+ t .Run ("ContainerCPU" , func (t * testing.T ) {
119
+ t .Parallel ()
120
+ cpu , err := s .ContainerCPU ()
121
+ require .NoError (t , err )
122
+ require .NotNil (t , cpu )
123
+ // This value does not change in between tests so it is zero.
124
+ assert .Zero (t , cpu .Used )
125
+ require .NotNil (t , cpu .Total )
126
+ assert .Equal (t , 2.5 , * cpu .Total )
127
+ assert .Equal (t , "cores" , cpu .Unit )
128
+ })
129
+
130
+ t .Run ("ContainerMemory" , func (t * testing.T ) {
131
+ t .Parallel ()
132
+ mem , err := s .ContainerMemory ()
133
+ require .NoError (t , err )
134
+ require .NotNil (t , mem )
135
+ assert .NotZero (t , mem .Used )
136
+ assert .NotZero (t , mem .Total )
137
+ assert .Equal (t , "GB" , mem .Unit )
138
+ })
90
139
})
91
140
})
92
141
93
142
t .Run ("CGroupV2" , func (t * testing.T ) {
94
143
t .Parallel ()
95
144
t .Run ("Limit" , func (t * testing.T ) {
145
+ t .Parallel ()
96
146
fs := initFS (t , fsContainerCgroupV2 )
97
147
s , err := New (WithFS (fs ))
98
148
require .NoError (t , err )
@@ -102,10 +152,9 @@ func TestStatter(t *testing.T) {
102
152
t .Parallel ()
103
153
cpu , err := s .ContainerCPU ()
104
154
require .NoError (t , err )
105
- assert .NotNil (t , cpu )
155
+ require .NotNil (t , cpu )
106
156
// This value does not change in between tests so it is zero.
107
157
assert .Zero (t , cpu .Used )
108
- // Eve
109
158
require .NotNil (t , cpu .Total )
110
159
assert .Equal (t , 2.5 , * cpu .Total )
111
160
assert .Equal (t , "cores" , cpu .Unit )
@@ -115,14 +164,15 @@ func TestStatter(t *testing.T) {
115
164
t .Parallel ()
116
165
mem , err := s .ContainerMemory ()
117
166
require .NoError (t , err )
118
- assert .NotNil (t , mem )
167
+ require .NotNil (t , mem )
119
168
assert .NotZero (t , mem .Used )
120
169
assert .NotZero (t , mem .Total )
121
170
assert .Equal (t , "GB" , mem .Unit )
122
171
})
123
172
})
124
173
125
174
t .Run ("NoLimit" , func (t * testing.T ) {
175
+ t .Parallel ()
126
176
fs := initFS (t , fsContainerCgroupV2 )
127
177
s , err := New (WithFS (fs ), func (s * Statter ) {
128
178
s .nproc = 2
@@ -134,10 +184,9 @@ func TestStatter(t *testing.T) {
134
184
t .Parallel ()
135
185
cpu , err := s .ContainerCPU ()
136
186
require .NoError (t , err )
137
- assert .NotNil (t , cpu )
187
+ require .NotNil (t , cpu )
138
188
// This value does not change in between tests so it is zero.
139
189
assert .Zero (t , cpu .Used )
140
- // Eve
141
190
require .NotNil (t , cpu .Total )
142
191
assert .Equal (t , 2.5 , * cpu .Total )
143
192
assert .Equal (t , "cores" , cpu .Unit )
@@ -147,7 +196,7 @@ func TestStatter(t *testing.T) {
147
196
t .Parallel ()
148
197
mem , err := s .ContainerMemory ()
149
198
require .NoError (t , err )
150
- assert .NotNil (t , mem )
199
+ require .NotNil (t , mem )
151
200
assert .NotZero (t , mem .Used )
152
201
assert .NotZero (t , mem .Total )
153
202
assert .Equal (t , "GB" , mem .Unit )
@@ -231,6 +280,20 @@ proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
231
280
procOneCgroup : "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f" ,
232
281
procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
233
282
proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
283
+ cgroupV1CPUAcctUsage : "162237573" ,
284
+ cgroupV1CFSQuotaUs : "250000" ,
285
+ cgroupV1MemoryMaxUsageBytes : "7782400" ,
286
+ cgroupV1MemoryUsageBytes : "total_rss 143360" ,
287
+ }
288
+ fsContainerCgroupV1NoLimit = map [string ]string {
289
+ procOneCgroup : "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f" ,
290
+ procMounts : `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
291
+ proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0` ,
292
+ cgroupV1CPUAcctUsage : "162237573" ,
293
+ cgroupV1CFSQuotaUs : "-1" ,
294
+ cgroupV1MemoryMaxUsageBytes : "7782400" ,
295
+ cgroupV1MemoryUsageBytes : "total_rss 143360" ,
296
+ cgroupV1MemoryStat : "total_inactive_file 3891200" ,
234
297
}
235
298
fsContainerCgroupV2NoLimit = map [string ]string {
236
299
procOneCgroup : "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f" ,
0 commit comments