mirror of
https://github.com/rclone/rclone.git
synced 2025-11-23 21:44:49 +02:00
Before this change, if any code called fs.Fatal(f) then it would stop rclone as designed. However this is not appropriate when using the RC API - we want the error returned to the user. This change turns the fs.Fatal(f) call into a panic which is caught by the RC API handler and returned to the user as a 500 error.
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// These tests use the job framework so must be external to the module
|
|
|
|
package rc_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/rclone/rclone/fs/rc"
|
|
"github.com/rclone/rclone/fs/rc/jobs"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestInternalPanic(t *testing.T) {
|
|
ctx := context.Background()
|
|
call := rc.Calls.Get("rc/panic")
|
|
assert.NotNil(t, call)
|
|
in := rc.Params{}
|
|
_, out, err := jobs.NewJob(ctx, call.Fn, in)
|
|
require.Error(t, err)
|
|
assert.ErrorContains(t, err, "arbitrary error on input map[]")
|
|
assert.ErrorContains(t, err, "panic received:")
|
|
assert.Equal(t, rc.Params{}, out)
|
|
}
|
|
|
|
func TestInternalFatal(t *testing.T) {
|
|
ctx := context.Background()
|
|
call := rc.Calls.Get("rc/fatal")
|
|
assert.NotNil(t, call)
|
|
in := rc.Params{}
|
|
_, out, err := jobs.NewJob(ctx, call.Fn, in)
|
|
require.Error(t, err)
|
|
assert.ErrorContains(t, err, "arbitrary error on input map[]")
|
|
assert.ErrorContains(t, err, "panic received:")
|
|
assert.ErrorContains(t, err, "fatal error:")
|
|
assert.Equal(t, rc.Params{}, out)
|
|
}
|