mirror of https://github.com/docker/cli.git
Merge b463a15f78
into 9861ce90fd
This commit is contained in:
commit
5380c0282a
|
@ -352,3 +352,26 @@ func (configFile *ConfigFile) SetPluginConfig(pluginname, option, value string)
|
|||
delete(configFile.Plugins, pluginname)
|
||||
}
|
||||
}
|
||||
|
||||
// GetFeature retrieves the given key from the config features map.
|
||||
func (configFile *ConfigFile) GetFeature(key string) (string, bool) {
|
||||
if configFile.Features == nil {
|
||||
return "", false
|
||||
}
|
||||
v, ok := configFile.Features[key]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// SetFeature sets the key to the given value in the config features map.
|
||||
// If the features field is nil, it initializes a new map.
|
||||
// Passing a value of "" will remove the key-value pair from the map.
|
||||
func (configFile *ConfigFile) SetFeature(key, value string) {
|
||||
if configFile.Features == nil {
|
||||
configFile.Features = make(map[string]string)
|
||||
}
|
||||
if value != "" {
|
||||
configFile.Features[key] = value
|
||||
} else {
|
||||
delete(configFile.Features, key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -602,3 +602,57 @@ func TestPluginConfig(t *testing.T) {
|
|||
assert.NilError(t, err)
|
||||
golden.Assert(t, string(cfg), "plugin-config-2.golden")
|
||||
}
|
||||
|
||||
func TestSetFeature(t *testing.T) {
|
||||
t.Run("new feature", func(t *testing.T) {
|
||||
configFile := &ConfigFile{}
|
||||
|
||||
configFile.SetFeature("foo", "bar")
|
||||
|
||||
assert.Equal(t, "bar", configFile.Features["foo"])
|
||||
})
|
||||
|
||||
t.Run("update key", func(t *testing.T) {
|
||||
configFile := &ConfigFile{}
|
||||
|
||||
configFile.SetFeature("foo", "bar")
|
||||
assert.Equal(t, "bar", configFile.Features["foo"])
|
||||
|
||||
configFile.SetFeature("foo", "baz")
|
||||
assert.Equal(t, "baz", configFile.Features["foo"])
|
||||
})
|
||||
|
||||
t.Run("remove feature", func(t *testing.T) {
|
||||
configFile := &ConfigFile{}
|
||||
|
||||
configFile.SetFeature("foo", "bar")
|
||||
assert.Equal(t, "bar", configFile.Features["foo"])
|
||||
|
||||
configFile.SetFeature("foo", "")
|
||||
_, exists := configFile.Features["foo"]
|
||||
assert.Check(t, !exists)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetFeature(t *testing.T) {
|
||||
t.Run("feature exists", func(t *testing.T) {
|
||||
configFile := &ConfigFile{}
|
||||
configFile.Features = map[string]string{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
f, ok := configFile.GetFeature("foo")
|
||||
|
||||
assert.Check(t, ok)
|
||||
assert.Equal(t, "bar", f)
|
||||
})
|
||||
|
||||
t.Run("missing feature", func(t *testing.T) {
|
||||
configFile := &ConfigFile{}
|
||||
|
||||
f, ok := configFile.GetFeature("baz")
|
||||
|
||||
assert.Check(t, !ok)
|
||||
assert.Equal(t, "", f)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue