Skip to content
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

[WIP][confmap] Enable decoding nil values in confmap #11734

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mahadzaryab1
Copy link
Contributor

@mahadzaryab1 mahadzaryab1 commented Nov 23, 2024

Description

Link to tracking issue

Towards ##10266

Testing

Documentation

Signed-off-by: Mahad Zaryab <[email protected]>
to.Set(reflect.MakeSlice(to.Type(), from.Len(), from.Cap()))
if !from.IsNil() {
to.Set(reflect.MakeSlice(to.Type(), from.Len(), from.Cap()))
}
}

return from.Interface(), nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you not changing this to from? That's the main change that needs to be applied across all hooks, otherwise you never know under which condition they might return untyped nil and break the chain.

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.60%. Comparing base (f74890a) to head (ac3972a).

Files with missing lines Patch % Lines
confmap/confmap.go 72.72% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11734      +/-   ##
==========================================
- Coverage   91.61%   91.60%   -0.01%     
==========================================
  Files         443      443              
  Lines       23770    23778       +8     
==========================================
+ Hits        21776    21781       +5     
- Misses       1620     1622       +2     
- Partials      374      375       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@@ -33,8 +33,7 @@ func TestLoadConf(t *testing.T) {
func TestToStringMapSanitizeEmptySlice(t *testing.T) {
cfg, err := LoadConf(filepath.Join("testdata", "empty-slice.yaml"))
require.NoError(t, err)
var nilSlice []interface{}
assert.Equal(t, map[string]any{"slice": nilSlice}, cfg.ToStringMap())
assert.Equal(t, map[string]any{"slice": []interface{}{}}, cfg.ToStringMap())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurishkuro What do you think of the change to this expectation here? It looks like it was conflicting with rest of the decoding flow. This is what empty-slice.yaml looks like:

slice: [] # empty slices are sanitized to nil in ToStringMap

Given that slice is explicitly identified, shouldn't slice be empty instead of nil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the comment in the fixture the current test is as expected. Does it not contradict the description of the hook?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is indeed a contradiction, I would suggest opening a ticket with description, to let the maintainers opine what behavior they expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is up at #11755 for the patch

confmap/confmap.go Outdated Show resolved Hide resolved
Signed-off-by: Mahad Zaryab <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants