mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 10:01:56 +08:00
test(thumb): new changes in filesystem pkg
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/auth"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/driver"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
||||
@@ -141,17 +142,34 @@ func TestHandler_Thumb(t *testing.T) {
|
||||
asserts.NoError(err)
|
||||
file.Close()
|
||||
|
||||
f := &model.File{
|
||||
SourceName: "TestHandler_Thumb",
|
||||
MetadataSerialized: map[string]string{
|
||||
model.ThumbStatusMetadataKey: model.ThumbStatusExist,
|
||||
},
|
||||
}
|
||||
|
||||
// 正常
|
||||
{
|
||||
thumb, err := handler.Thumb(ctx, "TestHandler_Thumb")
|
||||
thumb, err := handler.Thumb(ctx, f)
|
||||
asserts.NoError(err)
|
||||
asserts.NotNil(thumb.Content)
|
||||
}
|
||||
|
||||
// 不存在
|
||||
// file 不存在
|
||||
{
|
||||
_, err := handler.Thumb(ctx, "not_exist")
|
||||
f.SourceName = "not_exist"
|
||||
_, err := handler.Thumb(ctx, f)
|
||||
asserts.Error(err)
|
||||
asserts.ErrorIs(err, driver.ErrorThumbNotExist)
|
||||
}
|
||||
|
||||
// thumb not exist
|
||||
{
|
||||
f.MetadataSerialized[model.ThumbStatusMetadataKey] = model.ThumbStatusNotExist
|
||||
_, err := handler.Thumb(ctx, f)
|
||||
asserts.Error(err)
|
||||
asserts.ErrorIs(err, driver.ErrorThumbNotExist)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,19 +246,19 @@ func TestDriver_Thumb(t *testing.T) {
|
||||
}
|
||||
handler.Client, _ = NewClient(&model.Policy{})
|
||||
handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
|
||||
file := &model.File{PicInfo: "1,1", Model: gorm.Model{ID: 1}}
|
||||
|
||||
// 失败
|
||||
{
|
||||
ctx := context.WithValue(context.Background(), fsctx.ThumbSizeCtx, [2]uint{10, 20})
|
||||
ctx = context.WithValue(ctx, fsctx.FileModelCtx, model.File{PicInfo: "1,1", Model: gorm.Model{ID: 1}})
|
||||
res, err := handler.Thumb(ctx, "123.jpg")
|
||||
res, err := handler.Thumb(ctx, file)
|
||||
asserts.Error(err)
|
||||
asserts.Empty(res.URL)
|
||||
}
|
||||
|
||||
// 上下文错误
|
||||
{
|
||||
_, err := handler.Thumb(context.Background(), "123.jpg")
|
||||
_, err := handler.Thumb(context.Background(), file)
|
||||
asserts.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package remote
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/driver"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/mocks/remoteclientmock"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||
"io"
|
||||
@@ -373,14 +374,33 @@ func TestHandler_Thumb(t *testing.T) {
|
||||
Type: "remote",
|
||||
SecretKey: "test",
|
||||
Server: "http://test.com",
|
||||
OptionsSerialized: model.PolicyOption{
|
||||
ThumbExts: []string{"txt"},
|
||||
},
|
||||
},
|
||||
AuthInstance: auth.HMACAuth{},
|
||||
}
|
||||
file := &model.File{
|
||||
Name: "1.txt",
|
||||
SourceName: "1.txt",
|
||||
}
|
||||
ctx := context.Background()
|
||||
asserts.NoError(cache.Set("setting_preview_timeout", "60", 0))
|
||||
resp, err := handler.Thumb(ctx, "/1.txt")
|
||||
asserts.NoError(err)
|
||||
asserts.True(resp.Redirect)
|
||||
|
||||
// no error
|
||||
{
|
||||
resp, err := handler.Thumb(ctx, file)
|
||||
asserts.NoError(err)
|
||||
asserts.True(resp.Redirect)
|
||||
}
|
||||
|
||||
// ext not support
|
||||
{
|
||||
file.Name = "1.jpg"
|
||||
resp, err := handler.Thumb(ctx, file)
|
||||
asserts.ErrorIs(err, driver.ErrorThumbNotSupported)
|
||||
asserts.Nil(resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_Token(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user