Test: get parament source in OneDrive handler

pull/807/head
HFO4 4 years ago
parent a5f80a4431
commit 595f4a1350

@ -3,6 +3,7 @@ package onedrive
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/cloudreve/Cloudreve/v3/pkg/auth"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "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.Error(err)
asserts.Empty(res) 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.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
handler.Client.Credential.AccessToken = "1" 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) res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 0, true, 0)
cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_") cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_")
asserts.NoError(err) 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.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
handler.Client.Credential.AccessToken = "1" handler.Client.Credential.AccessToken = "1"
cache.Set(fmt.Sprintf("onedrive_source_file_%d_1", file.UpdatedAt.Unix()), "res", 0) 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_") cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_")
asserts.NoError(err) asserts.NoError(err)
asserts.Equal("res", res) asserts.Equal("res", res)
@ -185,10 +186,25 @@ func TestDriver_Source(t *testing.T) {
}) })
handler.Client.Request = clientMock handler.Client.Request = clientMock
handler.Client.Credential.AccessToken = "1" 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.NoError(err)
asserts.Equal("123321", res) 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) { func TestDriver_List(t *testing.T) {

Loading…
Cancel
Save