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