Test: pkg modifications

pull/247/head
HFO4 5 years ago
parent 0502a0f212
commit 663b827a1d

@ -135,3 +135,13 @@ func TestMemoStore_Delete(t *testing.T) {
asserts.Equal([]string{"1", "2"}, miss)
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").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除对应分享
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 归还容量
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)users").
@ -343,6 +348,11 @@ func TestFileSystem_Delete(t *testing.T) {
mock.ExpectExec("DELETE(.+)folders").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除对应分享
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
err := fs.Delete(ctx, []uint{1}, []uint{1})
asserts.Error(err)
@ -379,6 +389,11 @@ func TestFileSystem_Delete(t *testing.T) {
mock.ExpectExec("DELETE(.+)").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除对应分享
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 归还容量
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)").
@ -389,6 +404,11 @@ func TestFileSystem_Delete(t *testing.T) {
mock.ExpectExec("DELETE(.+)").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除对应分享
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
fs.FileTarget = []model.File{}
fs.DirTarget = []model.Folder{}

@ -8,6 +8,28 @@ import (
"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) {
asserts := assert.New(t)

Loading…
Cancel
Save