66 "testing"
77 "time"
88
9- "github.com/anyproto/any-sync/consensus/consensusclient"
10- "github.com/anyproto/any-sync/consensus/consensusclient/mock_consensusclient"
11- "github.com/anyproto/any-sync/consensus/consensusproto/consensuserr"
129 "github.com/anyproto/any-sync/coordinator/coordinatorproto"
1310 "github.com/anyproto/any-sync/testutil/anymock"
1411 "github.com/stretchr/testify/assert"
@@ -40,7 +37,6 @@ func TestSpaceDeleter_Run_Ok(t *testing.T) {
4037 lg := mockDeletionLog (store .Id ())
4138
4239 fx .coordClient .EXPECT ().DeletionLog (gomock .Any (), "" , logLimit ).Return (lg , nil ).AnyTimes ()
43- fx .consClient .EXPECT ().DeleteLog (gomock .Any (), payload .AclWithId .Id ).Return (nil )
4440 store .Close (context .Background ())
4541
4642 close (fx .waiterChan )
@@ -71,7 +67,6 @@ func TestSpaceDeleter_Run_Ok_NewPush(t *testing.T) {
7167 lg := mockDeletionLogNewPush (store .Id ())
7268
7369 fx .coordClient .EXPECT ().DeletionLog (gomock .Any (), "" , logLimit ).Return (lg , nil ).AnyTimes ()
74- fx .consClient .EXPECT ().DeleteLog (gomock .Any (), payload .AclWithId .Id ).Return (nil )
7570 store .Close (context .Background ())
7671
7772 close (fx .waiterChan )
@@ -85,31 +80,6 @@ func TestSpaceDeleter_Run_Ok_NewPush(t *testing.T) {
8580 require .Equal (t , nodestorage .SpaceStatusOk , status )
8681}
8782
88- func TestSpaceDeleter_Run_Ok_LogNotFound (t * testing.T ) {
89- fx := newSpaceDeleterFixture (t )
90- defer fx .stop (t )
91- payload := nodestorage .NewStorageCreatePayload (t )
92- store , err := fx .storage .CreateSpaceStorage (ctx , payload )
93- require .NoError (t , err )
94- lg := mockDeletionLog (store .Id ())
95-
96- fx .coordClient .EXPECT ().DeletionLog (gomock .Any (), "" , logLimit ).Return (lg , nil ).AnyTimes ()
97- fx .consClient .EXPECT ().DeleteLog (gomock .Any (), payload .AclWithId .Id ).Return (consensuserr .ErrLogNotFound )
98- store .Close (context .Background ())
99-
100- close (fx .waiterChan )
101- <- fx .deleter .testChan
102-
103- id , err := fx .storage .IndexStorage ().LastRecordId (ctx )
104- require .NoError (t , err )
105- require .Equal (t , lg [2 ].Id , id )
106- store , err = fx .storage .WaitSpaceStorage (context .Background (), payload .SpaceHeaderWithId .Id )
107- require .Error (t , err )
108- status , err := fx .storage .IndexStorage ().SpaceStatus (ctx , payload .SpaceHeaderWithId .Id )
109- require .NoError (t , err )
110- require .Equal (t , nodestorage .SpaceStatusRemove , status )
111- }
112-
11383func TestSpaceDeleter_Run_Ok_NoStorage (t * testing.T ) {
11484 fx := newSpaceDeleterFixture (t )
11585 defer fx .stop (t )
@@ -170,32 +140,6 @@ func TestSpaceDeleter_Run_Ok_EmptyStorage(t *testing.T) {
170140 require .Equal (t , nodestorage .SpaceStatusRemove , status )
171141}
172142
173- func TestSpaceDeleter_Run_Failure_LogError (t * testing.T ) {
174- fx := newSpaceDeleterFixture (t )
175- payload := nodestorage .NewStorageCreatePayload (t )
176- store , err := fx .storage .CreateSpaceStorage (ctx , payload )
177- require .NoError (t , err )
178- lg := mockDeletionLog (store .Id ())
179-
180- fx .coordClient .EXPECT ().DeletionLog (gomock .Any (), "" , logLimit ).Return (lg , nil ).AnyTimes ()
181- fx .consClient .EXPECT ().DeleteLog (gomock .Any (), payload .AclWithId .Id ).Return (consensuserr .ErrConflict )
182- store .Close (context .Background ())
183-
184- close (fx .waiterChan )
185- <- fx .deleter .testChan
186-
187- id , err := fx .storage .IndexStorage ().LastRecordId (ctx )
188- require .NoError (t , err )
189- require .Equal (t , lg [1 ].Id , id )
190- // checking that storage is still there
191- store , err = fx .storage .WaitSpaceStorage (ctx , payload .SpaceHeaderWithId .Id )
192- require .NoError (t , err )
193- store .Close (context .Background ())
194- _ , err = fx .storage .IndexStorage ().SpaceStatus (ctx , payload .SpaceHeaderWithId .Id )
195- require .Error (t , nodestorage .ErrUnknownSpaceId , err )
196- fx .stop (t )
197- }
198-
199143func mockDeletionLog (realId string ) []* coordinatorproto.DeletionLogRecord {
200144 return []* coordinatorproto.DeletionLogRecord {
201145 {Id : "1" , SpaceId : "space1" , Status : coordinatorproto .DeletionLogRecordStatus_Ok },
@@ -215,7 +159,6 @@ func mockDeletionLogNewPush(realId string) []*coordinatorproto.DeletionLogRecord
215159
216160type spaceDeleterFixture struct {
217161 coordClient * mock_coordinatorclient.MockCoordinatorClient
218- consClient * mock_consensusclient.MockService
219162 spaceService * mock_nodespace.MockService
220163 storage nodestorage.NodeStorage
221164 nodesync * mock_nodesync.MockNodeSync
@@ -244,19 +187,16 @@ func newSpaceDeleterFixture(t *testing.T) *spaceDeleterFixture {
244187 coordClient := mock_coordinatorclient .NewMockCoordinatorClient (ctrl )
245188 spaceService := mock_nodespace .NewMockService (ctrl )
246189 nodeSync := mock_nodesync .NewMockNodeSync (ctrl )
247- consClient := mock_consensusclient .NewMockService (ctrl )
248190 archive := mock_archive .NewMockArchive (ctrl )
249191 storage := nodestorage .New ()
250192 anymock .ExpectComp (coordClient .EXPECT (), coordinatorclient .CName )
251193 anymock .ExpectComp (spaceService .EXPECT (), nodespace .CName )
252- anymock .ExpectComp (consClient .EXPECT (), consensusclient .CName )
253194 anymock .ExpectComp (nodeSync .EXPECT (), nodesync .CName )
254195 anymock .ExpectComp (archive .EXPECT (), "node.archive" )
255196 nodeSync .EXPECT ().WaitSyncOnStart ().Return (waiterChan ).AnyTimes ()
256197 deleter := New ().(* spaceDeleter )
257198 a .Register (storeConfig (dir )).
258199 Register (coordClient ).
259- Register (consClient ).
260200 Register (storage ).
261201 Register (spaceService ).
262202 Register (archive ).
@@ -266,7 +206,6 @@ func newSpaceDeleterFixture(t *testing.T) *spaceDeleterFixture {
266206 require .NoError (t , err )
267207 return & spaceDeleterFixture {
268208 coordClient : coordClient ,
269- consClient : consClient ,
270209 spaceService : spaceService ,
271210 storage : storage ,
272211 nodesync : nodeSync ,
@@ -282,7 +221,6 @@ const testSaveDelay = 500 * time.Millisecond
282221func (fx * spaceDeleterFixture ) stop (t * testing.T ) {
283222 fx .nodesync .EXPECT ().Close (gomock .Any ()).Return (nil ).AnyTimes ()
284223 fx .spaceService .EXPECT ().Close (gomock .Any ()).Return (nil ).AnyTimes ()
285- fx .consClient .EXPECT ().Close (gomock .Any ()).Return (nil ).AnyTimes ()
286224 err := fx .app .Close (context .Background ())
287225 require .NoError (t , err )
288226 fx .ctrl .Finish ()
0 commit comments