mirror of
https://github.com/rclone/rclone.git
synced 2024-12-24 07:59:07 +01:00
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
|
package accounting
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/ncw/rclone/fs/rc"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"golang.org/x/time/rate"
|
||
|
)
|
||
|
|
||
|
func TestRcBwLimit(t *testing.T) {
|
||
|
call := rc.Calls.Get("core/bwlimit")
|
||
|
assert.NotNil(t, call)
|
||
|
|
||
|
// Set
|
||
|
in := rc.Params{
|
||
|
"rate": "1M",
|
||
|
}
|
||
|
out, err := call.Fn(context.Background(), in)
|
||
|
require.NoError(t, err)
|
||
|
assert.Equal(t, rc.Params{
|
||
|
"bytesPerSecond": int64(1048576),
|
||
|
"rate": "1M",
|
||
|
}, out)
|
||
|
assert.Equal(t, rate.Limit(1048576), tokenBucket.Limit())
|
||
|
|
||
|
// Query
|
||
|
in = rc.Params{}
|
||
|
out, err = call.Fn(context.Background(), in)
|
||
|
require.NoError(t, err)
|
||
|
assert.Equal(t, rc.Params{
|
||
|
"bytesPerSecond": int64(1048576),
|
||
|
"rate": "1M",
|
||
|
}, out)
|
||
|
|
||
|
// Reset
|
||
|
in = rc.Params{
|
||
|
"rate": "off",
|
||
|
}
|
||
|
out, err = call.Fn(context.Background(), in)
|
||
|
require.NoError(t, err)
|
||
|
assert.Equal(t, rc.Params{
|
||
|
"bytesPerSecond": int64(-1),
|
||
|
"rate": "off",
|
||
|
}, out)
|
||
|
assert.Nil(t, tokenBucket)
|
||
|
|
||
|
// Query
|
||
|
in = rc.Params{}
|
||
|
out, err = call.Fn(context.Background(), in)
|
||
|
require.NoError(t, err)
|
||
|
assert.Equal(t, rc.Params{
|
||
|
"bytesPerSecond": int64(-1),
|
||
|
"rate": "off",
|
||
|
}, out)
|
||
|
|
||
|
}
|