mirror of
https://github.com/rclone/rclone.git
synced 2025-08-15 00:02:35 +02:00
rc: fix unmarshalable http.AuthFn in options and put in test for marshalability
This commit is contained in:
@ -2,16 +2,23 @@ package rc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rclone/rclone/cmd/serve/httplib"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func clearOptionBlock() {
|
||||
func clearOptionBlock() func() {
|
||||
oldOptionBlock := optionBlock
|
||||
optionBlock = map[string]interface{}{}
|
||||
return func() {
|
||||
optionBlock = oldOptionBlock
|
||||
}
|
||||
}
|
||||
|
||||
var testOptions = struct {
|
||||
@ -23,7 +30,7 @@ var testOptions = struct {
|
||||
}
|
||||
|
||||
func TestAddOption(t *testing.T) {
|
||||
defer clearOptionBlock()
|
||||
defer clearOptionBlock()()
|
||||
assert.Equal(t, len(optionBlock), 0)
|
||||
AddOption("potato", &testOptions)
|
||||
assert.Equal(t, len(optionBlock), 1)
|
||||
@ -32,7 +39,7 @@ func TestAddOption(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddOptionReload(t *testing.T) {
|
||||
defer clearOptionBlock()
|
||||
defer clearOptionBlock()()
|
||||
assert.Equal(t, len(optionBlock), 0)
|
||||
reload := func() error { return nil }
|
||||
AddOptionReload("potato", &testOptions, reload)
|
||||
@ -43,7 +50,7 @@ func TestAddOptionReload(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptionsBlocks(t *testing.T) {
|
||||
defer clearOptionBlock()
|
||||
defer clearOptionBlock()()
|
||||
AddOption("potato", &testOptions)
|
||||
call := Calls.Get("options/blocks")
|
||||
require.NotNil(t, call)
|
||||
@ -55,7 +62,7 @@ func TestOptionsBlocks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOptionsGet(t *testing.T) {
|
||||
defer clearOptionBlock()
|
||||
defer clearOptionBlock()()
|
||||
AddOption("potato", &testOptions)
|
||||
call := Calls.Get("options/get")
|
||||
require.NotNil(t, call)
|
||||
@ -66,8 +73,29 @@ func TestOptionsGet(t *testing.T) {
|
||||
assert.Equal(t, Params{"potato": &testOptions}, out)
|
||||
}
|
||||
|
||||
func TestOptionsGetMarshal(t *testing.T) {
|
||||
defer clearOptionBlock()()
|
||||
|
||||
// Add some real options
|
||||
AddOption("http", &httplib.DefaultOpt)
|
||||
AddOption("main", fs.Config)
|
||||
AddOption("rc", &DefaultOpt)
|
||||
|
||||
// get them
|
||||
call := Calls.Get("options/get")
|
||||
require.NotNil(t, call)
|
||||
in := Params{}
|
||||
out, err := call.Fn(context.Background(), in)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, out)
|
||||
|
||||
// Check that they marshal
|
||||
_, err = json.Marshal(out)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestOptionsSet(t *testing.T) {
|
||||
defer clearOptionBlock()
|
||||
defer clearOptionBlock()()
|
||||
var reloaded int
|
||||
AddOptionReload("potato", &testOptions, func() error {
|
||||
if reloaded > 0 {
|
||||
|
Reference in New Issue
Block a user