mirror of https://github.com/cloudreve/Cloudreve
Test: Policy.IsThumbExist / filesystem.AddFile
parent
304e7b502c
commit
8c3287d380
|
@ -242,13 +242,62 @@ func TestPolicy_UpdateAccessKey(t *testing.T) {
|
||||||
func TestPolicy_Props(t *testing.T) {
|
func TestPolicy_Props(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
policy := Policy{Type: "onedrive"}
|
policy := Policy{Type: "onedrive"}
|
||||||
asserts.True(policy.IsMockThumbNeeded())
|
|
||||||
asserts.False(policy.IsThumbGenerateNeeded())
|
asserts.False(policy.IsThumbGenerateNeeded())
|
||||||
asserts.True(policy.IsPathGenerateNeeded())
|
asserts.True(policy.IsPathGenerateNeeded())
|
||||||
asserts.True(policy.IsTransitUpload(4))
|
asserts.True(policy.IsTransitUpload(4))
|
||||||
asserts.False(policy.IsTransitUpload(5 * 1024 * 1024))
|
asserts.False(policy.IsTransitUpload(5 * 1024 * 1024))
|
||||||
policy.Type = "local"
|
policy.Type = "local"
|
||||||
asserts.False(policy.IsMockThumbNeeded())
|
|
||||||
asserts.True(policy.IsThumbGenerateNeeded())
|
asserts.True(policy.IsThumbGenerateNeeded())
|
||||||
asserts.True(policy.IsPathGenerateNeeded())
|
asserts.True(policy.IsPathGenerateNeeded())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPolicy_IsThumbExist(t *testing.T) {
|
||||||
|
asserts := assert.New(t)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
expect bool
|
||||||
|
policy string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"1.png",
|
||||||
|
false,
|
||||||
|
"unknown",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1.png",
|
||||||
|
false,
|
||||||
|
"local",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1.png",
|
||||||
|
true,
|
||||||
|
"cos",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1",
|
||||||
|
false,
|
||||||
|
"cos",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1.txt.png",
|
||||||
|
true,
|
||||||
|
"cos",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1.png.txt",
|
||||||
|
false,
|
||||||
|
"cos",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"1",
|
||||||
|
true,
|
||||||
|
"onedrive",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
policy := Policy{Type: testCase.policy}
|
||||||
|
asserts.Equal(testCase.expect, policy.IsThumbExist(testCase.name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestFileSystem_AddFile(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
file := local.FileStream{
|
file := local.FileStream{
|
||||||
Size: 5,
|
Size: 5,
|
||||||
Name: "1.txt",
|
Name: "1.png",
|
||||||
}
|
}
|
||||||
folder := model.Folder{
|
folder := model.Folder{
|
||||||
Model: gorm.Model{
|
Model: gorm.Model{
|
||||||
|
@ -33,6 +33,7 @@ func TestFileSystem_AddFile(t *testing.T) {
|
||||||
ID: 1,
|
ID: 1,
|
||||||
},
|
},
|
||||||
Policy: model.Policy{
|
Policy: model.Policy{
|
||||||
|
Type: "cos",
|
||||||
Model: gorm.Model{
|
Model: gorm.Model{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
},
|
},
|
||||||
|
@ -40,7 +41,7 @@ func TestFileSystem_AddFile(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(context.Background(), fsctx.FileHeaderCtx, file)
|
ctx := context.WithValue(context.Background(), fsctx.FileHeaderCtx, file)
|
||||||
ctx = context.WithValue(ctx, fsctx.SavePathCtx, "/Uploads/1_sad.txt")
|
ctx = context.WithValue(ctx, fsctx.SavePathCtx, "/Uploads/1_sad.png")
|
||||||
|
|
||||||
_, err := fs.AddFile(ctx, &folder)
|
_, err := fs.AddFile(ctx, &folder)
|
||||||
|
|
||||||
|
@ -54,7 +55,8 @@ func TestFileSystem_AddFile(t *testing.T) {
|
||||||
|
|
||||||
asserts.NoError(err)
|
asserts.NoError(err)
|
||||||
asserts.NoError(mock.ExpectationsWereMet())
|
asserts.NoError(mock.ExpectationsWereMet())
|
||||||
asserts.Equal("/Uploads/1_sad.txt", f.SourceName)
|
asserts.Equal("/Uploads/1_sad.png", f.SourceName)
|
||||||
|
asserts.NotEmpty(f.PicInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileSystem_GetContent(t *testing.T) {
|
func TestFileSystem_GetContent(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue