-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: fix generic map conversion #1838
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
k8syaml "sigs.k8s.io/yaml" | ||
) | ||
|
||
func Test_cleanUpGenericMap(t *testing.T) { | ||
|
@@ -25,7 +26,7 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
}, | ||
want: map[string]interface{}{ | ||
"abc": "xyz", | ||
"number": 5, | ||
"number": float64(5), | ||
"float": 1.5, | ||
"bool": true, | ||
"array": []interface{}{ | ||
|
@@ -49,7 +50,7 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
want: map[string]interface{}{ | ||
"nest": map[string]interface{}{ | ||
"abc": "xyz", | ||
"number": 5, | ||
"number": float64(5), | ||
"float": 1.5, | ||
"bool": true, | ||
"array": []interface{}{ | ||
|
@@ -74,7 +75,7 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
want: map[string]interface{}{ | ||
"nest": map[string]interface{}{ | ||
"abc": "xyz", | ||
"number": 5, | ||
"number": float64(5), | ||
"float": 1.5, | ||
"bool": true, | ||
"array": []interface{}{ | ||
|
@@ -102,11 +103,11 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
want: map[string]interface{}{ | ||
"nest": map[string]interface{}{ | ||
"abc": "xyz", | ||
"number": 5, | ||
"number": float64(5), | ||
"float": 1.5, | ||
"bool": true, | ||
"array": []map[string]interface{}{ | ||
{ | ||
"array": []interface{}{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think helm will accept an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i assume since its passing tests... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our e2e tests never caught this bug, which is why these unit tests were introduced. so i wouldn't be so confident... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
map[string]interface{}{ | ||
"name": "example", | ||
"value": "true", | ||
}, | ||
|
@@ -133,11 +134,11 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
want: map[string]interface{}{ | ||
"nest": map[string]interface{}{ | ||
"abc": "xyz", | ||
"number": 5, | ||
"number": float64(5), | ||
"float": 1.5, | ||
"bool": true, | ||
"array": []map[string]interface{}{ | ||
{ | ||
"array": []interface{}{ | ||
map[string]interface{}{ | ||
"name": "example", | ||
"value": "true", | ||
}, | ||
|
@@ -149,7 +150,14 @@ func Test_cleanUpGenericMap(t *testing.T) { | |
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
req := require.New(t) | ||
req.Equal(tt.want, cleanUpGenericMap(tt.in)) | ||
out, err := cleanUpGenericMap(tt.in) | ||
req.NoError(err, "cleanUpGenericMap failed") | ||
req.Equal(tt.want, out) | ||
|
||
// ultimately helm calls k8syaml.Marshal so we must make sure that the output is compatible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you verify (even if manually) that this would've caught the issue fixed by #1834? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I verify? Can you provide reproduction steps? They are not in the original fix. |
||
// https://github.com/helm/helm/blob/v3.17.0/pkg/chartutil/values.go#L39 | ||
_, err = k8syaml.Marshal(out) | ||
req.NoError(err, "yaml marshal failed") | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not k8syaml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think because k8syaml cannot marshal a map[interface{}]interface{}. i will test and add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added comments to clarify