mirror of
https://github.com/rclone/rclone.git
synced 2024-12-24 13:03:51 +08:00
1cc22da87d
This almost 100% backwards compatible. The only difference being that in the rc options/get output CacheMode will be output as strings instead of integers. This is a lot more convenient for the user. They still accept integer inputs though so the fallout from this should be minimal.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package vfscommon
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/spf13/pflag"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// Check CacheMode it satisfies the pflag interface
|
|
var _ pflag.Value = (*CacheMode)(nil)
|
|
|
|
// Check CacheMode it satisfies the json.Unmarshaller interface
|
|
var _ json.Unmarshaler = (*CacheMode)(nil)
|
|
|
|
func TestCacheModeString(t *testing.T) {
|
|
assert.Equal(t, "off", CacheModeOff.String())
|
|
assert.Equal(t, "full", CacheModeFull.String())
|
|
assert.Equal(t, "Unknown(17)", CacheMode(17).String())
|
|
}
|
|
|
|
func TestCacheModeSet(t *testing.T) {
|
|
var m CacheMode
|
|
|
|
err := m.Set("full")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, CacheModeFull, m)
|
|
|
|
err = m.Set("potato")
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
|
|
err = m.Set("")
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
}
|
|
|
|
func TestCacheModeType(t *testing.T) {
|
|
var m CacheMode
|
|
assert.Equal(t, "CacheMode", m.Type())
|
|
}
|
|
|
|
func TestCacheModeUnmarshalJSON(t *testing.T) {
|
|
var m CacheMode
|
|
|
|
err := json.Unmarshal([]byte(`"full"`), &m)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, CacheModeFull, m)
|
|
|
|
err = json.Unmarshal([]byte(`"potato"`), &m)
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
|
|
err = json.Unmarshal([]byte(`""`), &m)
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
|
|
err = json.Unmarshal([]byte(strconv.Itoa(int(CacheModeFull))), &m)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, CacheModeFull, m)
|
|
|
|
err = json.Unmarshal([]byte("-1"), &m)
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
|
|
err = json.Unmarshal([]byte("99"), &m)
|
|
assert.Error(t, err, "Unknown cache mode level")
|
|
}
|