mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: failed unit test due to missing mock.ExpectWereMatch()
This commit is contained in:
@@ -26,24 +26,37 @@ type Object struct {
|
||||
}
|
||||
|
||||
// Rename 重命名对象
|
||||
func (fs *FileSystem) Rename(ctx context.Context, src, new string) (err error) {
|
||||
func (fs *FileSystem) Rename(ctx context.Context, dir, file []uint, new string) (err error) {
|
||||
// 验证新名字
|
||||
if !fs.ValidateLegalName(ctx, new) || !fs.ValidateExtension(ctx, new) {
|
||||
return ErrIllegalObjectName
|
||||
}
|
||||
|
||||
// 如果源对象是文件
|
||||
fileExist, file := fs.IsFileExist(src)
|
||||
if fileExist {
|
||||
err = file.Rename(new)
|
||||
return err
|
||||
if len(file) > 0 {
|
||||
fileObject, err := model.GetFilesByIDs([]uint{file[0]}, fs.User.ID)
|
||||
if err != nil || len(fileObject) == 0 {
|
||||
return ErrPathNotExist
|
||||
}
|
||||
|
||||
err = fileObject[0].Rename(new)
|
||||
if err != nil {
|
||||
return ErrFileExisted
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 源对象是目录
|
||||
folderExist, folder := fs.IsPathExist(src)
|
||||
if folderExist {
|
||||
err = folder.Rename(new)
|
||||
return err
|
||||
if len(dir) > 0 {
|
||||
folderObject, err := model.GetFoldersByIDs([]uint{dir[0]}, fs.User.ID)
|
||||
if err != nil || len(folderObject) == 0 {
|
||||
return ErrPathNotExist
|
||||
}
|
||||
|
||||
err = folderObject[0].Rename(new)
|
||||
if err != nil {
|
||||
return ErrFileExisted
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return ErrPathNotExist
|
||||
|
||||
@@ -411,7 +411,7 @@ func TestFileSystem_Copy(t *testing.T) {
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
|
||||
// 1
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
WithArgs(1, 1, "src").
|
||||
WithArgs(1, 1, "dst").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
|
||||
// 根目录
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
@@ -419,17 +419,17 @@ func TestFileSystem_Copy(t *testing.T) {
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
|
||||
// 1
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
WithArgs(1, 1, "dst").
|
||||
WithArgs(1, 1, "src").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
|
||||
|
||||
err := fs.Copy(ctx, []uint{1}, []uint{}, "/src", "/dst")
|
||||
asserts.Error(err)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFileSystem_Move(t *testing.T) {
|
||||
conf.DatabaseConfig.Type = "mysql"
|
||||
asserts := assert.New(t)
|
||||
fs := &FileSystem{User: &model.User{
|
||||
Model: gorm.Model{
|
||||
@@ -458,7 +458,7 @@ func TestFileSystem_Move(t *testing.T) {
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
|
||||
// 1
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
WithArgs(1, 1, "src").
|
||||
WithArgs(1, 1, "dst").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
|
||||
// 根目录
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
@@ -466,9 +466,10 @@ func TestFileSystem_Move(t *testing.T) {
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(1, 1))
|
||||
// 1
|
||||
mock.ExpectQuery("SELECT(.+)").
|
||||
WithArgs(1, 1, "dst").
|
||||
WithArgs(1, 1, "src").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "owner_id"}).AddRow(2, 1))
|
||||
err := fs.Move(ctx, []uint{1}, []uint{}, "/src", "/dst")
|
||||
asserts.Error(err)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user