mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: test failed due to Policy.AutoName
This commit is contained in:
@@ -15,3 +15,10 @@ type File struct {
|
||||
PolicyID uint
|
||||
Dir string `gorm:"size:65536"`
|
||||
}
|
||||
|
||||
// GetFileByPathAndName 给定路径、文件名、用户ID,查找文件
|
||||
func GetFileByPathAndName(path string, name string, uid uint) (File, error) {
|
||||
var file File
|
||||
result := DB.Where("user_id = ? AND dir = ? AND name=?", uid, path, name).Find(&file)
|
||||
return file, result.Error
|
||||
}
|
||||
|
||||
18
models/file_test.go
Normal file
18
models/file_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetFileByPathAndName(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
fileRows := sqlmock.NewRows([]string{"id", "name"}).
|
||||
AddRow(1, "1.cia")
|
||||
mock.ExpectQuery("SELECT(.+)").WillReturnRows(fileRows)
|
||||
file, _ := GetFileByPathAndName("/", "1.cia", 1)
|
||||
asserts.Equal("1.cia", file.Name)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
}
|
||||
@@ -76,7 +76,9 @@ func TestPolicy_GeneratePath(t *testing.T) {
|
||||
|
||||
func TestPolicy_GenerateFileName(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
testPolicy := Policy{}
|
||||
testPolicy := Policy{
|
||||
AutoRename: true,
|
||||
}
|
||||
|
||||
testPolicy.FileNameRule = "{randomkey16}"
|
||||
asserts.Len(testPolicy.GenerateFileName(1, "123.txt"), 16)
|
||||
|
||||
Reference in New Issue
Block a user