1
mirror of https://github.com/rclone/rclone synced 2024-12-25 17:03:45 +01:00

fstests: treat accountUpgradeRequired as success for OneDrive PublicLink

This commit is contained in:
Cnly 2021-07-27 17:03:51 +08:00 committed by Nick Craig-Wood
parent 80e47be65f
commit 51c952654c

View File

@ -441,6 +441,10 @@ func Run(t *testing.T, opt *Opt) {
} }
require.NoError(t, err, fmt.Sprintf("unexpected error: %v", err)) require.NoError(t, err, fmt.Sprintf("unexpected error: %v", err))
// Get fsInfo which contains type, etc. of the fs
fsInfo, _, _, _, err := fs.ConfigFs(subRemoteName)
require.NoError(t, err, fmt.Sprintf("unexpected error: %v", err))
// Skip the rest if it failed // Skip the rest if it failed
skipIfNotOk(t) skipIfNotOk(t)
@ -1587,12 +1591,30 @@ func Run(t *testing.T, opt *Opt) {
t.Run("PublicLink", func(t *testing.T) { t.Run("PublicLink", func(t *testing.T) {
skipIfNotOk(t) skipIfNotOk(t)
doPublicLink := f.Features().PublicLink publicLinkFunc := f.Features().PublicLink
if doPublicLink == nil { if publicLinkFunc == nil {
t.Skip("FS has no PublicLinker interface") t.Skip("FS has no PublicLinker interface")
} }
type PublicLinkFunc func(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error)
wrapPublicLinkFunc := func(f PublicLinkFunc) PublicLinkFunc {
return func(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error) {
link, err = publicLinkFunc(ctx, remote, expire, unlink)
if err == nil {
return
}
// For OneDrive Personal, link expiry is a premium feature
// Don't let it fail the test (https://github.com/rclone/rclone/issues/5420)
if fsInfo.Name == "onedrive" && strings.Contains(err.Error(), "accountUpgradeRequired") {
t.Log("treating accountUpgradeRequired as success for PublicLink")
link, err = "bogus link to "+remote, nil
}
return
}
}
expiry := fs.Duration(60 * time.Second) expiry := fs.Duration(60 * time.Second)
doPublicLink := wrapPublicLinkFunc(publicLinkFunc)
// if object not found // if object not found
link, err := doPublicLink(ctx, file1.Path+"_does_not_exist", expiry, false) link, err := doPublicLink(ctx, file1.Path+"_does_not_exist", expiry, false)
@ -1639,7 +1661,7 @@ func Run(t *testing.T, opt *Opt) {
_, err = subRemote.Put(ctx, buf, obji) _, err = subRemote.Put(ctx, buf, obji)
require.NoError(t, err) require.NoError(t, err)
link4, err := subRemote.Features().PublicLink(ctx, "", expiry, false) link4, err := wrapPublicLinkFunc(subRemote.Features().PublicLink)(ctx, "", expiry, false)
require.NoError(t, err, "Sharing root in a sub-remote should work") require.NoError(t, err, "Sharing root in a sub-remote should work")
require.NotEqual(t, "", link4, "Link should not be empty") require.NotEqual(t, "", link4, "Link should not be empty")
} }