@@ -34,27 +34,22 @@ var (
34
34
35
35
type TestDevices map [string ]string
36
36
37
- func (d TestDevices ) Loops () ( Devices , error ) {
37
+ func (d TestDevices ) Loops () Devices {
38
38
mgr := lsblkDeviceManager {
39
39
executer : executerFunc (run ),
40
40
}
41
- for loopTempPath , loop := range d {
42
- size , err := FilesUsage (loopTempPath )
43
- if err != nil {
44
- return Devices {}, err
45
- }
41
+ for _ , loop := range d {
46
42
mgr .cache = append (mgr .cache , DeviceInfo {
47
43
Path : loop ,
48
44
Rota : false ,
49
- Size : size ,
50
45
})
51
46
}
52
47
53
48
devices , err := mgr .Devices (context .Background ())
54
49
if err != nil {
55
- return Devices {}, err
50
+ panic ( err )
56
51
}
57
- return devices , nil
52
+ return devices
58
53
}
59
54
60
55
func (d TestDevices ) Destroy () {
@@ -178,13 +173,20 @@ func basePoolTest(t *testing.T, pool Pool) {
178
173
})
179
174
180
175
t .Run ("test limit subvolume" , func (t * testing.T ) {
176
+ usage , err := volume .Usage ()
177
+ require .NoError (t , err )
178
+
179
+ // Note: an empty subvolume has an overhead of 16384 bytes
180
+ assert .Equal (t , Usage {Used : 16384 }, usage )
181
+
181
182
err = volume .Limit (50 * 1024 * 1024 )
182
183
require .NoError (t , err )
183
184
184
- usage , err : = volume .Usage ()
185
+ usage , err = volume .Usage ()
185
186
require .NoError (t , err )
186
187
187
- assert .Equal (t , Usage {Used : 50 * 1024 * 1024 , Size : 50 * 1024 * 1024 }, usage )
188
+ // Note: an empty subvolume has an overhead of 16384 bytes
189
+ assert .Equal (t , Usage {Used : 16384 , Size : 50 * 1024 * 1024 }, usage )
188
190
})
189
191
190
192
t .Run ("test remove subvolume" , func (t * testing.T ) {
@@ -207,13 +209,9 @@ func TestBtrfsSingleCI(t *testing.T) {
207
209
require .NoError (t , err , "failed to initialize devices" )
208
210
209
211
defer devices .Destroy ()
210
- loops , err := devices .Loops ()
211
- require .NoError (t , err )
212
+ loops := devices .Loops ()
212
213
213
214
for _ , dev := range loops {
214
- dev .mgr = & lsblkDeviceManager {
215
- executer : executerFunc (run ),
216
- }
217
215
pool , err := NewBtrfsPool (dev )
218
216
require .NoError (t , err )
219
217
basePoolTest (t , pool )
@@ -229,11 +227,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
229
227
require .NoError (t , err , "failed to initialize devices" )
230
228
defer devices .Destroy ()
231
229
232
- loops , err := devices .Loops ()
233
- require .NoError (t , err )
234
- loops [0 ].mgr = & lsblkDeviceManager {
235
- executer : executerFunc (run ),
236
- }
230
+ loops := devices .Loops ()
237
231
pool , err := NewBtrfsPool (loops [0 ])
238
232
require .NoError (t , err )
239
233
@@ -255,8 +249,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
255
249
256
250
qgroups , err := btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
257
251
require .NoError (t , err )
258
- // it start with a volume of size 16384 by default
259
- assert .Equal (t , 2 , len (qgroups ))
252
+ assert .Equal (t , 1 , len (qgroups ))
260
253
t .Logf ("qgroups before delete: %v" , qgroups )
261
254
262
255
_ , ok = qgroups [fmt .Sprintf ("0/%d" , btrfsVol .id )]
@@ -269,5 +262,5 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
269
262
require .NoError (t , err )
270
263
271
264
t .Logf ("remaining qgroups: %+v" , qgroups )
272
- assert .Equal (t , 1 , len (qgroups ), "qgroups should have been deleted with the subvolume" )
273
- }
265
+ assert .Equal (t , 0 , len (qgroups ), "qgroups should have been deleted with the subvolume" )
266
+ }
0 commit comments