Commit e7205c94 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix helpers.GetMapKey (it were using invalid type)

parent e0a77639
Pipeline #776676 failed with stage
......@@ -49,26 +49,21 @@ func ToConfigMap(list interface{}) (map[string]interface{}, bool) {
return result, true
}
func GetMapKey(value interface{}, keys ...string) (interface{}, bool) {
func GetMapKey(value map[string]interface{}, keys ...string) (result interface{}, ok bool) {
result = value
for _, key := range keys {
stringMap, ok := value.(map[string]interface{})
if ok {
value, ok = stringMap[key]
if !ok {
return nil, false
if stringMap, ok := result.(map[string]interface{}); ok {
if result, ok = stringMap[key]; ok {
continue
}
continue
}
interfaceMap, ok := value.(map[interface{}]interface{})
if ok {
value, ok = interfaceMap[key]
if !ok {
return nil, false
} else if interfaceMap, ok := result.(map[interface{}]interface{}); ok {
if result, ok = interfaceMap[key]; ok {
continue
}
continue
}
return nil, false
}
return value, true
return result, true
}
......@@ -91,21 +91,12 @@ test:
`
config1 := make(map[string]interface{})
config2 := make(map[interface{}]interface{})
require.NoError(t, yaml.Unmarshal([]byte(data), config1))
require.NoError(t, yaml.Unmarshal([]byte(data), config2))
value, ok := GetMapKey(config1, "test", "cache", "untracked")
assert.True(t, ok)
assert.Equal(t, true, value)
value, ok = GetMapKey(config2, "test", "cache", "untracked")
assert.True(t, ok)
assert.Equal(t, true, value)
_, ok = GetMapKey(config1, "test", "undefined", "untracked")
assert.False(t, ok)
_, ok = GetMapKey(config2, "test", "undefined", "untracked")
assert.False(t, ok)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment