Skip to content

Commit

Permalink
Retain Extra fields over Uses,Augments (#244)
Browse files Browse the repository at this point in the history
* Retain Extra fields over Uses,Augments

* Fix duplication issue; add IfFeature test for uses in augment

* Add comments to entry_test
  • Loading branch information
bclasse authored May 15, 2023
1 parent 9a319ef commit 1d9b70a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 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,6 +1491,9 @@ func (e *Entry) merge(prefix *Value, namespace *Value, oe *Entry) {
} else {
v.Parent = e
v.Exts = append(v.Exts, oe.Exts...)
for lk := range oe.Extra {
v.Extra[lk] = append(v.Extra[lk], oe.Extra[lk]...)
}
e.Dir[k] = v
}
}
Expand Down
21 changes: 20 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,18 @@ func TestIfFeature(t *testing.T) {
inIfFeatures: ms.Modules["if-feature"].Uses[0].IfFeature,
wantIfFeatures: []string{"ft-uses"},
},
{
// Verify that if-feature field defined in "uses" is correctly propagated to container
name: "uses",
inIfFeatures: entryIfFeatures(mod.Dir["gc"]),
wantIfFeatures: []string{"ft-uses"},
},
{
// Verify that if-feature field defined in "augment" and in "augment > uses" is correctly propagated to container
name: "augment-uses",
inIfFeatures: entryIfFeatures(mod.Dir["cont"].Dir["gc"]),
wantIfFeatures: []string{"ft-augment-uses", "ft-augment"},
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit 1d9b70a

Please sign in to comment.