mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: modified folder methods and filesystem
This commit is contained in:
@@ -22,7 +22,7 @@ type File struct {
|
||||
Policy Policy `gorm:"PRELOAD:false,association_autoupdate:false"`
|
||||
|
||||
// 数据库忽略字段
|
||||
PositionTemp string `gorm:"-"`
|
||||
Position string `gorm:"-"`
|
||||
}
|
||||
|
||||
// Create 创建文件记录
|
||||
@@ -40,7 +40,7 @@ func (folder *Folder) GetChildFile(name string) (*File, error) {
|
||||
result := DB.Where("folder_id = ? AND name = ?", folder.ID, name).Find(&file)
|
||||
|
||||
if result.Error == nil {
|
||||
file.PositionTemp = path.Join(folder.PositionTemp, folder.Name, file.Name)
|
||||
file.Position = path.Join(folder.Position, folder.Name, file.Name)
|
||||
}
|
||||
return &file, result.Error
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestFolder_GetChildFile(t *testing.T) {
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("1.txt", file.Name)
|
||||
asserts.Equal("/1.txt", file.PositionTemp)
|
||||
asserts.Equal("/1.txt", file.Position)
|
||||
}
|
||||
|
||||
// 不存在
|
||||
|
||||
@@ -16,7 +16,7 @@ type Folder struct {
|
||||
OwnerID uint `gorm:"index:owner_id"`
|
||||
|
||||
// 数据库忽略字段
|
||||
PositionTemp string `gorm:"-"`
|
||||
Position string `gorm:"-"`
|
||||
}
|
||||
|
||||
// Create 创建目录
|
||||
@@ -37,7 +37,7 @@ func (folder *Folder) GetChild(name string) (*Folder, error) {
|
||||
|
||||
// 将子目录的路径传递下去
|
||||
if err == nil {
|
||||
resFolder.PositionTemp = path.Join(folder.PositionTemp, folder.Name)
|
||||
resFolder.Position = path.Join(folder.Position, folder.Name)
|
||||
}
|
||||
return &resFolder, err
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestFolder_GetChild(t *testing.T) {
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.NoError(err)
|
||||
asserts.Equal(sub.Name, "sub")
|
||||
asserts.Equal("/", sub.PositionTemp)
|
||||
asserts.Equal("/", sub.Position)
|
||||
}
|
||||
|
||||
// 目录不存在
|
||||
|
||||
Reference in New Issue
Block a user