diff --git a/models/policy_test.go b/models/policy_test.go index ba92bab..be7193f 100644 --- a/models/policy_test.go +++ b/models/policy_test.go @@ -242,13 +242,62 @@ func TestPolicy_UpdateAccessKey(t *testing.T) { func TestPolicy_Props(t *testing.T) { asserts := assert.New(t) policy := Policy{Type: "onedrive"} - asserts.True(policy.IsMockThumbNeeded()) asserts.False(policy.IsThumbGenerateNeeded()) asserts.True(policy.IsPathGenerateNeeded()) asserts.True(policy.IsTransitUpload(4)) asserts.False(policy.IsTransitUpload(5 * 1024 * 1024)) policy.Type = "local" - asserts.False(policy.IsMockThumbNeeded()) asserts.True(policy.IsThumbGenerateNeeded()) 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)) + } +} diff --git a/pkg/filesystem/file_test.go b/pkg/filesystem/file_test.go index 8c48ec7..efb4c9b 100644 --- a/pkg/filesystem/file_test.go +++ b/pkg/filesystem/file_test.go @@ -20,7 +20,7 @@ func TestFileSystem_AddFile(t *testing.T) { asserts := assert.New(t) file := local.FileStream{ Size: 5, - Name: "1.txt", + Name: "1.png", } folder := model.Folder{ Model: gorm.Model{ @@ -33,6 +33,7 @@ func TestFileSystem_AddFile(t *testing.T) { ID: 1, }, Policy: model.Policy{ + Type: "cos", Model: gorm.Model{ ID: 1, }, @@ -40,7 +41,7 @@ func TestFileSystem_AddFile(t *testing.T) { }, } 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) @@ -54,7 +55,8 @@ func TestFileSystem_AddFile(t *testing.T) { asserts.NoError(err) 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) {