diff --git a/pkg/filesystem/local/handller_test.go b/pkg/filesystem/local/handller_test.go index 6bfe7b6..7b8fcf3 100644 --- a/pkg/filesystem/local/handller_test.go +++ b/pkg/filesystem/local/handller_test.go @@ -135,7 +135,7 @@ func TestHandler_Source(t *testing.T) { ctx := context.WithValue(ctx, fsctx.FileModelCtx, file) baseURL, err := url.Parse("https://cloudreve.org") asserts.NoError(err) - sourceURL, err := handler.Source(ctx, "", *baseURL, 0, false) + sourceURL, err := handler.Source(ctx, "", *baseURL, 0, false, 0) asserts.NoError(err) asserts.NotEmpty(sourceURL) asserts.Contains(sourceURL, "sign=") @@ -146,7 +146,7 @@ func TestHandler_Source(t *testing.T) { { baseURL, err := url.Parse("https://cloudreve.org") asserts.NoError(err) - sourceURL, err := handler.Source(ctx, "", *baseURL, 0, false) + sourceURL, err := handler.Source(ctx, "", *baseURL, 0, false, 0) asserts.Error(err) asserts.Empty(sourceURL) } @@ -169,7 +169,7 @@ func TestHandler_GetDownloadURL(t *testing.T) { ctx := context.WithValue(ctx, fsctx.FileModelCtx, file) baseURL, err := url.Parse("https://cloudreve.org") asserts.NoError(err) - downloadURL, err := handler.Source(ctx, "", *baseURL, 10, true) + downloadURL, err := handler.Source(ctx, "", *baseURL, 10, true, 0) asserts.NoError(err) asserts.Contains(downloadURL, "sign=") asserts.Contains(downloadURL, "https://cloudreve.org") @@ -179,7 +179,7 @@ func TestHandler_GetDownloadURL(t *testing.T) { { baseURL, err := url.Parse("https://cloudreve.org") asserts.NoError(err) - downloadURL, err := handler.Source(ctx, "", *baseURL, 10, true) + downloadURL, err := handler.Source(ctx, "", *baseURL, 10, true, 0) asserts.Error(err) asserts.Empty(downloadURL) } diff --git a/pkg/filesystem/remote/handler_test.go b/pkg/filesystem/remote/handler_test.go index 9cbe9be..5a24465 100644 --- a/pkg/filesystem/remote/handler_test.go +++ b/pkg/filesystem/remote/handler_test.go @@ -5,8 +5,10 @@ import ( model "github.com/HFO4/cloudreve/models" "github.com/HFO4/cloudreve/pkg/auth" "github.com/HFO4/cloudreve/pkg/cache" + "github.com/HFO4/cloudreve/pkg/filesystem/fsctx" "github.com/HFO4/cloudreve/pkg/serializer" "github.com/stretchr/testify/assert" + "net/url" "testing" ) @@ -41,3 +43,45 @@ func TestHandler_Token(t *testing.T) { } } + +func TestHandler_Source(t *testing.T) { + asserts := assert.New(t) + auth.General = auth.HMACAuth{SecretKey: []byte("test")} + + // 无法获取上下文 + { + handler := Handler{} + ctx := context.Background() + res, err := handler.Source(ctx, "", url.URL{}, 0, true, 0) + asserts.Error(err) + asserts.Empty(res) + } + + // 成功 + { + handler := Handler{ + Policy: &model.Policy{Server: "/"}, + } + file := model.File{ + SourceName: "1.txt", + } + ctx := context.WithValue(context.Background(), fsctx.FileModelCtx, file) + res, err := handler.Source(ctx, "", url.URL{}, 10, true, 0) + asserts.NoError(err) + asserts.Contains(res, "api/v3/slave/download/0") + } + + // 成功 预览 + { + handler := Handler{ + Policy: &model.Policy{Server: "/"}, + } + file := model.File{ + SourceName: "1.txt", + } + ctx := context.WithValue(context.Background(), fsctx.FileModelCtx, file) + res, err := handler.Source(ctx, "", url.URL{}, 10, false, 0) + asserts.NoError(err) + asserts.Contains(res, "api/v3/slave/source/0") + } +}