1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 18:43:50 +00:00

fs: enable configmap to be able to tell values set vs config file values #4996

This adds AddOverrideGetter and GetOverride methods to config map and
uses them in fs.ConfigMap.

This enables us to tell which values have been set and which are just
read from the config file or at their defaults.

This also deletes the unused AddGetters method in configmap.
This commit is contained in:
Nick Craig-Wood
2021-03-10 12:17:08 +00:00
parent 96207f342c
commit f111e0eaf8
3 changed files with 80 additions and 12 deletions

View File

@@ -90,6 +90,56 @@ func TestConfigMapSet(t *testing.T) {
}, m2)
}
func TestConfigMapGetOverride(t *testing.T) {
m := New()
value, found := m.GetOverride("config1")
assert.Equal(t, "", value)
assert.Equal(t, false, found)
value, found = m.GetOverride("config2")
assert.Equal(t, "", value)
assert.Equal(t, false, found)
m1 := Simple{
"config1": "one",
}
m.AddOverrideGetter(m1)
value, found = m.GetOverride("config1")
assert.Equal(t, "one", value)
assert.Equal(t, true, found)
value, found = m.GetOverride("config2")
assert.Equal(t, "", value)
assert.Equal(t, false, found)
m2 := Simple{
"config1": "one2",
"config2": "two2",
}
m.AddGetter(m2)
value, found = m.GetOverride("config1")
assert.Equal(t, "one", value)
assert.Equal(t, true, found)
value, found = m.GetOverride("config2")
assert.Equal(t, "", value)
assert.Equal(t, false, found)
value, found = m.Get("config1")
assert.Equal(t, "one", value)
assert.Equal(t, true, found)
value, found = m.Get("config2")
assert.Equal(t, "two2", value)
assert.Equal(t, true, found)
}
func TestSimpleString(t *testing.T) {
// Basic
assert.Equal(t, "", Simple(nil).String())