Test: pkg/task / Fix: failed test due to policy cache
This commit is contained in:
@@ -14,9 +14,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
testMock "github.com/stretchr/testify/mock"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -200,3 +202,30 @@ func TestFileSystem_GetUploadToken(t *testing.T) {
|
||||
asserts.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileSystem_UploadFromStream(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
fs := FileSystem{User: &model.User{Model: gorm.Model{ID: 1}}}
|
||||
ctx := context.Background()
|
||||
|
||||
err := fs.UploadFromStream(ctx, ioutil.NopCloser(strings.NewReader("123")), "/1.txt", 1)
|
||||
asserts.Error(err)
|
||||
}
|
||||
|
||||
func TestFileSystem_UploadFromPath(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
fs := FileSystem{User: &model.User{Policy: model.Policy{Type: "mock"}, Model: gorm.Model{ID: 1}}}
|
||||
ctx := context.Background()
|
||||
|
||||
// 文件不存在
|
||||
{
|
||||
err := fs.UploadFromPath(ctx, "test/not_exist", "/")
|
||||
asserts.Error(err)
|
||||
}
|
||||
|
||||
// 文存在,上传失败
|
||||
{
|
||||
err := fs.UploadFromPath(ctx, "tests/test.zip", "/")
|
||||
asserts.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user