mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Test: new changes in model pkg
This commit is contained in:
@@ -104,7 +104,7 @@ func TestPolicy_GenerateFileName(t *testing.T) {
|
||||
asserts.Equal("123.txt", testPolicy.GenerateFileName(1, "123.txt"))
|
||||
|
||||
testPolicy.Type = "oss"
|
||||
asserts.Equal("${filename}", testPolicy.GenerateFileName(1, ""))
|
||||
asserts.Equal("origin", testPolicy.GenerateFileName(1, "origin"))
|
||||
}
|
||||
|
||||
// 重命名开启
|
||||
@@ -145,19 +145,23 @@ func TestPolicy_GenerateFileName(t *testing.T) {
|
||||
|
||||
testPolicy.Type = "oss"
|
||||
testPolicy.FileNameRule = "{uid}123{originname}"
|
||||
asserts.Equal("1123${filename}", testPolicy.GenerateFileName(1, ""))
|
||||
asserts.Equal("1123123321", testPolicy.GenerateFileName(1, "123321"))
|
||||
|
||||
testPolicy.Type = "upyun"
|
||||
testPolicy.FileNameRule = "{uid}123{originname}"
|
||||
asserts.Equal("1123{filename}{.suffix}", testPolicy.GenerateFileName(1, ""))
|
||||
asserts.Equal("1123123321", testPolicy.GenerateFileName(1, "123321"))
|
||||
|
||||
testPolicy.Type = "qiniu"
|
||||
testPolicy.FileNameRule = "{uid}123{originname}"
|
||||
asserts.Equal("1123$(fname)", testPolicy.GenerateFileName(1, ""))
|
||||
asserts.Equal("1123123321", testPolicy.GenerateFileName(1, "123321"))
|
||||
|
||||
testPolicy.Type = "local"
|
||||
testPolicy.FileNameRule = "{uid}123{originname}"
|
||||
asserts.Equal("1123", testPolicy.GenerateFileName(1, ""))
|
||||
|
||||
testPolicy.Type = "local"
|
||||
testPolicy.FileNameRule = "{ext}123{uuid}"
|
||||
asserts.Contains(testPolicy.GenerateFileName(1, "123.txt"), ".txt123")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -170,78 +174,6 @@ func TestPolicy_IsDirectlyPreview(t *testing.T) {
|
||||
asserts.False(policy.IsDirectlyPreview())
|
||||
}
|
||||
|
||||
func TestPolicy_GetUploadURL(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 本地
|
||||
{
|
||||
cache.Set("setting_siteURL", "http://127.0.0.1", 0)
|
||||
policy := Policy{Type: "local", Server: "http://127.0.0.1"}
|
||||
asserts.Equal("/api/v3/file/upload", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// 远程
|
||||
{
|
||||
policy := Policy{Type: "remote", Server: "http://127.0.0.1"}
|
||||
asserts.Equal("http://127.0.0.1/api/v3/slave/upload", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// OSS
|
||||
{
|
||||
policy := Policy{Type: "oss", BucketName: "base", Server: "127.0.0.1"}
|
||||
asserts.Equal("https://base.127.0.0.1", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// cos
|
||||
{
|
||||
policy := Policy{Type: "cos", BaseURL: "base", Server: "http://127.0.0.1"}
|
||||
asserts.Equal("http://127.0.0.1", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// upyun
|
||||
{
|
||||
policy := Policy{Type: "upyun", BucketName: "base", Server: "http://127.0.0.1"}
|
||||
asserts.Equal("https://v0.api.upyun.com/base", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// 未知
|
||||
{
|
||||
policy := Policy{Type: "unknown", Server: "http://127.0.0.1"}
|
||||
asserts.Equal("http://127.0.0.1", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// S3 未填写自动生成
|
||||
{
|
||||
policy := Policy{
|
||||
Type: "s3",
|
||||
Server: "",
|
||||
BucketName: "bucket",
|
||||
OptionsSerialized: PolicyOption{Region: "us-east"},
|
||||
}
|
||||
asserts.Equal("https://bucket.s3.us-east.amazonaws.com/", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
// s3 自己指定
|
||||
{
|
||||
policy := Policy{
|
||||
Type: "s3",
|
||||
Server: "https://s3.us-east.amazonaws.com/",
|
||||
BucketName: "bucket",
|
||||
OptionsSerialized: PolicyOption{Region: "us-east"},
|
||||
}
|
||||
asserts.Equal("https://s3.us-east.amazonaws.com/bucket", policy.GetUploadURL())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestPolicy_IsPathGenerateNeeded(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
policy := Policy{Type: "qiniu"}
|
||||
asserts.True(policy.IsPathGenerateNeeded())
|
||||
policy.Type = "remote"
|
||||
asserts.False(policy.IsPathGenerateNeeded())
|
||||
}
|
||||
|
||||
func TestPolicy_ClearCache(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
cache.Set("policy_202", 1, 0)
|
||||
@@ -266,15 +198,18 @@ func TestPolicy_UpdateAccessKey(t *testing.T) {
|
||||
func TestPolicy_Props(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
policy := Policy{Type: "onedrive"}
|
||||
policy.OptionsSerialized.PlaceholderWithSize = true
|
||||
asserts.False(policy.IsThumbGenerateNeeded())
|
||||
asserts.True(policy.IsPathGenerateNeeded())
|
||||
asserts.True(policy.IsTransitUpload(4))
|
||||
asserts.False(policy.IsTransitUpload(4))
|
||||
asserts.False(policy.IsTransitUpload(5 * 1024 * 1024))
|
||||
asserts.True(policy.CanStructureBeListed())
|
||||
asserts.True(policy.IsUploadPlaceholderWithSize())
|
||||
policy.Type = "local"
|
||||
asserts.True(policy.IsThumbGenerateNeeded())
|
||||
asserts.True(policy.IsPathGenerateNeeded())
|
||||
asserts.False(policy.CanStructureBeListed())
|
||||
asserts.False(policy.IsUploadPlaceholderWithSize())
|
||||
policy.Type = "remote"
|
||||
asserts.True(policy.IsUploadPlaceholderWithSize())
|
||||
}
|
||||
|
||||
func TestPolicy_IsThumbExist(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user