From 595f4a1350223de6a3db774159e1792c047268bb Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 21 Mar 2021 14:32:10 +0800 Subject: [PATCH] Test: get parament source in OneDrive handler --- .../driver/onedrive/handler_test.go | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/filesystem/driver/onedrive/handler_test.go b/pkg/filesystem/driver/onedrive/handler_test.go index 4f0bb97..ce64048 100644 --- a/pkg/filesystem/driver/onedrive/handler_test.go +++ b/pkg/filesystem/driver/onedrive/handler_test.go @@ -3,6 +3,7 @@ package onedrive import ( "context" "fmt" + "github.com/cloudreve/Cloudreve/v3/pkg/auth" "io" "io/ioutil" "net/http" @@ -135,7 +136,7 @@ func TestDriver_Source(t *testing.T) { // 失败 { - res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 0, true, 0) + res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 1, true, 0) asserts.Error(err) asserts.Empty(res) } @@ -144,7 +145,7 @@ func TestDriver_Source(t *testing.T) { { handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() handler.Client.Credential.AccessToken = "1" - cache.Set("onedrive_source_0_123.jpg", "res", 0) + cache.Set("onedrive_source_0_123.jpg", "res", 1) res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 0, true, 0) cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_") asserts.NoError(err) @@ -160,7 +161,7 @@ func TestDriver_Source(t *testing.T) { handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() handler.Client.Credential.AccessToken = "1" cache.Set(fmt.Sprintf("onedrive_source_file_%d_1", file.UpdatedAt.Unix()), "res", 0) - res, err := handler.Source(ctx, "123.jpg", url.URL{}, 0, true, 0) + res, err := handler.Source(ctx, "123.jpg", url.URL{}, 1, true, 0) cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_") asserts.NoError(err) asserts.Equal("res", res) @@ -185,10 +186,25 @@ func TestDriver_Source(t *testing.T) { }) handler.Client.Request = clientMock handler.Client.Credential.AccessToken = "1" - res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 0, true, 0) + res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 1, true, 0) asserts.NoError(err) asserts.Equal("123321", res) } + + // 成功 永久直链 + { + file := model.File{} + file.ID = 1 + file.Name = "123.jpg" + file.UpdatedAt = time.Now() + ctx := context.WithValue(context.Background(), fsctx.FileModelCtx, file) + handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() + auth.General = auth.HMACAuth{} + handler.Client.Credential.AccessToken = "1" + res, err := handler.Source(ctx, "123.jpg", url.URL{}, 0, true, 0) + asserts.NoError(err) + asserts.Contains(res, "/api/v3/file/source/1/123.jpg?sign") + } } func TestDriver_List(t *testing.T) {