@@ -34,22 +34,27 @@ var (
3434
3535type TestDevices map [string ]string
3636
37- func (d TestDevices ) Loops () Devices {
37+ func (d TestDevices ) Loops () ( Devices , error ) {
3838 mgr := lsblkDeviceManager {
3939 executer : executerFunc (run ),
4040 }
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+ }
4246 mgr .cache = append (mgr .cache , DeviceInfo {
4347 Path : loop ,
4448 Rota : false ,
49+ Size : size ,
4550 })
4651 }
4752
4853 devices , err := mgr .Devices (context .Background ())
4954 if err != nil {
50- panic ( err )
55+ return Devices {}, err
5156 }
52- return devices
57+ return devices , nil
5358}
5459
5560func (d TestDevices ) Destroy () {
@@ -175,20 +180,13 @@ func basePoolTest(t *testing.T, pool Pool) {
175180 })
176181
177182 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-
184183 err = volume .Limit (50 * 1024 * 1024 )
185184 require .NoError (t , err )
186185
187- usage , err = volume .Usage ()
186+ usage , err : = volume .Usage ()
188187 require .NoError (t , err )
189188
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 )
192190 })
193191
194192 t .Run ("test remove subvolume" , func (t * testing.T ) {
@@ -212,9 +210,12 @@ func TestBtrfsSingleCI(t *testing.T) {
212210 require .NoError (t , err , "failed to initialize devices" )
213211
214212 defer devices .Destroy ()
215- loops := devices .Loops ()
216-
213+ loops , err := devices .Loops ()
214+ require . NoError ( t , err )
217215 for _ , dev := range loops {
216+ dev .mgr = & lsblkDeviceManager {
217+ executer : executerFunc (run ),
218+ }
218219 pool , err := NewBtrfsPool (dev )
219220 require .NoError (t , err )
220221 basePoolTest (t , pool )
@@ -231,7 +232,11 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
231232 require .NoError (t , err , "failed to initialize devices" )
232233 defer devices .Destroy ()
233234
234- loops := devices .Loops ()
235+ loops , err := devices .Loops ()
236+ require .NoError (t , err )
237+ loops [0 ].mgr = & lsblkDeviceManager {
238+ executer : executerFunc (run ),
239+ }
235240 pool , err := NewBtrfsPool (loops [0 ])
236241 require .NoError (t , err )
237242
@@ -253,18 +258,25 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
253258
254259 qgroups , err := btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
255260 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 ))
257264 t .Logf ("qgroups before delete: %v" , qgroups )
258265
259266 _ , ok = qgroups [fmt .Sprintf ("0/%d" , btrfsVol .id )]
260267 assert .True (t , ok , "qgroups should contains a qgroup linked to the subvolume" )
261268
262269 err = pool .RemoveVolume ("vol1" )
263270 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 )
264276
265277 qgroups , err = btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
266278 require .NoError (t , err )
267279
268280 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" )
270282}
0 commit comments