mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
fs: add Features.Enabled to return map of enabled features by name
This commit is contained in:
parent
bd10344d65
commit
e1cf551ded
20
fs/fs.go
20
fs/fs.go
@ -618,6 +618,26 @@ func (ft *Features) List() (out []string) {
|
||||
return out
|
||||
}
|
||||
|
||||
// Enabled returns a map of features with keys showing whether they
|
||||
// are enabled or not
|
||||
func (ft *Features) Enabled() (features map[string]bool) {
|
||||
v := reflect.ValueOf(ft).Elem()
|
||||
vType := v.Type()
|
||||
features = make(map[string]bool, v.NumField())
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
vName := vType.Field(i).Name
|
||||
field := v.Field(i)
|
||||
if field.Kind() == reflect.Func {
|
||||
// Can't compare functions
|
||||
features[vName] = !field.IsNil()
|
||||
} else {
|
||||
zero := reflect.Zero(field.Type())
|
||||
features[vName] = field.Interface() != zero.Interface()
|
||||
}
|
||||
}
|
||||
return features
|
||||
}
|
||||
|
||||
// DisableList nil's out the comma separated list of named features.
|
||||
// If it isn't found then it will log a message.
|
||||
func (ft *Features) DisableList(list []string) *Features {
|
||||
|
@ -41,6 +41,31 @@ func TestFeaturesList(t *testing.T) {
|
||||
assert.True(t, strings.Contains(names, ",Copy,"))
|
||||
}
|
||||
|
||||
func TestFeaturesEnabled(t *testing.T) {
|
||||
ft := new(Features)
|
||||
ft.CaseInsensitive = true
|
||||
ft.Purge = func() error { return nil }
|
||||
enabled := ft.Enabled()
|
||||
|
||||
flag, ok := enabled["CaseInsensitive"]
|
||||
assert.Equal(t, true, ok)
|
||||
assert.Equal(t, true, flag, enabled)
|
||||
|
||||
flag, ok = enabled["Purge"]
|
||||
assert.Equal(t, true, ok)
|
||||
assert.Equal(t, true, flag, enabled)
|
||||
|
||||
flag, ok = enabled["DuplicateFiles"]
|
||||
assert.Equal(t, true, ok)
|
||||
assert.Equal(t, false, flag, enabled)
|
||||
|
||||
flag, ok = enabled["Copy"]
|
||||
assert.Equal(t, true, ok)
|
||||
assert.Equal(t, false, flag, enabled)
|
||||
|
||||
assert.Equal(t, len(ft.List()), len(enabled))
|
||||
}
|
||||
|
||||
func TestFeaturesDisableList(t *testing.T) {
|
||||
ft := new(Features)
|
||||
ft.Copy = func(src Object, remote string) (Object, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user