Test: pkg/task / Fix: failed test due to policy cache

This commit is contained in:
HFO4
2020-02-07 11:47:52 +08:00
parent fc5b7d42c8
commit 4c530a26a0
14 changed files with 309 additions and 57 deletions

View File

@@ -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)
}
}