mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 08:54:10 +01:00
11da2a6c9b
The purpose of this is to make it easier to maintain and eventually to allow the rclone backends to be re-used in other projects without having to use the rclone configuration system. The new code layout is documented in CONTRIBUTING.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package fs
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/pflag"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// Check it satisfies the interface
|
|
var _ pflag.Value = (*Duration)(nil)
|
|
|
|
func TestParseDuration(t *testing.T) {
|
|
for _, test := range []struct {
|
|
in string
|
|
want float64
|
|
err bool
|
|
}{
|
|
{"0", 0, false},
|
|
{"", 0, true},
|
|
{"1ms", float64(time.Millisecond), false},
|
|
{"1s", float64(time.Second), false},
|
|
{"1m", float64(time.Minute), false},
|
|
{"1h", float64(time.Hour), false},
|
|
{"1d", float64(time.Hour) * 24, false},
|
|
{"1w", float64(time.Hour) * 24 * 7, false},
|
|
{"1M", float64(time.Hour) * 24 * 30, false},
|
|
{"1y", float64(time.Hour) * 24 * 365, false},
|
|
{"1.5y", float64(time.Hour) * 24 * 365 * 1.5, false},
|
|
{"-1s", -float64(time.Second), false},
|
|
{"1.s", float64(time.Second), false},
|
|
{"1x", 0, true},
|
|
} {
|
|
duration, err := ParseDuration(test.in)
|
|
if test.err {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
assert.Equal(t, test.want, float64(duration))
|
|
}
|
|
}
|