From 0e5683bc3b102a474b03992eb7932ac12643bcd1 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 30 Apr 2022 10:02:57 +0800 Subject: [PATCH] test: search file with limited parent ids --- assets | 2 +- models/file.go | 2 +- models/file_test.go | 13 +++++++++++-- models/policy.go | 1 + pkg/filesystem/hooks_test.go | 19 +++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/assets b/assets index 1d11ce8..2d20892 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 1d11ce88ad85cceda1273da9ed8643f1ce3b6ee4 +Subproject commit 2d20892994d041953cecaba1ecc2d8be7abd5a4a diff --git a/models/file.go b/models/file.go index c4beeb8..34dad78 100644 --- a/models/file.go +++ b/models/file.go @@ -148,7 +148,7 @@ func GetFilesByKeywords(uid uint, parents []uint, keywords ...interface{}) ([]Fi // GetChildFilesOfFolders 批量检索目录子文件 func GetChildFilesOfFolders(folders *[]Folder) ([]File, error) { - // 将所有待删除目录ID抽离,以便检索文件 + // 将所有待检索目录ID抽离,以便检索文件 folderIDs := make([]uint, 0, len(*folders)) for _, value := range *folders { folderIDs = append(folderIDs, value.ID) diff --git a/models/file_test.go b/models/file_test.go index 68bf89c..b421763 100644 --- a/models/file_test.go +++ b/models/file_test.go @@ -561,7 +561,7 @@ func TestGetFilesByKeywords(t *testing.T) { // 未指定用户 { mock.ExpectQuery("SELECT(.+)").WithArgs("k1", "k2").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) - res, err := GetFilesByKeywords(0, "k1", "k2") + res, err := GetFilesByKeywords(0, nil, "k1", "k2") asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(err) asserts.Len(res, 1) @@ -570,7 +570,16 @@ func TestGetFilesByKeywords(t *testing.T) { // 指定用户 { mock.ExpectQuery("SELECT(.+)").WithArgs(1, "k1", "k2").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) - res, err := GetFilesByKeywords(1, "k1", "k2") + res, err := GetFilesByKeywords(1, nil, "k1", "k2") + asserts.NoError(mock.ExpectationsWereMet()) + asserts.NoError(err) + asserts.Len(res, 1) + } + + // 指定父目录 + { + mock.ExpectQuery("SELECT(.+)").WithArgs(1, 12, "k1", "k2").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1)) + res, err := GetFilesByKeywords(1, []uint{12}, "k1", "k2") asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(err) asserts.Len(res, 1) diff --git a/models/policy.go b/models/policy.go index a5f4826..1338a66 100644 --- a/models/policy.go +++ b/models/policy.go @@ -63,6 +63,7 @@ type PolicyOption struct { PlaceholderWithSize bool `json:"placeholder_with_size,omitempty"` } +// thumbSuffix 支持缩略图处理的文件扩展名 var thumbSuffix = map[string][]string{ "local": {}, "qiniu": {".psd", ".jpg", ".jpeg", ".png", ".gif", ".webp", ".tiff", ".bmp"}, diff --git a/pkg/filesystem/hooks_test.go b/pkg/filesystem/hooks_test.go index bf82d4c..b8f2d63 100644 --- a/pkg/filesystem/hooks_test.go +++ b/pkg/filesystem/hooks_test.go @@ -671,6 +671,25 @@ func TestHookPopPlaceholderToFile(t *testing.T) { a.NoError(mock.ExpectationsWereMet()) } +func TestHookPopPlaceholderToFileBySuffix(t *testing.T) { + a := assert.New(t) + fs := &FileSystem{ + Policy: &model.Policy{Type: "cos"}, + } + file := &fsctx.FileStream{ + Name: "1.png", + Model: &model.File{ + Model: gorm.Model{ID: 1}, + }, + } + + mock.ExpectBegin() + mock.ExpectExec("UPDATE(.+)files(.+)").WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectCommit() + a.NoError(HookPopPlaceholderToFile("")(context.Background(), fs, file)) + a.NoError(mock.ExpectationsWereMet()) +} + func TestHookDeleteUploadSession(t *testing.T) { a := assert.New(t) fs := &FileSystem{}