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

Retain Extra fields over Uses,Augments #244

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/yang/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,12 @@ func (e *Entry) dup() *Entry {
ne.Dir[k] = de
}
}

ne.Extra = make(map[string][]interface{})
for k, v := range e.Extra {
ne.Extra[k] = v
}

return &ne
}

Expand All @@ -1485,11 +1491,7 @@ func (e *Entry) merge(prefix *Value, namespace *Value, oe *Entry) {
} else {
v.Parent = e
v.Exts = append(v.Exts, oe.Exts...)
for lk, lv := range oe.Extra {
if v.Extra[lk] == nil {
v.Extra[lk] = lv
continue
}
for lk := range oe.Extra {
v.Extra[lk] = append(v.Extra[lk], oe.Extra[lk]...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a test in TestIfFeature in entry_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

(optional) Note that currently only augments in uses statements are going to be picked up. Raw augments won't be. I'd also suggest adding this statement outside of the for loop as well and fixing the relevant test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please give an example where this would occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For what I see, augment defined in uses are ignored, regardless of if-feature field - could we open a new issue, approve this PR, and treat that corner case separately? What do you reckon @wenovus ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually my comment here was misled by my naive thought that if-features should be applied to the target node where they should only be applied to the nodes within the uses or augment, which is exactly what your PR does. This LGTM.

}
e.Dir[k] = v
Expand Down
18 changes: 17 additions & 1 deletion pkg/yang/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,7 @@ var testIfFeatureModules = []struct {
feature ft-identity;
feature ft-uses;
feature ft-refine;
feature ft-augment-uses;

container cont {
if-feature ft-container;
Expand Down Expand Up @@ -2118,6 +2119,9 @@ var testIfFeatureModules = []struct {

augment "/cont" {
if-feature ft-augment;
uses g {
if-feature ft-augment-uses;
}
}

identity id {
Expand All @@ -2130,7 +2134,10 @@ var testIfFeatureModules = []struct {
if-feature ft-refine;
}
}
grouping g {}

grouping g {
container gc {}
}
}
`,
},
Expand Down Expand Up @@ -2269,6 +2276,15 @@ func TestIfFeature(t *testing.T) {
inIfFeatures: ms.Modules["if-feature"].Uses[0].IfFeature,
wantIfFeatures: []string{"ft-uses"},
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you can add a comment above this test block, something like "// Testing that if-features are merged correctly" I think that would help make this more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

name: "uses",
inIfFeatures: entryIfFeatures(mod.Dir["gc"]),
wantIfFeatures: []string{"ft-uses"},
}, {
name: "augment-uses",
inIfFeatures: entryIfFeatures(mod.Dir["cont"].Dir["gc"]),
wantIfFeatures: []string{"ft-augment-uses", "ft-augment"},
},
}

for _, tc := range testcases {
Expand Down