2019-06-24 20:18:52 +08:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs/rc"
|
2019-06-24 20:18:52 +08:00
|
|
|
"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)
|
2020-07-05 00:20:54 +08:00
|
|
|
assert.Equal(t, rate.Limit(1048576), TokenBucket.curr[0].Limit())
|
2019-06-24 20:18:52 +08:00
|
|
|
|
|
|
|
// 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)
|
2020-07-05 00:20:54 +08:00
|
|
|
assert.Nil(t, TokenBucket.curr[0])
|
2019-06-24 20:18:52 +08:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
}
|