mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: filesystem/local & filesystem/validator
This commit is contained in:
@@ -2,7 +2,6 @@ package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"io"
|
||||
"os"
|
||||
@@ -19,7 +18,6 @@ func (handler Handler) Put(ctx context.Context, file io.ReadCloser, dst string)
|
||||
// 如果目标目录不存在,创建
|
||||
basePath := filepath.Dir(dst)
|
||||
if !util.Exists(basePath) {
|
||||
fmt.Println("创建", basePath)
|
||||
err := os.MkdirAll(basePath, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
44
pkg/filesystem/local/handller_test.go
Normal file
44
pkg/filesystem/local/handller_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHandler_Put(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
handler := Handler{}
|
||||
ctx := context.Background()
|
||||
|
||||
testCases := []struct {
|
||||
file io.ReadCloser
|
||||
dst string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
file: ioutil.NopCloser(strings.NewReader("test input file")),
|
||||
dst: "test/test/txt",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
file: ioutil.NopCloser(strings.NewReader("test input file")),
|
||||
dst: "notexist:/S.TXT",
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
err := handler.Put(ctx, testCase.file, testCase.dst)
|
||||
if testCase.err {
|
||||
asserts.Error(err)
|
||||
} else {
|
||||
asserts.NoError(err)
|
||||
asserts.True(util.Exists(testCase.dst))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user