mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 10:01:56 +08:00
Test: filesystem/file, filesystem, filesystem/hook, model/file/Create
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/local"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -45,3 +46,49 @@ func TestGenericBeforeUpload(t *testing.T) {
|
||||
ctx = context.WithValue(context.Background(), FileHeaderCtx, file)
|
||||
asserts.Error(GenericBeforeUpload(ctx, &fs))
|
||||
}
|
||||
|
||||
func TestGenericAfterUploadCanceled(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
f, err := os.Create("TestGenericAfterUploadCanceled")
|
||||
asserts.NoError(err)
|
||||
f.Close()
|
||||
file := local.FileStream{
|
||||
Size: 5,
|
||||
Name: "TestGenericAfterUploadCanceled",
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), SavePathCtx, "TestGenericAfterUploadCanceled")
|
||||
ctx = context.WithValue(ctx, FileHeaderCtx, file)
|
||||
fs := FileSystem{
|
||||
User: &model.User{Storage: 5},
|
||||
Handler: local.Handler{},
|
||||
}
|
||||
|
||||
// 成功
|
||||
err = GenericAfterUploadCanceled(ctx, &fs)
|
||||
asserts.NoError(err)
|
||||
asserts.Equal(uint64(0), fs.User.Storage)
|
||||
|
||||
f, err = os.Create("TestGenericAfterUploadCanceled")
|
||||
asserts.NoError(err)
|
||||
f.Close()
|
||||
|
||||
// 容量不能再降低
|
||||
err = GenericAfterUploadCanceled(ctx, &fs)
|
||||
asserts.Error(err)
|
||||
|
||||
//文件不存在
|
||||
fs.User.Storage = 5
|
||||
err = GenericAfterUploadCanceled(ctx, &fs)
|
||||
asserts.NoError(err)
|
||||
}
|
||||
|
||||
//func TestGenericAfterUpload(t *testing.T) {
|
||||
// asserts := assert.New(t)
|
||||
// testObj := FileSystem{}
|
||||
// ctx := context.WithValue(context.Background(),FileHeaderCtx,local.FileStream{
|
||||
// VirtualPath: "/我的文件",
|
||||
// Name: "test.txt",
|
||||
// })
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user