test: fix failed test
This commit is contained in:
parent
478d390867
commit
18f5bffed1
4 changed files with 22 additions and 14 deletions
|
@ -76,3 +76,12 @@ func TestIsFunctionEnabled(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCacheControl(t *testing.T) {
|
||||||
|
a := assert.New(t)
|
||||||
|
TestFunc := CacheControl()
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(rec)
|
||||||
|
TestFunc(c)
|
||||||
|
a.Contains(c.Writer.Header().Get("Cache-Control"), "no-cache")
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/request"
|
"github.com/cloudreve/Cloudreve/v3/pkg/request"
|
||||||
|
@ -58,12 +59,11 @@ func TestFileSystem_Compress(t *testing.T) {
|
||||||
)
|
)
|
||||||
// 查找上传策略
|
// 查找上传策略
|
||||||
asserts.NoError(cache.Set("policy_1", model.Policy{Type: "local"}, -1))
|
asserts.NoError(cache.Set("policy_1", model.Policy{Type: "local"}, -1))
|
||||||
|
w := &bytes.Buffer{}
|
||||||
|
|
||||||
zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true)
|
err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true)
|
||||||
asserts.NoError(err)
|
asserts.NoError(err)
|
||||||
asserts.NotEmpty(zipFile)
|
asserts.NotEmpty(w.Len())
|
||||||
asserts.Contains(zipFile, "archive_")
|
|
||||||
asserts.Contains(zipFile, "tests")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上下文取消
|
// 上下文取消
|
||||||
|
@ -84,9 +84,10 @@ func TestFileSystem_Compress(t *testing.T) {
|
||||||
)
|
)
|
||||||
asserts.NoError(cache.Set("setting_temp_path", "tests", -1))
|
asserts.NoError(cache.Set("setting_temp_path", "tests", -1))
|
||||||
|
|
||||||
zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true)
|
w := &bytes.Buffer{}
|
||||||
|
err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true)
|
||||||
asserts.Error(err)
|
asserts.Error(err)
|
||||||
asserts.Empty(zipFile)
|
asserts.NotEmpty(w.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 限制父目录
|
// 限制父目录
|
||||||
|
@ -108,10 +109,11 @@ func TestFileSystem_Compress(t *testing.T) {
|
||||||
)
|
)
|
||||||
asserts.NoError(cache.Set("setting_temp_path", "tests", -1))
|
asserts.NoError(cache.Set("setting_temp_path", "tests", -1))
|
||||||
|
|
||||||
zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true)
|
w := &bytes.Buffer{}
|
||||||
|
err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true)
|
||||||
asserts.Error(err)
|
asserts.Error(err)
|
||||||
asserts.Equal(ErrObjectNotExist, err)
|
asserts.Equal(ErrObjectNotExist, err)
|
||||||
asserts.Empty(zipFile)
|
asserts.Empty(w.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (job *CompressTask) Do() {
|
||||||
|
|
||||||
job.zipPath = zipFilePath
|
job.zipPath = zipFilePath
|
||||||
zipFile.Close()
|
zipFile.Close()
|
||||||
util.Log().Debug("压缩文件存放至%s,开始上传", zipFile)
|
util.Log().Debug("压缩文件存放至%s,开始上传", zipFilePath)
|
||||||
job.TaskModel.SetProgress(TransferringProgress)
|
job.TaskModel.SetProgress(TransferringProgress)
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (service *ArchiveService) DownloadArchived(ctx context.Context, c *gin.Cont
|
||||||
user := userRaw.(model.User)
|
user := userRaw.(model.User)
|
||||||
|
|
||||||
// 创建文件系统
|
// 创建文件系统
|
||||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
fs, err := filesystem.NewFileSystem(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,6 @@ func (service *ArchiveService) DownloadArchived(ctx context.Context, c *gin.Cont
|
||||||
return serializer.Err(404, "归档会话不存在", nil)
|
return serializer.Err(404, "归档会话不存在", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理打包会话
|
|
||||||
_ = cache.Deletes([]string{service.ID, "user_" + service.ID}, "archive_")
|
|
||||||
|
|
||||||
// 开始打包
|
// 开始打包
|
||||||
c.Header("Content-Disposition", "attachment;")
|
c.Header("Content-Disposition", "attachment;")
|
||||||
c.Header("Content-Type", "application/zip")
|
c.Header("Content-Type", "application/zip")
|
||||||
|
@ -268,7 +265,7 @@ func (service *FileIDService) CreateDownloadSession(ctx context.Context, c *gin.
|
||||||
// Download 通过签名URL的文件下载,无需登录
|
// Download 通过签名URL的文件下载,无需登录
|
||||||
func (service *DownloadService) Download(ctx context.Context, c *gin.Context) serializer.Response {
|
func (service *DownloadService) Download(ctx context.Context, c *gin.Context) serializer.Response {
|
||||||
// 创建文件系统
|
// 创建文件系统
|
||||||
fs, err := filesystem.NewFileSystem(&user)
|
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue