@@ -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 () {
@@ -173,20 +178,13 @@ func basePoolTest(t *testing.T, pool Pool) {
173178 })
174179
175180 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-
182181 err = volume .Limit (50 * 1024 * 1024 )
183182 require .NoError (t , err )
184183
185- usage , err = volume .Usage ()
184+ usage , err : = volume .Usage ()
186185 require .NoError (t , err )
187186
188- // Note: an empty subvolume has an overhead of 16384 bytes
189- assert .Equal (t , Usage {Used : 16384 , Size : 50 * 1024 * 1024 }, usage )
187+ assert .Equal (t , Usage {Used : 50 * 1024 * 1024 , Size : 50 * 1024 * 1024 }, usage )
190188 })
191189
192190 t .Run ("test remove subvolume" , func (t * testing.T ) {
@@ -209,9 +207,12 @@ func TestBtrfsSingleCI(t *testing.T) {
209207 require .NoError (t , err , "failed to initialize devices" )
210208
211209 defer devices .Destroy ()
212- loops := devices .Loops ()
213-
210+ loops , err := devices .Loops ()
211+ require . NoError ( t , err )
214212 for _ , dev := range loops {
213+ dev .mgr = & lsblkDeviceManager {
214+ executer : executerFunc (run ),
215+ }
215216 pool , err := NewBtrfsPool (dev )
216217 require .NoError (t , err )
217218 basePoolTest (t , pool )
@@ -227,7 +228,11 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
227228 require .NoError (t , err , "failed to initialize devices" )
228229 defer devices .Destroy ()
229230
230- loops := devices .Loops ()
231+ loops , err := devices .Loops ()
232+ require .NoError (t , err )
233+ loops [0 ].mgr = & lsblkDeviceManager {
234+ executer : executerFunc (run ),
235+ }
231236 pool , err := NewBtrfsPool (loops [0 ])
232237 require .NoError (t , err )
233238
@@ -249,18 +254,25 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
249254
250255 qgroups , err := btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
251256 require .NoError (t , err )
252- assert .Equal (t , 1 , len (qgroups ))
257+
258+ // it start with a volume of size 16384 by default
259+ assert .Equal (t , 2 , len (qgroups ))
253260 t .Logf ("qgroups before delete: %v" , qgroups )
254261
255262 _ , ok = qgroups [fmt .Sprintf ("0/%d" , btrfsVol .id )]
256263 assert .True (t , ok , "qgroups should contains a qgroup linked to the subvolume" )
257264
258265 err = pool .RemoveVolume ("vol1" )
259266 require .NoError (t , err )
267+ u := btrfsVol .utils
268+ _ , err = u .run (context .TODO (), "btrfs" , "quota" , "disable" , pool .Path ())
269+ require .NoError (t , err )
270+ _ , err = u .run (context .TODO (), "btrfs" , "quota" , "enable" , pool .Path ())
271+ require .NoError (t , err )
260272
261273 qgroups , err = btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
262274 require .NoError (t , err )
263275
264276 t .Logf ("remaining qgroups: %+v" , qgroups )
265- assert .Equal (t , 0 , len (qgroups ), "qgroups should have been deleted with the subvolume" )
277+ assert .Equal (t , 1 , len (qgroups ), "qgroups should have been deleted with the subvolume" )
266278}
0 commit comments