-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: merge environment values by ovewriting with empty values (#1162)
Fixes #1154
- Loading branch information
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package environment | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"testing" | ||
) | ||
|
||
// See https://github.com/roboll/helmfile/issues/1150 | ||
func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) { | ||
dst := &Environment{ | ||
Name: "dst", | ||
Values: map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": nil, | ||
}, | ||
}, | ||
Defaults: nil, | ||
} | ||
|
||
src := &Environment{ | ||
Name: "src", | ||
Values: map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": map[string]interface{}{ | ||
"version": "0.10.3", | ||
}, | ||
}, | ||
}, | ||
Defaults: nil, | ||
} | ||
|
||
merged, err := dst.Merge(src) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
actual := merged.Values | ||
|
||
expected := map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": map[string]interface{}{ | ||
"version": "0.10.3", | ||
}, | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(expected, actual); diff != "" { | ||
t.Errorf(diff) | ||
} | ||
} | ||
|
||
// See https://github.com/roboll/helmfile/issues/1154 | ||
func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) { | ||
dst := &Environment{ | ||
Name: "dst", | ||
Values: map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": map[string]interface{}{ | ||
"version": "0.10.0", | ||
}, | ||
}, | ||
}, | ||
Defaults: nil, | ||
} | ||
|
||
src := &Environment{ | ||
Name: "src", | ||
Values: map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": map[string]interface{}{ | ||
"version": "0.10.3", | ||
}, | ||
"prometheus": nil, | ||
}, | ||
}, | ||
Defaults: nil, | ||
} | ||
|
||
merged, err := dst.Merge(src) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
actual := merged.Values | ||
|
||
expected := map[string]interface{}{ | ||
"components": map[string]interface{}{ | ||
"etcd-operator": map[string]interface{}{ | ||
"version": "0.10.3", | ||
}, | ||
"prometheus": nil, | ||
}, | ||
} | ||
|
||
if diff := cmp.Diff(expected, actual); diff != "" { | ||
t.Errorf(diff) | ||
} | ||
} |