Skip to content

Commit

Permalink
test: search file with limited parent ids
Browse files Browse the repository at this point in the history
  • Loading branch information
HFO4 committed Apr 30, 2022
1 parent a31ac22 commit 0e5683b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions models/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions models/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
19 changes: 19 additions & 0 deletions pkg/filesystem/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 0e5683b

Please sign in to comment.