mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 06:14:35 +02:00
fix: --state-values-set unable to set booleans (#1199)
This pr fixes auto-wrapping of booleans and integers into quotes when using --state-values-set by: - Adding: --state-values-set-string flag for intentional string set of boolean or integer - Changing: --state-values-set flag not wrapping now - Removing - Resolves https://github.com/roboll/helmfile/issues/1347 Signed-off-by: Tunahan Sezen <sezentunahan@outlook.com>
This commit is contained in:
@@ -69,7 +69,7 @@ func TestMapUtil_KeyArg(t *testing.T) {
|
||||
|
||||
key := []string{"a", "b", "c"}
|
||||
|
||||
Set(m, key, "C")
|
||||
Set(m, key, "C", false)
|
||||
|
||||
c := (((m["a"].(map[string]any))["b"]).(map[string]any))["c"]
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestMapUtil_IndexedKeyArg(t *testing.T) {
|
||||
|
||||
key := []string{"a", "b[0]", "c"}
|
||||
|
||||
Set(m, key, "C")
|
||||
Set(m, key, "C", false)
|
||||
|
||||
c := (((m["a"].(map[string]any))["b"].([]any))[0].(map[string]any))["c"]
|
||||
|
||||
@@ -124,7 +124,7 @@ func TestMapUtil_IndexedKeyArg2(t *testing.T) {
|
||||
k := ParseKey(op[0])
|
||||
v := op[1]
|
||||
|
||||
Set(set, k, v)
|
||||
Set(set, k, v, false)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(set, c.want) {
|
||||
@@ -174,3 +174,77 @@ func TestMapUtil_ParseKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapUtil_typedVal(t *testing.T) {
|
||||
typedValueTest(t, "true", true)
|
||||
typedValueTest(t, "null", nil)
|
||||
typedValueTest(t, "0", int64(0))
|
||||
typedValueTest(t, "5", int64(5))
|
||||
typedValueTest(t, "05", "05")
|
||||
}
|
||||
|
||||
func typedValueTest(t *testing.T, input string, expectedWhenNoStr any) {
|
||||
returnValue := typedVal(input, true)
|
||||
if returnValue != input {
|
||||
t.Errorf("unexpected typed value: expected=%s, got=%s", input, returnValue)
|
||||
}
|
||||
returnValue = typedVal(input, false)
|
||||
if returnValue != expectedWhenNoStr {
|
||||
t.Errorf("unexpected typed value: expected=%s, got=%s", input, returnValue)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapUtil_MergeMaps(t *testing.T) {
|
||||
map1 := map[string]interface{}{
|
||||
"debug": true,
|
||||
}
|
||||
map2 := map[string]interface{}{
|
||||
"logLevel": "info",
|
||||
"replicaCount": 3,
|
||||
}
|
||||
map3 := map[string]interface{}{
|
||||
"logLevel": "info",
|
||||
"replicaCount": map[string]any{
|
||||
"app1": 3,
|
||||
"awesome": 4,
|
||||
},
|
||||
}
|
||||
map4 := map[string]interface{}{
|
||||
"logLevel": "info",
|
||||
"replicaCount": map[string]any{
|
||||
"app1": 3,
|
||||
},
|
||||
}
|
||||
|
||||
testMap := MergeMaps(map2, map4)
|
||||
equal := reflect.DeepEqual(testMap, map4)
|
||||
if !equal {
|
||||
t.Errorf("Expected a nested map to overwrite a flat value. Expected: %v, got %v", map4, testMap)
|
||||
}
|
||||
|
||||
testMap = MergeMaps(map4, map2)
|
||||
equal = reflect.DeepEqual(testMap, map2)
|
||||
if !equal {
|
||||
t.Errorf("Expected a flat value to overwrite a map. Expected: %v, got %v", map2, testMap)
|
||||
}
|
||||
|
||||
testMap = MergeMaps(map4, map3)
|
||||
equal = reflect.DeepEqual(testMap, map3)
|
||||
if !equal {
|
||||
t.Errorf("Expected a nested map to overwrite another nested map. Expected: %v, got %v", map3, testMap)
|
||||
}
|
||||
|
||||
testMap = MergeMaps(map1, map3)
|
||||
expectedMap := map[string]interface{}{
|
||||
"debug": true,
|
||||
"logLevel": "info",
|
||||
"replicaCount": map[string]any{
|
||||
"app1": 3,
|
||||
"awesome": 4,
|
||||
},
|
||||
}
|
||||
equal = reflect.DeepEqual(testMap, expectedMap)
|
||||
if !equal {
|
||||
t.Errorf("Expected a map with different keys to merge properly with another map. Expected: %v, got %v", expectedMap, testMap)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user