mirror of
				https://github.com/cloudreve/cloudreve.git
				synced 2025-11-01 00:57:15 +08:00 
			
		
		
		
	Test: pkg modifications
This commit is contained in:
		
							
								
								
									
										10
									
								
								pkg/cache/memo_test.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								pkg/cache/memo_test.go
									
									
									
									
										vendored
									
									
								
							| @ -135,3 +135,13 @@ func TestMemoStore_Delete(t *testing.T) { | |||||||
| 	asserts.Equal([]string{"1", "2"}, miss) | 	asserts.Equal([]string{"1", "2"}, miss) | ||||||
| 	asserts.Equal(map[string]interface{}{"3": "3.val", "4": "4.val"}, values) | 	asserts.Equal(map[string]interface{}{"3": "3.val", "4": "4.val"}, values) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestMemoStore_GarbageCollect(t *testing.T) { | ||||||
|  | 	asserts := assert.New(t) | ||||||
|  | 	store := NewMemoStore() | ||||||
|  | 	store.Set("test", 1, 1) | ||||||
|  | 	time.Sleep(time.Duration(2000) * time.Millisecond) | ||||||
|  | 	store.GarbageCollect() | ||||||
|  | 	_, ok := store.Get("test") | ||||||
|  | 	asserts.False(ok) | ||||||
|  | } | ||||||
|  | |||||||
| @ -333,6 +333,11 @@ func TestFileSystem_Delete(t *testing.T) { | |||||||
| 		mock.ExpectExec("DELETE(.+)files"). | 		mock.ExpectExec("DELETE(.+)files"). | ||||||
| 			WillReturnResult(sqlmock.NewResult(0, 3)) | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
| 		mock.ExpectCommit() | 		mock.ExpectCommit() | ||||||
|  | 		// 删除对应分享 | ||||||
|  | 		mock.ExpectBegin() | ||||||
|  | 		mock.ExpectExec("UPDATE(.+)shares"). | ||||||
|  | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
|  | 		mock.ExpectCommit() | ||||||
| 		// 归还容量 | 		// 归还容量 | ||||||
| 		mock.ExpectBegin() | 		mock.ExpectBegin() | ||||||
| 		mock.ExpectExec("UPDATE(.+)users"). | 		mock.ExpectExec("UPDATE(.+)users"). | ||||||
| @ -343,6 +348,11 @@ func TestFileSystem_Delete(t *testing.T) { | |||||||
| 		mock.ExpectExec("DELETE(.+)folders"). | 		mock.ExpectExec("DELETE(.+)folders"). | ||||||
| 			WillReturnResult(sqlmock.NewResult(0, 3)) | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
| 		mock.ExpectCommit() | 		mock.ExpectCommit() | ||||||
|  | 		// 删除对应分享 | ||||||
|  | 		mock.ExpectBegin() | ||||||
|  | 		mock.ExpectExec("UPDATE(.+)shares"). | ||||||
|  | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
|  | 		mock.ExpectCommit() | ||||||
|  |  | ||||||
| 		err := fs.Delete(ctx, []uint{1}, []uint{1}) | 		err := fs.Delete(ctx, []uint{1}, []uint{1}) | ||||||
| 		asserts.Error(err) | 		asserts.Error(err) | ||||||
| @ -379,6 +389,11 @@ func TestFileSystem_Delete(t *testing.T) { | |||||||
| 		mock.ExpectExec("DELETE(.+)"). | 		mock.ExpectExec("DELETE(.+)"). | ||||||
| 			WillReturnResult(sqlmock.NewResult(0, 3)) | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
| 		mock.ExpectCommit() | 		mock.ExpectCommit() | ||||||
|  | 		// 删除对应分享 | ||||||
|  | 		mock.ExpectBegin() | ||||||
|  | 		mock.ExpectExec("UPDATE(.+)shares"). | ||||||
|  | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
|  | 		mock.ExpectCommit() | ||||||
| 		// 归还容量 | 		// 归还容量 | ||||||
| 		mock.ExpectBegin() | 		mock.ExpectBegin() | ||||||
| 		mock.ExpectExec("UPDATE(.+)"). | 		mock.ExpectExec("UPDATE(.+)"). | ||||||
| @ -389,6 +404,11 @@ func TestFileSystem_Delete(t *testing.T) { | |||||||
| 		mock.ExpectExec("DELETE(.+)"). | 		mock.ExpectExec("DELETE(.+)"). | ||||||
| 			WillReturnResult(sqlmock.NewResult(0, 3)) | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
| 		mock.ExpectCommit() | 		mock.ExpectCommit() | ||||||
|  | 		// 删除对应分享 | ||||||
|  | 		mock.ExpectBegin() | ||||||
|  | 		mock.ExpectExec("UPDATE(.+)shares"). | ||||||
|  | 			WillReturnResult(sqlmock.NewResult(0, 3)) | ||||||
|  | 		mock.ExpectCommit() | ||||||
|  |  | ||||||
| 		fs.FileTarget = []model.File{} | 		fs.FileTarget = []model.File{} | ||||||
| 		fs.DirTarget = []model.Folder{} | 		fs.DirTarget = []model.Folder{} | ||||||
|  | |||||||
| @ -8,6 +8,28 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | func TestBuildShareList(t *testing.T) { | ||||||
|  | 	asserts := assert.New(t) | ||||||
|  | 	timeNow := time.Now() | ||||||
|  |  | ||||||
|  | 	shares := []model.Share{ | ||||||
|  | 		{ | ||||||
|  | 			Expires: &timeNow, | ||||||
|  | 			File: model.File{ | ||||||
|  | 				Model: gorm.Model{ID: 1}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			Folder: model.Folder{ | ||||||
|  | 				Model: gorm.Model{ID: 1}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	res := BuildShareList(shares, 2) | ||||||
|  | 	asserts.Equal(0, res.Code) | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestBuildShareResponse(t *testing.T) { | func TestBuildShareResponse(t *testing.T) { | ||||||
| 	asserts := assert.New(t) | 	asserts := assert.New(t) | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 HFO4
					HFO4