@@ -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 () {
@@ -121,8 +126,6 @@ func TestMain(m *testing.M) {
121
126
}
122
127
123
128
func basePoolTest (t * testing.T , pool Pool ) {
124
- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
125
-
126
129
t .Run ("test mounted" , func (t * testing.T ) {
127
130
_ , err := pool .Mounted ()
128
131
assert .ErrorIs (t , err , ErrDeviceNotMounted )
@@ -175,20 +178,13 @@ func basePoolTest(t *testing.T, pool Pool) {
175
178
})
176
179
177
180
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
181
err = volume .Limit (50 * 1024 * 1024 )
185
182
require .NoError (t , err )
186
183
187
- usage , err = volume .Usage ()
184
+ usage , err : = volume .Usage ()
188
185
require .NoError (t , err )
189
186
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 )
192
188
})
193
189
194
190
t .Run ("test remove subvolume" , func (t * testing.T ) {
@@ -206,15 +202,17 @@ func TestBtrfsSingleCI(t *testing.T) {
206
202
if SkipCITests {
207
203
t .Skip ("test requires ability to create loop devices" )
208
204
}
209
- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
210
205
211
206
devices , err := SetupDevices (1 )
212
207
require .NoError (t , err , "failed to initialize devices" )
213
208
214
209
defer devices .Destroy ()
215
- loops := devices .Loops ()
216
-
210
+ loops , err := devices .Loops ()
211
+ require . NoError ( t , err )
217
212
for _ , dev := range loops {
213
+ dev .mgr = & lsblkDeviceManager {
214
+ executer : executerFunc (run ),
215
+ }
218
216
pool , err := NewBtrfsPool (dev )
219
217
require .NoError (t , err )
220
218
basePoolTest (t , pool )
@@ -225,13 +223,16 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
225
223
if SkipCITests {
226
224
t .Skip ("test requires ability to create loop devices" )
227
225
}
228
- t .Skip ("skipping test, to be solved in https://github.com/threefoldtech/zosbase/issues/19" )
229
226
230
227
devices , err := SetupDevices (1 )
231
228
require .NoError (t , err , "failed to initialize devices" )
232
229
defer devices .Destroy ()
233
230
234
- loops := devices .Loops ()
231
+ loops , err := devices .Loops ()
232
+ require .NoError (t , err )
233
+ loops [0 ].mgr = & lsblkDeviceManager {
234
+ executer : executerFunc (run ),
235
+ }
235
236
pool , err := NewBtrfsPool (loops [0 ])
236
237
require .NoError (t , err )
237
238
@@ -253,18 +254,25 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
253
254
254
255
qgroups , err := btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
255
256
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 ))
257
260
t .Logf ("qgroups before delete: %v" , qgroups )
258
261
259
262
_ , ok = qgroups [fmt .Sprintf ("0/%d" , btrfsVol .id )]
260
263
assert .True (t , ok , "qgroups should contains a qgroup linked to the subvolume" )
261
264
262
265
err = pool .RemoveVolume ("vol1" )
263
266
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 )
264
272
265
273
qgroups , err = btrfsVol .utils .QGroupList (context .TODO (), pool .Path ())
266
274
require .NoError (t , err )
267
275
268
276
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" )
270
278
}
0 commit comments