@@ -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 () {
@@ -121,8 +126,6 @@ func TestMain(m *testing.M) {
121126}
122127
123128func basePoolTest (t * testing.T , pool Pool ) {
124- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
125-
126129 t .Run ("test mounted" , func (t * testing.T ) {
127130 _ , err := pool .Mounted ()
128131 assert .ErrorIs (t , err , ErrDeviceNotMounted )
@@ -175,20 +178,13 @@ func basePoolTest(t *testing.T, pool Pool) {
175178 })
176179
177180 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-
184181 err = volume .Limit (50 * 1024 * 1024 )
185182 require .NoError (t , err )
186183
187- usage , err = volume .Usage ()
184+ usage , err : = volume .Usage ()
188185 require .NoError (t , err )
189186
190- // Note: an empty subvolume has an overhead of 16384 bytes
191- 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 )
192188 })
193189
194190 t .Run ("test remove subvolume" , func (t * testing.T ) {
@@ -206,15 +202,17 @@ func TestBtrfsSingleCI(t *testing.T) {
206202 if SkipCITests {
207203 t .Skip ("test requires ability to create loop devices" )
208204 }
209- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
210205
211206 devices , err := SetupDevices (1 )
212207 require .NoError (t , err , "failed to initialize devices" )
213208
214209 defer devices .Destroy ()
215- loops := devices .Loops ()
216-
210+ loops , err := devices .Loops ()
211+ require . NoError ( t , err )
217212 for _ , dev := range loops {
213+ dev .mgr = & lsblkDeviceManager {
214+ executer : executerFunc (run ),
215+ }
218216 pool , err := NewBtrfsPool (dev )
219217 require .NoError (t , err )
220218 basePoolTest (t , pool )
@@ -225,13 +223,16 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
225223 if SkipCITests {
226224 t .Skip ("test requires ability to create loop devices" )
227225 }
228- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
229226
230227 devices , err := SetupDevices (1 )
231228 require .NoError (t , err , "failed to initialize devices" )
232229 defer devices .Destroy ()
233230
234- loops := devices .Loops ()
231+ loops , err := devices .Loops ()
232+ require .NoError (t , err )
233+ loops [0 ].mgr = & lsblkDeviceManager {
234+ executer : executerFunc (run ),
235+ }
235236 pool , err := NewBtrfsPool (loops [0 ])
236237 require .NoError (t , err )
237238
@@ -253,18 +254,25 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
253254
254255 qgroups , err := btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
255256 require .NoError (t , err )
256- 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 ))
257260 t .Logf ("qgroups before delete: %v" , qgroups )
258261
259262 _ , ok = qgroups [fmt .Sprintf ("0/%d" , btrfsVol .id )]
260263 assert .True (t , ok , "qgroups should contains a qgroup linked to the subvolume" )
261264
262265 err = pool .RemoveVolume ("vol1" )
263266 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 )
264272
265273 qgroups , err = btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
266274 require .NoError (t , err )
267275
268276 t .Logf ("remaining qgroups: %+v" , qgroups )
269- 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" )
270278}
0 commit comments