Test: file compress / download

This commit is contained in:
HFO4
2019-12-14 14:28:01 +08:00
parent 03dcd9a9e0
commit ca07a94d41
15 changed files with 367 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package model
import (
"encoding/gob"
"github.com/HFO4/cloudreve/pkg/util"
"github.com/jinzhu/gorm"
"path"
@@ -25,6 +26,11 @@ type File struct {
Position string `gorm:"-"`
}
func init() {
// 注册缓存用到的复杂结构
gob.Register(File{})
}
// Create 创建文件记录
func (file *File) Create() (uint, error) {
if err := DB.Create(file).Error; err != nil {

View File

@@ -64,6 +64,8 @@ func TestFolder_GetChildFiles(t *testing.T) {
Model: gorm.Model{
ID: 1,
},
Position: "/123",
Name: "456",
}
// 找不到
@@ -78,6 +80,7 @@ func TestFolder_GetChildFiles(t *testing.T) {
files, err = folder.GetChildFiles()
asserts.NoError(err)
asserts.Len(files, 2)
asserts.Equal("/123/456", files[0].Position)
asserts.NoError(mock.ExpectationsWereMet())
}

View File

@@ -73,6 +73,8 @@ func TestFolder_GetChildFolder(t *testing.T) {
Model: gorm.Model{
ID: 1,
},
Position: "/123",
Name: "456",
}
// 找不到
@@ -87,6 +89,7 @@ func TestFolder_GetChildFolder(t *testing.T) {
files, err = folder.GetChildFolder()
asserts.NoError(err)
asserts.Len(files, 2)
asserts.Equal("/123/456", files[0].Position)
asserts.NoError(mock.ExpectationsWereMet())
}

View File

@@ -67,6 +67,9 @@ func addDefaultPolicy() {
DirNameRule: "uploads/{uid}/{path}",
FileNameRule: "{uid}_{randomkey8}_{originname}",
IsOriginLinkEnable: false,
OptionsSerialized: PolicyOption{
FileType: []string{},
},
}
if err := DB.Create(&defaultPolicy).Error; err != nil {
util.Log().Panic("无法创建初始存储策略, %s", err)
@@ -76,7 +79,7 @@ func addDefaultPolicy() {
func addDefaultSettings() {
defaultSettings := []Setting{
{Name: "siteURL", Value: `http://lite.aoaoao.me/`, Type: "basic"},
{Name: "siteURL", Value: ``, Type: "basic"},
{Name: "siteName", Value: `Cloudreve`, Type: "basic"},
{Name: "siteStatus", Value: `open`, Type: "basic"},
{Name: "regStatus", Value: `0`, Type: "register"},