test: search file with limited parent ids
This commit is contained in:
parent
a31ac2299a
commit
0e5683bc3b
5 changed files with 33 additions and 4 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 1d11ce88ad85cceda1273da9ed8643f1ce3b6ee4
|
Subproject commit 2d20892994d041953cecaba1ecc2d8be7abd5a4a
|
|
@ -148,7 +148,7 @@ func GetFilesByKeywords(uid uint, parents []uint, keywords ...interface{}) ([]Fi
|
||||||
|
|
||||||
// GetChildFilesOfFolders 批量检索目录子文件
|
// GetChildFilesOfFolders 批量检索目录子文件
|
||||||
func GetChildFilesOfFolders(folders *[]Folder) ([]File, error) {
|
func GetChildFilesOfFolders(folders *[]Folder) ([]File, error) {
|
||||||
// 将所有待删除目录ID抽离,以便检索文件
|
// 将所有待检索目录ID抽离,以便检索文件
|
||||||
folderIDs := make([]uint, 0, len(*folders))
|
folderIDs := make([]uint, 0, len(*folders))
|
||||||
for _, value := range *folders {
|
for _, value := range *folders {
|
||||||
folderIDs = append(folderIDs, value.ID)
|
folderIDs = append(folderIDs, value.ID)
|
||||||
|
|
|
@ -561,7 +561,7 @@ func TestGetFilesByKeywords(t *testing.T) {
|
||||||
// 未指定用户
|
// 未指定用户
|
||||||
{
|
{
|
||||||
mock.ExpectQuery("SELECT(.+)").WithArgs("k1", "k2").WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))
|
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(mock.ExpectationsWereMet())
|
||||||
asserts.NoError(err)
|
asserts.NoError(err)
|
||||||
asserts.Len(res, 1)
|
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))
|
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(mock.ExpectationsWereMet())
|
||||||
asserts.NoError(err)
|
asserts.NoError(err)
|
||||||
asserts.Len(res, 1)
|
asserts.Len(res, 1)
|
||||||
|
|
|
@ -63,6 +63,7 @@ type PolicyOption struct {
|
||||||
PlaceholderWithSize bool `json:"placeholder_with_size,omitempty"`
|
PlaceholderWithSize bool `json:"placeholder_with_size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// thumbSuffix 支持缩略图处理的文件扩展名
|
||||||
var thumbSuffix = map[string][]string{
|
var thumbSuffix = map[string][]string{
|
||||||
"local": {},
|
"local": {},
|
||||||
"qiniu": {".psd", ".jpg", ".jpeg", ".png", ".gif", ".webp", ".tiff", ".bmp"},
|
"qiniu": {".psd", ".jpg", ".jpeg", ".png", ".gif", ".webp", ".tiff", ".bmp"},
|
||||||
|
|
|
@ -671,6 +671,25 @@ func TestHookPopPlaceholderToFile(t *testing.T) {
|
||||||
a.NoError(mock.ExpectationsWereMet())
|
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) {
|
func TestHookDeleteUploadSession(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
fs := &FileSystem{}
|
fs := &FileSystem{}
|
||||||
|
|
Loading…
Add table
Reference in a new issue