parent
438ce02420
commit
7cb27b2102
@ -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)
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewFileSystem(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
user := model.User{
|
||||
Policy: model.Policy{
|
||||
Type: "local",
|
||||
},
|
||||
}
|
||||
|
||||
fs, err := NewFileSystem(&user)
|
||||
asserts.NoError(err)
|
||||
asserts.NotNil(fs.Handler)
|
||||
|
||||
user.Policy.Type = "unknown"
|
||||
fs, err = NewFileSystem(&user)
|
||||
asserts.Error(err)
|
||||
}
|
Loading…
Reference in new issue