mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: filesystem/file, filesystem, filesystem/hook, model/file/Create
This commit is contained in:
52
pkg/filesystem/file_test.go
Normal file
52
pkg/filesystem/file_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/local"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileSystem_AddFile(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
file := local.FileData{
|
||||
Size: 5,
|
||||
Name: "1.txt",
|
||||
}
|
||||
folder := model.Folder{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
PositionAbsolute: "/我的文件",
|
||||
}
|
||||
fs := FileSystem{
|
||||
User: &model.User{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
Policy: model.Policy{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), FileHeaderCtx, file)
|
||||
ctx = context.WithValue(ctx, SavePathCtx, "/Uploads/1_sad.txt")
|
||||
|
||||
_, err := fs.AddFile(ctx, &folder)
|
||||
|
||||
asserts.Error(err)
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("INSERT(.+)").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
|
||||
f, err := fs.AddFile(ctx, &folder)
|
||||
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("/Uploads/1_sad.txt", f.SourceName)
|
||||
}
|
||||
Reference in New Issue
Block a user