@@ -10,59 +10,103 @@ import (
1010)
1111
1212func TestRedisIndex_SpaceDelete (t * testing.T ) {
13- fx := newFixture (t )
14- defer fx .Finish (t )
15- key := newRandKey ()
16-
17- // space not exists
18- ok , err := fx .SpaceDelete (ctx , key )
19- require .NoError (t , err )
20- assert .False (t , ok )
21-
22- // add files
23- bs := testutil .NewRandBlocks (5 )
24- require .NoError (t , fx .BlocksAdd (ctx , bs ))
25- cids , err := fx .CidEntriesByBlocks (ctx , bs )
26- require .NoError (t , err )
27- cids .Release ()
28-
29- // bind to files with intersected cids
30- fileId1 := testutil .NewRandCid ().String ()
31- fileId2 := testutil .NewRandCid ().String ()
32-
33- cids1 , err := fx .CidEntriesByBlocks (ctx , bs )
34- require .NoError (t , err )
35- require .NoError (t , fx .FileBind (ctx , key , fileId1 , cids1 ))
36- cids1 .Release ()
37-
38- cids2 , err := fx .CidEntriesByBlocks (ctx , bs [:2 ])
39- require .NoError (t , err )
40- require .NoError (t , fx .FileBind (ctx , key , fileId2 , cids2 ))
41- cids2 .Release ()
42-
43- groupInfo , err := fx .GroupInfo (ctx , key .GroupId )
44- require .NoError (t , err )
45- assert .NotEmpty (t , groupInfo .BytesUsage )
46- assert .Contains (t , groupInfo .SpaceIds , key .SpaceId )
47-
48- require .NoError (t , fx .SetGroupLimit (ctx , key .GroupId , 5000 ))
49- require .NoError (t , fx .SetSpaceLimit (ctx , key , 4000 ))
50-
51- ok , err = fx .SpaceDelete (ctx , key )
52- require .NoError (t , err )
53- assert .True (t , ok )
54-
55- groupInfo , err = fx .GroupInfo (ctx , key .GroupId )
56- require .NoError (t , err )
57- assert .Empty (t , groupInfo .BytesUsage )
58- assert .NotContains (t , groupInfo .SpaceIds , key .SpaceId )
59- assert .Equal (t , uint64 (5000 ), groupInfo .AccountLimit )
60- assert .Equal (t , uint64 (5000 ), groupInfo .Limit )
61-
62- // second call
63- ok , err = fx .SpaceDelete (ctx , key )
64- require .NoError (t , err )
65- assert .False (t , ok )
13+ t .Run ("success" , func (t * testing.T ) {
14+ fx := newFixture (t )
15+ defer fx .Finish (t )
16+ key := newRandKey ()
17+
18+ // space not exists
19+ ok , err := fx .SpaceDelete (ctx , key )
20+ require .NoError (t , err )
21+ assert .False (t , ok )
22+
23+ // add files
24+ bs := testutil .NewRandBlocks (5 )
25+ require .NoError (t , fx .BlocksAdd (ctx , bs ))
26+ cids , err := fx .CidEntriesByBlocks (ctx , bs )
27+ require .NoError (t , err )
28+ cids .Release ()
29+
30+ // bind to files with intersected cids
31+ fileId1 := testutil .NewRandCid ().String ()
32+ fileId2 := testutil .NewRandCid ().String ()
33+
34+ cids1 , err := fx .CidEntriesByBlocks (ctx , bs )
35+ require .NoError (t , err )
36+ require .NoError (t , fx .FileBind (ctx , key , fileId1 , cids1 ))
37+ cids1 .Release ()
38+
39+ cids2 , err := fx .CidEntriesByBlocks (ctx , bs [:2 ])
40+ require .NoError (t , err )
41+ require .NoError (t , fx .FileBind (ctx , key , fileId2 , cids2 ))
42+ cids2 .Release ()
43+
44+ groupInfo , err := fx .GroupInfo (ctx , key .GroupId )
45+ require .NoError (t , err )
46+ assert .NotEmpty (t , groupInfo .BytesUsage )
47+ assert .Contains (t , groupInfo .SpaceIds , key .SpaceId )
48+
49+ require .NoError (t , fx .SetGroupLimit (ctx , key .GroupId , 5000 ))
50+ require .NoError (t , fx .SetSpaceLimit (ctx , key , 4000 ))
51+
52+ ok , err = fx .SpaceDelete (ctx , key )
53+ require .NoError (t , err )
54+ assert .True (t , ok )
55+
56+ groupInfo , err = fx .GroupInfo (ctx , key .GroupId )
57+ require .NoError (t , err )
58+ assert .Empty (t , groupInfo .BytesUsage )
59+ assert .NotContains (t , groupInfo .SpaceIds , key .SpaceId )
60+ assert .Equal (t , uint64 (5000 ), groupInfo .AccountLimit )
61+ assert .Equal (t , uint64 (5000 ), groupInfo .Limit )
62+
63+ // second call
64+ ok , err = fx .SpaceDelete (ctx , key )
65+ require .NoError (t , err )
66+ assert .False (t , ok )
67+ })
68+ t .Run ("delete from group" , func (t * testing.T ) {
69+ fx := newFixture (t )
70+ defer fx .Finish (t )
71+ key := newRandKey ()
72+
73+ // add files
74+ bs := testutil .NewRandBlocks (5 )
75+ require .NoError (t , fx .BlocksAdd (ctx , bs ))
76+ cids , err := fx .CidEntriesByBlocks (ctx , bs )
77+ require .NoError (t , err )
78+ cids .Release ()
79+
80+ // bind to files with intersected cids
81+ fileId1 := testutil .NewRandCid ().String ()
82+ fileId2 := testutil .NewRandCid ().String ()
83+
84+ cids1 , err := fx .CidEntriesByBlocks (ctx , bs )
85+ require .NoError (t , err )
86+ require .NoError (t , fx .FileBind (ctx , key , fileId1 , cids1 ))
87+ cids1 .Release ()
88+
89+ cids2 , err := fx .CidEntriesByBlocks (ctx , bs [:2 ])
90+ require .NoError (t , err )
91+ require .NoError (t , fx .FileBind (ctx , key , fileId2 , cids2 ))
92+ cids2 .Release ()
93+
94+ require .NoError (t , fx .FileUnbind (ctx , key , fileId1 , fileId2 ))
95+
96+ ok , err := fx .MarkSpaceAsDeleted (ctx , key )
97+ require .NoError (t , err )
98+ assert .True (t , ok )
99+
100+ require .NoError (t , fx .cl .Del (ctx , SpaceKey (key )).Err ())
101+
102+ ok , err = fx .SpaceDelete (ctx , key )
103+ require .NoError (t , err )
104+ assert .True (t , ok )
105+
106+ groupInfo , err := fx .GroupInfo (ctx , key .GroupId )
107+ require .NoError (t , err )
108+ assert .NotContains (t , groupInfo .SpaceIds , key .SpaceId )
109+ })
66110}
67111
68112func TestRedisIndex_MarkSpaceAsDeleted (t * testing.T ) {
0 commit comments